为什么ActionEvent无法响应????
我做的一个画板程序:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import javax.swing.*;
public class DrawBoard extends JApplet implements ActionListener{
JFrame frame;
JMenuBar menu;
JMenu file,edit,view,image,color,help;
JMenuItem newfile,openfile,copy,t,helpabout,about;
JPanel panel1,panel2,panel3;
JButton cut,pencil,gun,drawline,rectangle,polygon,circle;
JColorChooser jj;
private Container top;
public void init()
{
Container top = getContentPane();
top.setLayout(new BorderLayout());
setSize(800,800);
menu=new JMenuBar();
menu.setOpaque(true);
menu.setBackground(Color.lightGray);
menu.setPreferredSize(new Dimension(500,20));
file=new JMenu("文件(F)");
edit=new JMenu("编辑(E)");
view=new JMenu("查看(V)");
image=new JMenu("图像(I)");
color=new JMenu("颜色(C)");
help=new JMenu("帮助(H)");
newfile=new JMenuItem("新建(N) Ctrl+N");
openfile=new JMenuItem("打开(O) Ctrl+O");
copy=new JMenuItem("复制(C) Ctrl+C");
t=new JMenuItem("剪切(T) Ctrl+T");
helpabout=new JMenuItem("帮助主题(H) Ctrl+H");
about=new JMenuItem("关于(A) Ctrl+A");
file.add(newfile);
file.add(openfile);
file.add(copy);
file.add(t);
help.add(helpabout);
help.add(about);
menu.add(file);
menu.add(edit);
menu.add(view);
menu.add(image);
menu.add(color);
menu.add(help);
setJMenuBar(menu);
JButton cut=new JButton("裁剪");
JButton pencil=new JButton("铅笔");
JButton gun=new JButton("喷枪");
JButton drawline=new JButton("直线");
JButton rectangle=new JButton("矩形");
JButton polygon=new JButton("多边形");
JButton circle=new JButton("圆");
cut.addActionListener(this);
pencil.addActionListener(this);
gun.addActionListener(this);
drawline.addActionListener(this);
rectangle.addActionListener(this);
polygon.addActionListener(this);
circle.addActionListener(this);
JPanel panel1=new JPanel();
panel1.setLayout(new GridLayout(7,1,1,3));
panel1.add(cut);
panel1.add(pencil);
panel1.add(gun);
panel1.add(drawline);
panel1.add(rectangle);
panel1.add(polygon);
panel1.add(circle);
top.add(panel1,BorderLayout.WEST);
JPanel panel2=new JPanel();
JColorChooser jj=new JColorChooser();
panel2.add(jj);
top.add(panel2,BorderLayout.SOUTH);
JPanel panel3=new JPanel();
panel3.setBackground(Color.WHITE);
panel3.setSize(300,500);
top.add(panel3,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
Object g=e.getSource();
if(g==cut||g==pencil||g==gun)
{ JOptionPane.showMessageDialog(null,"Asdf","d",JOptionPane.INFORMATION_MESSAGE);
}
}
为什么我按下哪个按钮都不弹出对话框,急啊!!!