抱歉我的英语不好。
我希望能够打开一个新的JFrame(prova()),禁用按钮" hello",并关闭JFrame(prova())恢复按钮" hello"。但我不明白如何使用WindowListener
public class ciao extends JFrame implements ActionListener{
JButton c = new JButton("hello");
JButton b = new JButton("ciao");
ciao(){
JFrame f = new JFrame();
f.setTitle("ciao");
f.setSize(200,200);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setVisible(true);
c.addActionListener(this);
b.addActionListener(this);
f.add(b);
f.add(c);
f.setLayout(new FlowLayout());
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==c)
{
JFrame p = new prova();
c.setEnabled(false);
p.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
c.setEnabled(false);
}
});
}
if (e.getSource()==b)
{
System.out.println("booooooooooo");
}
}}