62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
/**
*
* @author zys59三仙半(QQ:597882752)<br>
* 创建时间:2015年9月16日 上午7:47:05
*/
public class DoubleFrame extends JFrame {
private static final long serialVersionUID = -2768086441362968872L;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DoubleFrame frame = new DoubleFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private JFrame child;
private JButton btnAaa;
private JButton btnBbb;
/**
* Create the frame.
*/
public DoubleFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("主窗口");
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
child = new JFrame("从窗口");
child.setBounds(20, 20, 150, 120);
child.setDefaultCloseOperation(HIDE_ON_CLOSE);
child.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
btnAaa.setEnabled(true);
}
});
btnAaa = new JButton("AAA");
btnAaa.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
btnAaa.setEnabled(false);
child.setVisible(true);
}
});
btnAaa.setBounds(38, 105, 93, 23);
contentPane.add(btnAaa);
btnBbb = new JButton("BBB");
btnBbb.setBounds(216, 147, 93, 23);
contentPane.add(btnBbb);
}
}