当前位置: 代码迷 >> Java相关 >> 初学困惑
  详细解决方案

初学困惑

热度:437   发布时间:2007-09-20 05:57:52.0
初学困惑

import java.awt.*;
import java.awt.event.*;

public class ToolbarFrame1 extends Frame implements ActionListener {
Button cutButton, copyButton, pasteButton;
public ToolbarFrame1(){
super ("Toolbar Example(AWT)");
setSize(450, 250);
addWindowListener(new BasicWindowMonitor());

Panel toolbar = new Panel();
toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

cutButton = new Button ("Cut");
cutButton.addActionListener(this);
toolbar.add(cutButton);

copyButton = new Button ("Copy");
copyButton.addActionListener(this);
toolbar.add(copyButton);

pasteButton = new Button("Paste");
pasteButton.addActionListener(this);
toolbar.add(pasteButton);

add(toolbar , BorderLayout.NORTH);
}
public void actionPerformed (ActionEvent ae){
System.out.println(ae.getActionCommand());
}
public static void main(String[] args) {
ToolbarFrame1 tf1 = new ToolbarFrame1();
tf1.setVisible(true);

}

}


public class BasicWindowMonitor extends WindowAdapter{
public void windowClosing (WindowEvent e){
Window w = e.getWindow();
w.setVisible(false);
w.dispose();
System.exit(0);
}

}
运行不了啊,求达人改下了,谢谢!

搜索更多相关的解决方案: 初学  困惑  

----------------解决方案--------------------------------------------------------
一个文件里只能有一个类是public的。。。。。
事件处理类的public 去掉。。。
这里用个匿名类就OK了。一句话就搞定。
----------------解决方案--------------------------------------------------------
啊怎么改,不是很明白啊
----------------解决方案--------------------------------------------------------
如果我分成两个类呢
----------------解决方案--------------------------------------------------------

最简单改法。把后一个类的public 去掉


----------------解决方案--------------------------------------------------------
  相关解决方案