一 创建一个Frame窗口
1 代码
import java.awt.Frame;
public class TestFrame
{
public static void main(String[] args)
{
Frame frame = new Frame();
//frame.setSize(500, 300);
frame.setBounds(50,50, 500,300);
frame.setTitle("Hello Java GUI");
frame.setVisible(true);
}
}
2 运行
二 能设置背景色的窗口
1 代码
import java.awt.Color;
import java.awt.Frame;
class TestFrameColor extends Frame
{
public TestFrameColor() {
//设置标题
this.setTitle( "Hello Java GUI" );
//设置大小可更改
this.setResizable( true );
//设置大小
//this.setSize(300,200);
//设置大小及窗口顶点位置
this.setBounds(50,50,500,300);
//设置背景颜色
this.setBackground(Color.green);
//显示窗口
this.setVisible(true);
}
public static void main(String[] args)
{
TestFrameColor colorFrame = new TestFrameColor();
}
}
2 运行
三 能关闭的窗口
1 代码
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class CloseFrame {
public static void main( String[] args ) {
Frame frame = new Frame();
frame.setSize(500, 300);
frame.setTitle("Hello Java GUI");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
2 运行
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)