[4866] in java-interest
Re: Button in a simple frame
daemon@ATHENA.MIT.EDU (mark@hactl.com.hk)
Wed Jan 17 04:10:18 1996
From: mark@hactl.com.hk
Date: Wed, 17 Jan 1996 15:11:03 +0800
To: java-interest@java.sun.com, Franck Lantres <lantres@lome.seriat.fr>
I think you can move the definition of panel p and three add statements from
paint() to MyApp() before pack(). I can display the buttons in this way.
Mark
______________________________ Reply Separator _________________________________
Subject: Button in a simple frame
Author: Franck Lantres <lantres@lome.seriat.fr> at INTERNET
Date: 1/16/96 4:56 PM
I just start with Java.
I want to put two buttons in a simple frame. Here is the code :
import java.awt.*;
public class MyFrame extends Frame
{
static final int x=300;
static final int y=300;
public MyFrame(String title)
{
setTitle(title);
setFont(new Font("TimesRoman", Font.PLAIN, 12));
setBackground(Color.white);
setForeground(Color.black);
setLayout(new BorderLayout());
pack();
resize(x, y);
show();
}
public void paint(Graphics g)
{
Panel p=new Panel();
g.setColor(Color.blue);
g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g.drawString("Tms Normal", 30, 50);
g.setFont(new Font("TimesRoman", Font.BOLD, 20));
g.drawString("Tms Bold", 30, 70);
g.setFont(new Font("TimesRoman", Font.ITALIC, 20));
g.drawString("Tms Italic", 30, 90);
p.add(new Button("Ok"));
p.add(new Button("Cancel"));
add("South", p);
}
public boolean handleEvent(Event evt)
{
switch(evt.id)
{
case Event.WINDOW_DESTROY :
{
System.exit(0);
return true;
}
default :
return false;
}
}
public static void main(String args[])
{
new MyFrame("My First Window ...");
}
}
Why these buttons don't appear ?
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com