[4836] in java-interest

home help back first fref pref prev next nref lref last post

Button in a simple frame

daemon@ATHENA.MIT.EDU (Franck Lantres)
Tue Jan 16 16:30:28 1996

From: Franck Lantres <lantres@lome.seriat.fr>
Date: Tue, 16 Jan 96 16:56:10 GMT
To: java-interest@java.sun.com

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

home help back first fref pref prev next nref lref last post