aboutsummaryrefslogtreecommitdiff
path: root/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java
blob: b845a7f38026b497f50df29c3d59f54730ea3577 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino.
package RobottinoUtils;

// Importo i package standard relativi al funzionamento delle finestre e della grafica in generale.
import java.awt.*;

// E i package RobottinoAzioni e RobottinoUtils da me definiti.
import RobottinoAzioni.*;
import RobottinoUtils.Listener;

// La classe è una sottoclasse di Frame per poter sfruttare gli effetti grafici
// ma implementa anche l'interfaccia WindowListener, necessaria per gestire gli eventi collegati alle finestre
// (riduzione a icona, chiusura...); per questo devo successivamente ridefinire tutti i
// metodi dell'interfaccia.
public class Grafica extends Frame {

	// Creo un'istanza della classe Listener che userò come listener per gli eventi.
	public static Listener listener;

	// Il costruttore senza argomenti.
	public Grafica () {

		// Il metodo "setBounds" posiziona e dimensiona la finestra.
		setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza);

		// "setTitle" per il titolo della finestra.
		setTitle ("Robottino v2.2");

		// "setVisible" per poterla visualizzare.
		setVisible (true);

		// E addWindowListener per l'ascoltatore (listener).
		listener = new Listener();
		addWindowListener (listener);

		// Aggiungo la barra del menu con i vari sottomenu
		setMenuBar (barraMenu);

		// Il menu file.
		NewRobot.addActionListener(listener);
		NewRobot.setActionCommand("newrobot");

		ChangeRobot.addActionListener(listener);
		ChangeRobot.setActionCommand("changerobot");

		DeleteRobot.addActionListener(listener);
		DeleteRobot.setActionCommand("deleterobot");

		Exit.addActionListener(listener);
		Exit.setActionCommand("exit");

		file.add(NewRobot);
		file.add(ChangeRobot);
		file.add(DeleteRobot);
		file.addSeparator();
		file.add(Exit);

		barraMenu.add(file);

		// Il braccio sinistro.
		LeftArmMove.addActionListener(listener);
		LeftArmMove.setActionCommand("leftarmmove");

		LeftArmOn.addActionListener(listener);
		LeftArmOn.setActionCommand("leftarmon");

		LeftArmOff.addActionListener(listener);
		LeftArmOff.setActionCommand("leftarmoff");

		LeftArm.add(LeftArmMove);
		LeftArm.add(LeftArmOn);
		LeftArm.add(LeftArmOff);

		// Il braccio destro.
		RightArmMove.addActionListener(listener);
		RightArmMove.setActionCommand("rightarmmove");

		RightArmOn.addActionListener(listener);
		RightArmOn.setActionCommand("rightarmon");

		RightArmOff.addActionListener(listener);
		RightArmOff.setActionCommand("rightarmoff");

		RightArm.add(RightArmMove);
		RightArm.add(RightArmOn);
		RightArm.add(RightArmOff);

		// La gamba sinistra.
		LeftLegMove.addActionListener(listener);
		LeftLegMove.setActionCommand("leftlegmove");

		LeftLegOn.addActionListener(listener);
		LeftLegOn.setActionCommand("leftlegon");

		LeftLegOff.addActionListener(listener);
		LeftLegOff.setActionCommand("leftlegoff");

		LeftLeg.add(LeftLegMove);
		LeftLeg.add(LeftLegOn);
		LeftLeg.add(LeftLegOff);

		// La gamba destra.
		RightLegMove.addActionListener(listener);
		RightLegMove.setActionCommand("rightlegmove");

		RightLegOn.addActionListener(listener);
		RightLegOn.setActionCommand("rightlegon");

		RightLegOff.addActionListener(listener);
		RightLegOff.setActionCommand("rightlegoff");

		RightLeg.add(RightLegMove);
		RightLeg.add(RightLegOn);
		RightLeg.add(RightLegOff);

		// Menu rinomina.
		Rename.addActionListener(listener);
		Rename.setActionCommand("rename");

		Menu modifica = new Menu("Modifica");
		modifica.add(LeftArm);
		modifica.add(RightArm);
		modifica.add(LeftLeg);
		modifica.add(RightLeg);
		modifica.addSeparator();
		modifica.add(Rename);

		barraMenu.add(modifica);

		// Menu azioni.
		Exploud.addActionListener(listener);
		Exploud.setActionCommand("exploud");

		Bier.addActionListener(listener);
		Bier.setActionCommand("bier");

		xxx.addActionListener(listener);
		xxx.setActionCommand("xxx");

		Dance.addActionListener(listener);
		Dance.setActionCommand("dance");

		azioni.add(Exploud);
		azioni.add(Bier);
		azioni.add(xxx);
		azioni.add(Dance);

		barraMenu.add(azioni);

		// Menu info.
		Porky.addActionListener(listener);
		Porky.setActionCommand("porky");

		l.addActionListener(listener);
		l.setActionCommand("l");

		RobotList.addActionListener(listener);
		RobotList.setActionCommand("robotlist");

		info.add(Porky);
		info.add(l);
		info.add(RobotList);

		barraMenu.add(info);
	}

	// Le variabili pubbliche di classe per il metodo "setBounds".
	public int orizzontale = 0;
	public int verticale = 0;
	public int larghezza = 500;
	public int altezza = 500;

	// E i vari Menu e MenuItem.
	MenuBar barraMenu = new MenuBar();
	Menu file = new Menu("File");
	MenuItem NewRobot = new MenuItem("Nuovo robot");
	MenuItem ChangeRobot = new MenuItem("Dai i comandi a un altro robot");
	MenuItem DeleteRobot = new MenuItem("Elimina un robot");
	MenuItem Exit = new MenuItem("Esci");
	Menu LeftArm = new Menu("Braccio sinistro");
	MenuItem LeftArmMove = new MenuItem("Cambia posizione");
	MenuItem LeftArmOn = new MenuItem("Alza");
	MenuItem LeftArmOff = new MenuItem("Abbassa");
	Menu RightArm = new Menu("Braccio destro");
	MenuItem RightArmMove = new MenuItem("Cambia posizione");
	MenuItem RightArmOn = new MenuItem("Alza");
	MenuItem RightArmOff = new MenuItem("Abbassa");
	Menu LeftLeg = new Menu("Gamba sinistra");
	MenuItem LeftLegMove = new MenuItem("Cambia posizione");
	MenuItem LeftLegOn = new MenuItem("Alza");
	MenuItem LeftLegOff = new MenuItem("Abbassa");
	Menu RightLeg = new Menu("Gamba destra");
	MenuItem RightLegMove = new MenuItem("Cambia posizione");
	MenuItem RightLegOn = new MenuItem("Alza");
	MenuItem RightLegOff = new MenuItem("Abbassa");
	MenuItem Rename = new MenuItem("Rinomina");
	Menu azioni = new Menu("Azioni");
	MenuItem Exploud = new MenuItem("Esplodi");
	MenuItem Bier = new MenuItem("Birra");
	MenuItem xxx = new MenuItem("xxx");
	MenuItem Dance = new MenuItem("Balla");
	Menu info = new Menu("?");
	MenuItem Porky = new MenuItem("Informazioni sul programmatore");
	MenuItem l = new MenuItem("Legenda Comandi");
	MenuItem RobotList = new MenuItem("Lista robot");
}




Generated with cgit - Back to sebastiano.tronto.net