日期:2014-05-20 浏览次数:20603 次
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class Test extends JPanel implements ActionListener{
JButton b, c;
JInternalFrame jif1, jif2;
public Test(){
this.setLayout(null);
b = new JButton("Hello");
b.setBounds(50, 50, 100, 50);
b.addActionListener(this);
this.add(b);
c = new JButton("World");
c.setBounds(300, 50, 100, 50);
c.addActionListener(this);
this.add(c);
jif1 = new JInternalFrame("Hello", false, true);
jif1.setBounds(200, 200, 200, 200);
jif1.addInternalFrameListener(new MyInternalFrame());
this.add(jif1);
jif2 = new JInternalFrame("World", false, true);
jif2.setBounds(300, 300, 200, 200);
jif2.addInternalFrameListener(new MyInternalFrame());
this.add(jif2);
}
public static void main(String[] args) {
JFrame f = new JFrame();
Test t = new Test();
f.add(t);
f.setSize(500, 500);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setUndecorated(true);
f.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(b == e.getSource()){
jif1.show();
}
if(c == e.getSource()){
jif2.show();
}
}
class MyInternalFrame extends InternalFrameAdapter{
@Override
public void internalFrameActivated(InternalFrameEvent e) {
// TODO Auto-generated method stub
System.out.println("开");
Test.this.setEnabled(false);
System.out.println(Test.this.isEnabled());
}
@Override
public void internalFrameClosed(InternalFrameEvent e) {
// TODO Auto-generated method stub
System.out.println("关");
Test.this.setEnabled(true);
System.out.println(Test.this.isEnabled());
}
}
}