MiKe12268 MiKe12268
关注数: 2 粉丝数: 93 发帖数: 4,438 关注贴吧数: 25
大神来帮忙看看对话框怎么关不了 本人初学,费了九牛二虎写了下面代码,现在Jdialog点右上角的X 无法关闭,百度了下addWindowListener(new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } );这条命令可以关闭Jdialog,请教下大神这命令应该加在哪一段?谢谢了 public class Exp extends JFrame implements ActionListener { JFrame jf = new JFrame(); JPanel jp1 = new JPanel(); JTextArea ta = new JTextArea(); JScrollPane js = new JScrollPane(ta); JButton olt = new JButton("olt脚本"), Exp() { jf.setTitle("脚本生成"); jf.setVisible(true); jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); jp1.setLayout(new BorderLayout()); jf.setBounds(300, 100, 600, 400); jp1.add(js); jf.add(jp1, BorderLayout.CENTER); jf.add(jp2, BorderLayout.SOUTH); jp2.add(olt); olt.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource()==olt) { ta.setText(""); MyDialog1 dlg = new MyDialog1(this,true); dlg.show(); } } public static void main(String[] args) { new Exp(); } class MyDialog1 extends Dialog implements ActionListener { JLabel label1 = new JLabel("起始上网vlan"); JTextField firvlan = new JTextField(50); JButton ok = new JButton("确定"); MyDialog1(Exp parent, boolean modal) { super(parent,modal); setResizable(false); setLayout(null); add(label1); label1.setBounds(30, 30, 80, 20); add(firvlan); firvlan.setBounds(150, 30, 90, 20); ok.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource()==ok) { 。。。 } dispose(); } } }
1 下一页