The function of the program is to appear the menu bar, click the menu exit option to exit the form!
Package com.xywei.awt;
Import Java.awt.Button;
Import Java.awt.FlowLayout;
Import Java.awt.Frame;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.awt.event.WindowAdapter;
Import java.awt.event.WindowEvent;
public class MyFrame {
Create a Frame
Frame MyFrame = new Frame ();
Create a button
Button MyButton = New button ();
public void MyFrame () {
Create a Frame
MyFrame = new Frame ();
Create a button
MyButton = new Button ();
Mybutton.setlabel ("OK button");
Set the various properties of the frame, distance left 400, top 300, window frame 200 wide, 150 high
Myframe.setbounds (400, 100, 700, 450);
Set the layout inside the window, with flow layout, border layout, grid layout
Myframe.setlayout (New FlowLayout ());
Add a button to the window frame
Myframe.add (MyButton);
Add an event to the form
Myframe.addwindowlistener (New Windowadapter () {
public void windowclosing (WindowEvent e) {
System.out.println ("===== will close the window =======");
System.out.println ("window is closed! ");
System.exit (0);
}
public void windowactivated (WindowEvent e) {
System.out
. println ("This is public void windowactivated (WindowEvent e) {}");
}
public void windowopened (WindowEvent e) {
System.out
. println ("public void windowopened (WindowEvent e) {} What is it???? ");
}
});
Add an event to the button
Mybutton.addactionlistener (new ActionListener () {
private int count = 1;
@Override
public void actionperformed (ActionEvent e) {
TODO auto-generated Method Stub
Button bt= (button) E.getsource ();
Frame fm= (frame) bt.getparent ();
Fm.add (New button ("button==" +count++));
Fm.validate ();
System.out.println ("count==" +count++);
}
});
Myframe.settitle ("This is my first window interface");
setting is visible
Myframe.setvisible (TRUE);
}
public static void Main (string[] args) {
MyFrame frame1 = new MyFrame ();
Frame1.myframe ();
}
}
In Java, you use AWT to write your own third graphical interface with a menu bar