summaryrefslogtreecommitdiff
path: root/java/apps/NexusII/src/RoomSpace.java
blob: 9afb78ddff1da23eb766f4489699cab5d68c808b (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.awt.*;

class RoomFrame extends Frame // implements Runnable
{

  // Graphics Objects
    private Panel  panel = new Panel();
    private TextField tfInput = new TextField(80);
    private TextArea taOutput = new TextArea(80,10);
    Button bLeave = new Button("Leave");
    ImageCanvas icOutput = new ImageCanvas();

  void InitGraphics()
  {
      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();
      setFont(new Font("Helvetica", Font.PLAIN, 14));
      panel.setLayout (gbl);

      gbc.weightx = 1.0;
      gbc.weighty = 1.0;

      // First the Image so that sizes are fixed
      gbc.gridx = 1;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.CENTER;
      gbc.fill = GridBagConstraints.NONE;
      gbl.setConstraints(icOutput, gbc);
      panel.add(icOutput);

      // The Text Output Area
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.WEST;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbl.setConstraints(taOutput,gbc);
      taOutput.setEditable(false);
      panel.add(taOutput);

      // The Text Input Field
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.anchor = GridBagConstraints.WEST;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbl.setConstraints(tfInput,gbc);
      panel.add(tfInput);

      // The Leave Button
      gbc.gridx = 1;
      gbc.gridy = 1;
      gbc.anchor = GridBagConstraints.WEST;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbl.setConstraints(bLeave,gbc);
      panel.add(bLeave);
  }
      
      
  public RoomFrame()
  {
      this("Anonymous");
  }

  public RoomFrame(String s)
  {
      InitGraphics();
      super(s);
      this.pack();
      this.show();
  }

  public boolean handleEvent(Event event)
  {
      if (event.id == Event.WINDOW_DESTROY)
	  dispose();
      return super.handleEvent(event);
  }

}

class ImageCanvas extends Canvas {

  Image image_;
  int imgWidth_ = 128;
  int imgHeight_ = 128;

  public Dimension preferredSize() {
      return minimumSize();
  }

  public Dimension minimumSize() {
      return new Dimension(imgWidth_, imgHeight_);
  }

  public void image(Image newIm) {
      image_ = newIm;
  }

  public Image image() {
      return image_;
  }

  public void paint(Graphics g) {
      g.drawImage(image_,0,0,this);
  }

  public void update() {
      paint();
  }
  
} // End of the Image Canvas Class