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.0/src/RobotFrame.java | 179 ++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100755 robottino/all_versions/v4.0/src/RobotFrame.java (limited to 'robottino/all_versions/v4.0/src/RobotFrame.java') diff --git a/robottino/all_versions/v4.0/src/RobotFrame.java b/robottino/all_versions/v4.0/src/RobotFrame.java new file mode 100755 index 0000000..ad7067f --- /dev/null +++ b/robottino/all_versions/v4.0/src/RobotFrame.java @@ -0,0 +1,179 @@ +/* +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 rax, ray, lax, lay, rlx, rly, llx, lly; + public static Main main; + public static ImageIcon ra, la, rl, ll, body; + public static JMenuBar barraMenu; + public static JMenu modifica, raMenu, laMenu, rlMenu, llMenu; + public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem; + public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem; + RobotFrame( String titolo ) { + super ( titolo ); + rax = 66; + ray = 248; + lax = 225; + lay = 242; + rlx = 84; + rly = 367; + llx = 148; + lly = 367; + ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + 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" ); + 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 ); + barraMenu = new JMenuBar(); + barraMenu.add( modifica ); + setJMenuBar( barraMenu ); + } + public void paint ( Graphics g ) { + super.paint( g ); + body.paintIcon( this, g, 100, 60 ); + ra.paintIcon( this, g, this.rax, this.ray ); + la.paintIcon( this, g, this.lax, this.lay ); + rl.paintIcon( this, g, this.rlx, this.rly ); + ll.paintIcon( this, g, this.llx, this.lly ); + } + 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; + 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; + setImages(); + repaint(); + } + public void setImages() { + if ( main.list.getRobot( this.getTitle() ).rightArm ) { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raon.gif" ) ); + this.rax = 68; + this.ray = 128; + } + else { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + this.rax = 66; + this.ray = 248; + } + if ( main.list.getRobot( this.getTitle() ).leftArm ) { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laon.gif" ) ); + this.lax = 224; + this.lay = 118; + } + else { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + this.lax = 225; + this.lay = 242; + } + if ( main.list.getRobot( this.getTitle() ).rightLeg ) { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rlon.gif" ) ); + this.rlx = 84; + this.rly = 356; + } + else { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + this.rlx = 84; + this.rly = 367; + } + if ( main.list.getRobot( this.getTitle() ).leftLeg ) { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/llon.gif" ) ); + this.llx = 140; + this.lly = 363; + } + else { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + this.llx = 148; + this.lly = 367; + } + } +} \ No newline at end of file -- cgit v1.3