ParentChildFrames.java
1 |
import javax.swing.*; |
---|---|
2 |
import java.awt.event.*; |
3 |
import java.awt.*; |
4 |
|
5 |
public class ParentChildFrames |
6 |
{ |
7 |
public static void main(String[] args) |
8 |
{ |
9 |
SwingUtilities.invokeLater(new Runnable() |
10 |
{ |
11 |
public void run() |
12 |
{ |
13 |
JFrame parentFrame = new JFrame("Parent"); |
14 |
parentFrame.setSize(250, 250); |
15 |
parentFrame.setLocation(150, 150); |
16 |
// parentFrame.setUndecorated(true);
|
17 |
|
18 |
final JWindow childFrame = new JWindow(parentFrame); |
19 |
childFrame.setSize(250, 250); |
20 |
childFrame.setLocation(550, 150); |
21 |
childFrame.getContentPane().setBackground(Color.RED);
|
22 |
|
23 |
final JCheckBox childVisible = new JCheckBox("Child Window Visibility"); |
24 |
parentFrame.add(childVisible); |
25 |
|
26 |
childVisible.addItemListener(new ItemListener() |
27 |
{ |
28 |
public void itemStateChanged(ItemEvent e) |
29 |
{ |
30 |
childFrame.setVisible(childVisible.isSelected()); |
31 |
} |
32 |
}); |
33 |
|
34 |
childVisible.setSelected(true);
|
35 |
|
36 |
parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
37 |
parentFrame.setVisible(true);
|
38 |
} |
39 |
}); |
40 |
} |
41 |
} |