Use AWT to write your first graphical interface in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.