看了毕老师关于图形界面的视频,自己动手试了一下- import java.awt.*;
- import java.awt.event.*;
- class FrameDemo
- {
- private Frame f;
- private Button but;
- FrameDemo()
- {
- init();
- }
- public static void main(String[] args)
- {
- new FrameDemo();
- }
- private void init()
- {
- f=new Frame("My Frame");
- f.setSize(400,300);
- f.setLocation(300,200);
- f.setLayout(new FlowLayout());
- but=new Button("转换");
- f.add(but);
- f.setVisible(true);
- }
- f.addWindowListener(new WindowAdapter()//这一行报错, <identifier> expected
- //f.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.out.println("我关");
- System.exit(0);
- }
- public void windowOpende(WindowEvent e)
- {
- System.out.println("打开");
- }
- public void windowActiviated(WindowEvent e)
- {
- System.out.println("被置为当前");
- }
- });
- }
复制代码 不知道为什么会错? |
|