1 package fi.jyu.mit.graphics;
2
3 import java.awt.*;
4 import javax.swing.*;
5
6
11 public class EasyApplet extends JApplet {
12
13 private final SpacePanel panel;
14 private TouchPad tp;
15 private ControlButtons cb;
16 private static final long serialVersionUID = 1L;
17 private final JPanel tpPanel = new JPanel();
18 private final JPanel cbPanel = new JPanel();
19 private final Panel controlpanel = new Panel();
20
21
25 public EasyApplet() {
26 super();
27 Container pane = getContentPane();
28 pane.setLayout(new BorderLayout());
29 panel = new SpacePanel();
30 panel.setBounds(0,0,400,300);
31 pane.add(panel, BorderLayout.CENTER);
32 pane.setBounds(0,0,400,550);
33 this.setBounds(0,0,400,550);
34 pane.setPreferredSize(new Dimension(400,550));
35 pane.setBackground(Color.WHITE);
36 controlpanel.setLayout(new BorderLayout());
37 pane.add(controlpanel, BorderLayout.SOUTH);
38 tpPanel.setVisible(false);
39 cbPanel.setVisible(false);
40 controlpanel.add(tpPanel,BorderLayout.WEST);
41 controlpanel.add(cbPanel,BorderLayout.EAST);
42 tpPanel.setBorder(BorderFactory.createLineBorder(Color.black));
43 cbPanel.setBorder(BorderFactory.createLineBorder(Color.black));
44 }
45
46
51 public void setTouchPad(boolean touchPadOn, boolean move) {
52 if (touchPadOn) {
53 if ( tp == null ) {
54 tp = new TouchPad(panel, move);
55 tpPanel.add(tp);
56 tp.setPreferredSize(new Dimension(160,150));
57 }
58 else
59 tp.setMove(move);
60 }
61 tpPanel.setVisible(touchPadOn);
62 }
63
64
69 public void setTouchPad(boolean touchPadOn) {
70 this.setTouchPad(touchPadOn, false);
71 }
72
73
77 public void setControlButtons(boolean controlButtonsOn) {
78 if (controlButtonsOn && ( cb == null )) {
79 cb = new ControlButtons(panel);
80 cbPanel.add(cb);
81 cb.setPreferredSize(new Dimension(160,150));
82 }
83 cbPanel.setVisible(controlButtonsOn);
84 }
85
86
90 public SpacePanel getPanel() {
91 return this.panel;
92 }
93
94
98 public Panel getControlPanel() {
99 return this.controlpanel;
100 }
101
102
106 public void add(BasicController controller) {
107 controlpanel.setLayout(new FlowLayout());
108 JPanel panel = new JPanel();
109 panel.setVisible(true);
110 panel.add(controller);
111 controller.setPreferredSize(new Dimension(160,150));
112 controlpanel.add(panel,BorderLayout.WEST);
113 panel.setBorder(BorderFactory.createLineBorder(Color.black));
114
115 }
116
117
121 @Override
122 public void init() {
123 }
125 }
126