summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3607.java
blob: 75d88e588ad756cef73a78335aaa63ad27c31e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Listing3607.java */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DesktopFrame
extends JFrame
{
  private JDesktopPane desk;

  public DesktopFrame()
  {
    super("DesktopFrame");
    this.desk = new JDesktopPane();
    desk.setDesktopManager(new DefaultDesktopManager());
    setContentPane(desk);
    addWindowListener(new WindowClosingAdapter(true));
  }

  public void addChild(JInternalFrame child, int x, int y)
  {
    child.setLocation(x, y);
    child.setSize(200, 150);
    child.setDefaultCloseOperation(
      JInternalFrame.DISPOSE_ON_CLOSE
    );
    desk.add(child);
    child.setVisible(true);
  }
}

class ChildFrame
extends JInternalFrame
{
  public ChildFrame(String title)
  {
    super("Child " + title, true, true);
    setIconifiable(true);
    setMaximizable(true);
    setBackground(Color.lightGray);
  }
}

public class Listing3607
{
  public static void main(String[] args)
  {
    //Desktop erzeugen
    DesktopFrame desktop = new DesktopFrame();
    desktop.setLocation(100, 100);
    desktop.setSize(400, 300);
    desktop.setVisible(true);
    //Zwei ChildFrames hinzuf�gen
    desktop.addChild(new ChildFrame("1"), 10, 10);
    desktop.addChild(new ChildFrame("2"), 20, 20);
  }
}