Robot.java (3059B)
1 /* 2 Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> 3 4 This file is part of Robottino. 5 6 Robottino is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 Robottino is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Robottino; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 20 */ 21 22 import javax.swing.*; 23 import java.awt.event.*; 24 import java.awt.*; 25 26 public class Robot { 27 public static Main main = new Main(); 28 boolean leftArm, rightArm, leftLeg, rightLeg; 29 String nomeRobot; 30 Robot precedenteRobot, prossimoRobot; 31 RobotFrame robotFrame; 32 Robot() { 33 this( false, false, false, false, "", main.list.ultimoRobot, null ); 34 } 35 Robot( String nome ) { 36 this ( false, false, false, false, nome, main.list.ultimoRobot, null ); 37 } 38 Robot( boolean la, boolean ra, boolean ll, boolean rl, String nome, Robot prec, Robot prox ) { 39 leftArm = la; 40 rightArm = ra; 41 leftLeg = ll; 42 rightLeg = rl; 43 nomeRobot = nome; 44 precedenteRobot = prec; 45 prossimoRobot = prox; 46 robotFrame = new RobotFrame( nome ); 47 robotFrame.setSize( 350, 600 ); 48 robotFrame.setVisible( true ); 49 robotFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); 50 robotFrame.addWindowListener( 51 new WindowAdapter() { 52 public void windowClosing( WindowEvent e ) { 53 int selezione = JOptionPane.showOptionDialog( Robot.this.robotFrame, "Eliminare il robottino " + Robot.this.getName() + " ?", "Robottino v4.1 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); 54 if ( selezione == JOptionPane.YES_OPTION ) { 55 main.list.deleteRobot( Robot.this.getName() ); 56 robotFrame.dispose(); 57 } 58 } 59 } 60 ); 61 } 62 void setLA( boolean la ) { 63 setPositions( la, this.rightArm, this.leftLeg, this.rightLeg ); 64 } 65 void setRA( boolean ra ) { 66 setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg ); 67 } 68 void setLL( boolean ll ) { 69 setPositions( this.leftArm, this.rightArm, ll, this.rightLeg ); 70 } 71 void setRL( boolean rl ) { 72 setPositions( this.leftArm, this.rightArm, this.leftLeg, rl ); 73 } 74 void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) { 75 this.leftArm = la; 76 this.rightArm = ra; 77 this.leftLeg = ll; 78 this.rightLeg = rl; 79 } 80 void setName( String nome ) { 81 nomeRobot = nome; 82 } 83 boolean getLA() { 84 return leftArm; 85 } 86 boolean getRA() { 87 return rightArm; 88 } 89 boolean getLL() { 90 return leftLeg; 91 } 92 boolean getRL() { 93 return rightLeg; 94 } 95 String getName() { 96 return nomeRobot; 97 } 98 Robot getNext() { 99 return prossimoRobot; 100 } 101 }