初学AWT,这一块是不是大概学一下就好?
- /*
- FrameDemo
- 经过简单优化的Frame类
- */
- import java.awt.*;
- import java.awt.event.*;
- class FrameDemo {
- public static void main(String[] args) {
- new FrameDemo();
- }
-
- //定义该图形中所需的组建的引用
- private Frame frame;
- private Button button;
-
- FrameDemo() {
- init();
- }
-
- public void init() {
- frame = new Frame("My Frame");
-
- //对frame进行基本设置
- frame.setBounds(300,200,800,600);
- frame.setLayout(new FlowLayout());
-
- button = new Button("My Button");
-
- //将组建添加到frame中
- frame.add(button);
-
- //加载窗体上的事件
- myEvent();
-
- //显示窗体
- frame.setVisible(true);
- }
-
- private void myEvent() {
- //关闭按钮
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
-
- //button事件
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- }
复制代码 |
|