ancient-projects

My earliest programs (2006-2010)
git clone https://git.tronto.net/ancient-projects
Download | Log | Files | Refs | README

Robot.java (3175B)


      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.0 - 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 					else {
     59 						try {
     60 							Thread.currentThread().sleep( 50 );
     61 						} catch ( Exception e2 ) {}
     62 						robotFrame.repaint();
     63 					}
     64 				}
     65 			}
     66 		);
     67 	}
     68 	void setLA( boolean la ) {
     69 		setPositions( la, this.rightArm, this.leftLeg, this.rightLeg );
     70 	}
     71 	void setRA( boolean ra ) {
     72 		setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg );
     73 	}
     74 	void setLL( boolean ll ) {
     75 		setPositions( this.leftArm, this.rightArm, ll, this.rightLeg );
     76 	}
     77 	void setRL( boolean rl ) {
     78 		setPositions( this.leftArm, this.rightArm, this.leftLeg, rl );
     79 	}
     80 	void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) {
     81 		leftArm = la;
     82 		rightArm = ra;
     83 		leftLeg = ll;
     84 		rightLeg = rl;
     85 	}
     86 	void setName( String nome ) {
     87 		nomeRobot = nome;
     88 	}
     89 	boolean getLA() {
     90 		return leftArm;
     91 	}
     92 	boolean getRA() {
     93 		return rightArm;
     94 	}
     95 	boolean getLL() {
     96 		return leftLeg;
     97 	}
     98 	boolean getRL() {
     99 		return rightLeg;
    100 	}
    101 	String getName() {
    102 		return nomeRobot;
    103 	}
    104 	Robot getNext() {
    105 		return prossimoRobot;
    106 	}
    107 }