AWT and swing are different, swing is based on a lightweight component on the weight awt, and the AWT development graphical interface is not as good as swing on a cross-platform basis, so it's generally better to use swind components!
Package com.xywei.awt;
Import Java.awt.Button;
Import Java.awt.FlowLayout;
Import Java.awt.Frame;
Import Java.awt.event.WindowAdapter;
Import java.awt.event.WindowEvent;
public class MyFrame {
public void MyFrame () {
Create a Frame
Frame MyFrame = new Frame ();
Create a button
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);
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 do you do???? ");
}
});
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 ();
}
}
Use AWT to write your first graphical interface in Java