aboutsummaryrefslogtreecommitdiff
path: root/robottino/all_versions/v4.2/src/Frame.java
blob: 6015c41df263455dcddaaf7b53c2ce1919768f3e (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org>

This file is part of Robottino.

    Robottino is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Robottino is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Robottino; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

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

public class Frame extends JFrame implements ActionListener {
	public static int i;
	public static Main main;
	public static RobotPanel robotPanel;
	public static JLabel label;
	public static Timer timer;
	public static JMenuBar barraMenu;
	public static JMenu file, modifica, azioni, info, raMenu, laMenu, rlMenu, llMenu;
	public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem;
	public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem;
	public static JMenuItem rinomina, birra, balla, esplodi, informazioni, esci;
	public Frame() {
		super( "Robottino versione 4.2" );
		i = 0;
		main = new Main();
		robotPanel = new RobotPanel();
		label = new JLabel( "Robot: " + main.robot.getName() );
		label.setFont( new Font( "Monospace", 0, 30 ) );
		barraMenu = new JMenuBar();
		rinomina = new JMenuItem( "Cambia nome" );
		birra = new JMenuItem( "Birra" );
		balla = new JMenuItem( "Balla" );
		esplodi = new JMenuItem( "Esplodi" );
		informazioni = new JMenuItem( "Informazioni" );
		esci = new JMenuItem( "Esci" );
		raonMenuItem = new JMenuItem( "Alza" );
		laonMenuItem = new JMenuItem( "Alza" );
		rlonMenuItem = new JMenuItem( "Alza" );
		llonMenuItem = new JMenuItem( "Alza" );
		raoffMenuItem = new JMenuItem( "Abbassa" );
		laoffMenuItem = new JMenuItem( "Abbassa" );
		rloffMenuItem = new JMenuItem( "Abbassa" );
		lloffMenuItem = new JMenuItem( "Abbassa" );
		rachangeMenuItem = new JMenuItem( "Cambia posizione" );
		lachangeMenuItem = new JMenuItem( "Cambia posizione" );
		rlchangeMenuItem = new JMenuItem( "Cambia posizione" );
		llchangeMenuItem = new JMenuItem( "Cambia posizione" );
		esci.addActionListener( this );
		rinomina.addActionListener( this );
		birra.addActionListener( this );
		balla.addActionListener( this );
		esplodi.addActionListener( this );
		informazioni.addActionListener( this );
		raonMenuItem.addActionListener( this );
		raoffMenuItem.addActionListener( this );
		rachangeMenuItem.addActionListener( this );
		laonMenuItem.addActionListener( this );
		laoffMenuItem.addActionListener( this );
		lachangeMenuItem.addActionListener( this );
		rlonMenuItem.addActionListener( this );
		rloffMenuItem.addActionListener( this );
		rlchangeMenuItem.addActionListener( this );
		llonMenuItem.addActionListener( this );
		lloffMenuItem.addActionListener( this );
		llchangeMenuItem.addActionListener( this );
		raMenu = new JMenu( "Braccio destro" );
		raMenu.add( raonMenuItem );
		raMenu.add( raoffMenuItem );
		raMenu.add( rachangeMenuItem );
		laMenu = new JMenu( "Braccio sinistro" );
		laMenu.add( laonMenuItem );
		laMenu.add( laoffMenuItem );
		laMenu.add( lachangeMenuItem );
		rlMenu = new JMenu( "Gamba destra" );
		rlMenu.add( rlonMenuItem );
		rlMenu.add( rloffMenuItem );
		rlMenu.add( rlchangeMenuItem );
		llMenu = new JMenu( "Gamba sinistra" );
		llMenu.add( llonMenuItem );
		llMenu.add( lloffMenuItem );
		llMenu.add( llchangeMenuItem );
		modifica = new JMenu( "Modifica" );
		modifica.add( raMenu );
		modifica.add( laMenu );
		modifica.add( rlMenu );
		modifica.add( llMenu );
		file = new JMenu( "File" );
		file.add( rinomina );
		file.add( esci );
		azioni = new JMenu( "Azioni" );
		azioni.add( birra );
		azioni.add( balla );
		azioni.add( esplodi );
		info = new JMenu( "?" );
		info.add( informazioni );
		barraMenu.add( file );
		barraMenu.add( modifica );
		barraMenu.add( azioni );
		barraMenu.add( info );
		setJMenuBar( barraMenu );
		add( robotPanel, BorderLayout.CENTER );
		add( label, BorderLayout.SOUTH );
		addWindowListener(
			new WindowAdapter() {
				public void windowClosing( WindowEvent e ) {
					int selezione = JOptionPane.showOptionDialog( Frame.this, "Vuoi davvero uscire?", "Robottino v4.2", JOptionPane.YES_NO_OPTION,  JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" );
					if ( selezione == JOptionPane.YES_OPTION )
						System.exit( 0 );
				}
			}
		);
	}
	public void actionPerformed( ActionEvent e ) {
		if ( e.getSource() == esci ) {
			int selezione = JOptionPane.showOptionDialog( this, "Vuoi davvero uscire?", "Robottino v4.2", JOptionPane.YES_NO_OPTION,  JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" );
			if ( selezione == JOptionPane.YES_OPTION )
				System.exit( 0 );
		}
		else if ( e.getSource() == rinomina ) {
			String newName = main.robot.getName();
			newName = JOptionPane.showInputDialog( this, "Inserire il nuovo nome per il robottino:", newName );
			if ( newName != null ) {
				main.robot.setName( newName );
				label .setText( "Robot: " + main.robot.getName() );
			}
		}
		else if ( e.getSource() == raonMenuItem )
			main.robot.setRA( true );
		else if ( e.getSource() == raoffMenuItem )
			main.robot.setRA( false );
		else if ( e.getSource() == rachangeMenuItem )
			main.robot.setRA( !main.robot.rightArm );
		else if ( e.getSource() == laonMenuItem )
			main.robot.setLA( true );
		else if ( e.getSource() == laoffMenuItem )
			main.robot.setLA( false );
		else if ( e.getSource() == lachangeMenuItem )
			main.robot.setLA( !main.robot.leftArm );
		else if ( e.getSource() == rlonMenuItem )
			main.robot.setRL( true );
		else if ( e.getSource() == rloffMenuItem )
			main.robot.setRL( false );
		else if ( e.getSource() == rlchangeMenuItem )
			main.robot.setRL( !main.robot.rightLeg );
		else if ( e.getSource() == llonMenuItem )
			main.robot.setLL( true );
		else if ( e.getSource() == lloffMenuItem )
			main.robot.setLL( false );
		else if ( e.getSource() == llchangeMenuItem )
			main.robot.setLL( !main.robot.leftLeg );
		else if ( e.getSource() == birra ) {
			ImageIcon birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra5.gif" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra );
			birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra1.jpg" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra );
			birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra2.jpg" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra );
			birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra3.jpg" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra );
			birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra4.jpg" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra );
			JOptionPane.showMessageDialog( this, "Che bevuta!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE );
			JOptionPane.showMessageDialog( this, "Buuuuuuurp!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE );
			robotPanel.body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) );
		}
		if ( e.getSource() == esplodi ) {
			String aux = main.robot.getName();
			main.robot.setPositions( false, false, false, false );
			main.robot.setName( "no-name" );
			label.setText( "Robot: " + main.robot.getName() );
			ImageIcon boom = new ImageIcon( ClassLoader.getSystemResource( "img/boom.png" ) );
			JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, boom );
			JOptionPane.showMessageDialog( this, aux + " si è autodistrutto!", "Robottino v4.2", JOptionPane.WARNING_MESSAGE );
			JOptionPane.showMessageDialog( this, "È stato creato un nuovo robottino: " + main.robot.getName(), "Robottino v4.2", JOptionPane.INFORMATION_MESSAGE );
		}
		if ( e.getSource() == informazioni ) {
			String aux = main.robot.getName() + ":\n\n";
			if ( main.robot.rightArm )
				aux += "Braccio destro: alzato\n";
			else
				aux += "Braccio destro: abbassato\n";
			if ( main.robot.leftArm )
				aux += "Braccio sinistro: alzato\n";
			else
				aux += "Braccio sinistro: abbassato\n";
			if ( main.robot.rightLeg )
				aux += "Gamba destra: alzata\n";
			else
				aux += "Gamba destra: abbassata\n";
			if ( main.robot.leftLeg )
				aux += "Gamba sinistra: alzata\n";
			else
				aux += "Gamba sinistra: abbassata\n";
			JOptionPane.showMessageDialog( this, aux, "Robottino - v4.2", JOptionPane.INFORMATION_MESSAGE );
		}
		else if ( e.getSource() == balla ) {
			this.i = 0;
			main.robot.setPositions( false, false, false, false );
			timer = new Timer( 250, 
				new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						Frame.this.i++;
						switch( Frame.this.i ) {
							case 1:
								Frame.main.robot.setRA( true );
								break;
							case 2:
								break;
							case 3:
								Frame.main.robot.setLA( true );
								break;
							case 4:
								break;
							case 5:
								Frame.main.robot.setPositions( false, false, false, true );
								break;
							case 6:
								Frame.main.robot.setPositions( true, true, false, false );
								break;
							case 7:
								Frame.main.robot.setPositions( false, false, true, false );
								break;
							case 8:
								Frame.main.robot.setPositions( true, true, false, false );
								break;
							case 9:
								Frame.main.robot.setPositions( true, false, false, true );
								break;
							case 10:
								Frame.main.robot.setPositions( false, false, false, false );
								break;
							case 11:
								Frame.main.robot.setPositions( true, false, false, true );
								break;
							case 12:
								Frame.main.robot.setPositions( false, true, true, false );
								break;
							case 13:
								Frame.main.robot.setPositions( false, false, false, false );
								break;
							case 14:
								Frame.main.robot.setPositions( false, true, true, false );
								break;
							case 15:
								Frame.main.robot.setPositions( false, false, false, false );
								break;
							case 16:
								break;
							case 17:
								Frame.main.robot.setPositions( false, false, true, false );
								break;
							case 18:
								Frame.main.robot.setPositions( false, false, false, true );
								break;
							case 19:
								Frame.main.robot.setPositions( false, false, true, false );
								break;
							case 20:
								Frame.main.robot.setPositions( false, false, false, true );
								break;
							case 21:
								Frame.main.robot.setPositions( false, false, true, false );
								break;
							case 22:
								Frame.main.robot.setPositions( false, false, false, true );
								break;
							case 23:
								Frame.main.robot.setPositions( true, true, true, true );
								break;
							case 24:
								break;
							case 25:
								break;
							case 26:
								Frame.main.robot.setPositions( false, false, false, false );
								break;
							case 27:
								JOptionPane.showMessageDialog( Frame.this, "Cha fatica!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE );
								JOptionPane.showMessageDialog( Frame.this, Frame.main.robot.getName() + " è tornato alla posizione di partenza", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE );
								break;
							default:
								timer.stop();
								break;
						}
						Frame.this.robotPanel.setImages();
						Frame.this.robotPanel.repaint();
						Frame.this.repaint();
					}
				}
			);
			timer.start();
		}
		try {
			this.robotPanel.setImages();
			this.robotPanel.repaint();
			this.repaint();
		} catch ( NullPointerException n ) { }
	}
}

Generated with cgit - Back to sebastiano.tronto.net