黑马程序员技术交流社区
标题:
图形化界面基础代码
[打印本页]
作者:
℃葫芦
时间:
2015-8-17 21:56
标题:
图形化界面基础代码
public class FrameDemo {
/**
* @param args
*/
public static void main(String[] args) {
Frame f = new Frame("my frame");
// f.setSize(500, 400);
// f.setLocation(400, 200);
f.setBounds(400, 200, 500, 400);
f.setLayout(new FlowLayout());//设置流式布局
Button but = new Button("一个按钮");
f.add(but);//将按钮添加到窗体中。
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// System.out.println("closing......."+e);
System.exit(0);
}
});
//在按钮上加上一个监听。
but.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("button run .....");
System.exit(0);
}
});
f.setVisible(true);
System.out.println("over");
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2