如何点击弹出窗口中的按钮,然后只关闭弹出窗口 弹出窗口内的代码如下
classwindow2extendsJFrame{publicwindow2(){setTitle("提示:");setLayout(null);setBounds(2...
class window2 extends JFrame
{
public window2()
{
setTitle("提示:");
setLayout(null);
setBounds(230,210,260,200);
Container c = getContentPane();
JLabel l1 = new JLabel();
JLabel l2 = new JLabel();
JLabel l3 = new JLabel();
l1.setText("输入错误!!");
l2.setText("请重新输入一个在0~35之间的数字号码,");
l3.setText("并且每个数字均不相同.");
l1.setHorizontalAlignment(SwingConstants.CENTER);
l2.setHorizontalAlignment(SwingConstants.CENTER);
l3.setHorizontalAlignment(SwingConstants.CENTER);
l1.setBounds(0,10,240,70);
l2.setBounds(0,20,240,80);
l3.setBounds(0,30,240,90);
JButton b1 =new JButton("关闭");
b1.setBounds(90,100,60,20);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
//这里到底应该写什么
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
c.add(l1);
c.add(l2);
c.add(l3);
c.add(b1);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
} 展开
{
public window2()
{
setTitle("提示:");
setLayout(null);
setBounds(230,210,260,200);
Container c = getContentPane();
JLabel l1 = new JLabel();
JLabel l2 = new JLabel();
JLabel l3 = new JLabel();
l1.setText("输入错误!!");
l2.setText("请重新输入一个在0~35之间的数字号码,");
l3.setText("并且每个数字均不相同.");
l1.setHorizontalAlignment(SwingConstants.CENTER);
l2.setHorizontalAlignment(SwingConstants.CENTER);
l3.setHorizontalAlignment(SwingConstants.CENTER);
l1.setBounds(0,10,240,70);
l2.setBounds(0,20,240,80);
l3.setBounds(0,30,240,90);
JButton b1 =new JButton("关闭");
b1.setBounds(90,100,60,20);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
//这里到底应该写什么
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
c.add(l1);
c.add(l2);
c.add(l3);
c.add(b1);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询