为什么实现不了弹出自定义的对话框
我想实现点击按钮弹出一个自定义的对话框,可是编写了下面的代码后发现没办法调用监听器,实现不了对话框的弹出,请高手指教!
import java.awt.*;
import java.awt.event.*;
public class work0 extends Frame
{
private Panel gridPanel1;
public work0(String title)
{
super(title);
setSize(600,400);
setLocation(100,100);
setgridLayoutPanel1();
add(gridPanel1);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
System.exit(0);}});
}
public <InterfaceHeader> void setgridLayoutPanel1()
{
gridPanel1=new Panel();
gridPanel1.setLayout(new GridLayout(4,8));
Button btn1=new Button("1");
Button btn2=new Button("2");
Button btn3=new Button("3");
Button btn4=new Button("4");
Button btn5=new Button("5");
gridPanel1.add(btn1);
gridPanel1.add(btn2);
gridPanel1.add(btn3);
gridPanel1.add(btn4);
gridPanel1.add(btn5);
btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new s1();
setVisible(true);
}
});
btn3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args)
{
work0 w=new work0("弹出对话框");
w.show();
}
}
class s1 extends Frame{
private Panel p1;
s1(){
super ("变化图");
setSize(600,400);
setLocation(200,200);
setLayout();
add(p1);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
System.exit(0);}});
}
private void setLayout() {
p1=new Panel();
p1.setLayout(null);
p1.setBackground(Color.blue);
}
}
------解决方案--------------------
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
s1 s=new s1(); [code=Java][/code]
s.setVisible(true);
}
});
这个地方错了哦!我帮你改了哦,你看看!