From 7167b4341ef290d56fb96e2af10883a4b925d83b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Mar 2026 19:27:18 +0100 Subject: I found my old code! --- robottino/all_versions/v4.1/src/RobotFrame.java | 312 ++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100755 robottino/all_versions/v4.1/src/RobotFrame.java (limited to 'robottino/all_versions/v4.1/src/RobotFrame.java') diff --git a/robottino/all_versions/v4.1/src/RobotFrame.java b/robottino/all_versions/v4.1/src/RobotFrame.java new file mode 100755 index 0000000..c8cbf13 --- /dev/null +++ b/robottino/all_versions/v4.1/src/RobotFrame.java @@ -0,0 +1,312 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto + +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.event.*; +import java.awt.*; + +public class RobotFrame extends JFrame implements ActionListener { + public static int numeroCopie, i; + public static Main main; + public static RobotPanel robotPanel; + 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, elimina, duplica, birra, balla, esplodi, informazioni; + RobotFrame( String titolo ) { + super ( titolo ); + numeroCopie = 0; + robotPanel = new RobotPanel( titolo ); + rinomina = new JMenuItem( "Cambia nome" ); + elimina = new JMenuItem( "Elimina" ); + duplica = new JMenuItem( "Duplica robot" ); + birra = new JMenuItem( "Birra" ); + balla = new JMenuItem( "Balla" ); + esplodi = new JMenuItem( "Esplodi" ); + informazioni = new JMenuItem( "Informazioni" ); + 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" ); + rinomina.addActionListener( this ); + elimina.addActionListener( this ); + duplica.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( duplica ); + file.add( elimina ); + azioni = new JMenu( "Azioni" ); + azioni.add( birra ); + azioni.add( balla ); + azioni.add( esplodi ); + info = new JMenu( "?" ); + info.add( informazioni ); + barraMenu = new JMenuBar(); + barraMenu.add( file ); + barraMenu.add( azioni ); + barraMenu.add( modifica ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + add( robotPanel ); + } + public void actionPerformed( ActionEvent e ) { + esegui( e ); + } + public void esegui( ActionEvent e ) { + if ( e.getSource() == raonMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = true; + else if ( e.getSource() == raoffMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = false; + else if ( e.getSource() == rachangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = !main.list.getRobot( this.getTitle() ).rightArm; + else if ( e.getSource() == laonMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = true; + else if ( e.getSource() == laoffMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = false; + else if ( e.getSource() == lachangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = !main.list.getRobot( this.getTitle() ).leftArm; + else if ( e.getSource() == rlonMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = true; + else if ( e.getSource() == rloffMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = false; + else if ( e.getSource() == rlchangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = !main.list.getRobot( this.getTitle() ).rightLeg; + else if ( e.getSource() == llonMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = true; + else if ( e.getSource() == lloffMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = false; + else if ( e.getSource() == llchangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = !main.list.getRobot( this.getTitle() ).leftLeg; + else if ( e.getSource() == rinomina ) { + String newName = JOptionPane.showInputDialog( this, "Inserire il nuovo nome per questo robot:", this.getTitle() ); + if ( newName != null ) { + main.list.getRobot( this.getTitle() ).setName( newName ); + this.setTitle( newName ); + robotPanel.nomeRobot = newName; + } + } + else if ( e.getSource() == elimina ) { + int selezione = JOptionPane.showOptionDialog( this, "Eliminare il robottino " + this.getTitle() + " ?", "Robottino v4.1 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.list.deleteRobot( this.getTitle() ); + this.dispose(); + } + } + else if ( e.getSource() == duplica ) { + String newName = JOptionPane.showInputDialog( this, "Inserire il nome per il nuovo robot:", this.getTitle() + " #" + (++numeroCopie) ); + if ( newName != null ) { + main.list.newRobot( main.list.getRobot( this.getTitle() ).leftArm, main.list.getRobot( this.getTitle() ).rightArm, main.list.getRobot( this.getTitle() ).leftLeg, main.list.getRobot( this.getTitle() ).rightLeg, newName ); + } + } + else if ( e.getSource() == birra ) { + ImageIcon birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra5.gif" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra1.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra2.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra3.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra4.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + JOptionPane.showMessageDialog( this, "Che bevuta!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( this, "Buuuuuuurp!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + robotPanel.body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + } + else if ( e.getSource() == balla ) { + this.i = 0; + main.list.getRobot( this.getTitle() ).setPositions( false, false, false, false ); + timer = new Timer( 250, + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + RobotFrame.this.i++; + switch( RobotFrame.this.i ) { + case 1: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setRA( true ); + break; + case 2: + break; + case 3: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setLA( true ); + break; + case 4: + break; + case 5: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 6: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, false, false ); + break; + case 7: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 8: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, false, false ); + break; + case 9: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, false, false, true ); + break; + case 10: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 11: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, false, false, true ); + break; + case 12: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, true, true, false ); + break; + case 13: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 14: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, true, true, false ); + break; + case 15: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 16: + break; + case 17: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 18: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 19: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 20: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 21: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 22: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 23: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, true, true ); + break; + case 24: + break; + case 25: + break; + case 26: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 27: + JOptionPane.showMessageDialog( RobotFrame.this, "Cha fatica!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( RobotFrame.this, RobotFrame.this.getTitle() + " è tornato alla posizione di partenza", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + break; + default: + timer.stop(); + break; + } + RobotFrame.robotPanel.setImages(); + RobotFrame.robotPanel.repaint(); + RobotFrame.this.repaint(); + } + } + ); + timer.start(); + } + if ( e.getSource() == esplodi ) { + String aux = this.getTitle(); + main.list.deleteRobot( this.getTitle() ); + this.dispose(); + ImageIcon boom = new ImageIcon( ClassLoader.getSystemResource( "img/boom.png" ) ); + JOptionPane.showMessageDialog( null, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, boom ); + JOptionPane.showMessageDialog( null, aux + " si è autodistrutto!", "Robottino v4.1", JOptionPane.WARNING_MESSAGE ); + } + if ( e.getSource() == informazioni ) { + String aux = this.getTitle() + ":\n\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).rightArm ) + aux += "Braccio destro: alzato\n"; + else + aux += "Braccio destro: abbassato\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).leftArm ) + aux += "Braccio sinistro: alzato\n"; + else + aux += "Braccio sinistro: abbassato\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).rightLeg ) + aux += "Gamba destra: alzata\n"; + else + aux += "Gamba destra: abbassata\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).leftLeg ) + aux += "Gamba sinistra: alzata\n"; + else + aux += "Gamba sinistra: abbassata\n"; + JOptionPane.showMessageDialog( this, aux, "Robottino - v4.1", JOptionPane.INFORMATION_MESSAGE ); + } + try { + robotPanel.setImages(); + robotPanel.repaint(); + repaint(); + } catch ( NullPointerException n ) { } + } +} \ No newline at end of file -- cgit v1.3