日期:2014-05-20 浏览次数:20770 次
package test.ww.swing;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MyTest {
public static void main(String[] args) {
JFrame A = new JFrame("A");
JButton openB = new JButton("打开B");
A.add(openB);
A.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
A.setSize(400, 300);
A.setVisible(true);
openB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final JFrame B = new JFrame("B");
B.setSize(400, 300);
B.setBackground(Color.BLACK);
B.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
B.setVisible(true);
B.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub