diff options
Diffstat (limited to 'robottino/all_versions/v2.3/src/RobottinoUtils')
3 files changed, 304 insertions, 0 deletions
diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java b/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java new file mode 100755 index 0000000..b845a7f --- /dev/null +++ b/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | // Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. | ||
| 2 | package RobottinoUtils; | ||
| 3 | |||
| 4 | // Importo i package standard relativi al funzionamento delle finestre e della grafica in generale. | ||
| 5 | import java.awt.*; | ||
| 6 | |||
| 7 | // E i package RobottinoAzioni e RobottinoUtils da me definiti. | ||
| 8 | import RobottinoAzioni.*; | ||
| 9 | import RobottinoUtils.Listener; | ||
| 10 | |||
| 11 | // La classe è una sottoclasse di Frame per poter sfruttare gli effetti grafici | ||
| 12 | // ma implementa anche l'interfaccia WindowListener, necessaria per gestire gli eventi collegati alle finestre | ||
| 13 | // (riduzione a icona, chiusura...); per questo devo successivamente ridefinire tutti i | ||
| 14 | // metodi dell'interfaccia. | ||
| 15 | public class Grafica extends Frame { | ||
| 16 | |||
| 17 | // Creo un'istanza della classe Listener che userò come listener per gli eventi. | ||
| 18 | public static Listener listener; | ||
| 19 | |||
| 20 | // Il costruttore senza argomenti. | ||
| 21 | public Grafica () { | ||
| 22 | |||
| 23 | // Il metodo "setBounds" posiziona e dimensiona la finestra. | ||
| 24 | setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza); | ||
| 25 | |||
| 26 | // "setTitle" per il titolo della finestra. | ||
| 27 | setTitle ("Robottino v2.2"); | ||
| 28 | |||
| 29 | // "setVisible" per poterla visualizzare. | ||
| 30 | setVisible (true); | ||
| 31 | |||
| 32 | // E addWindowListener per l'ascoltatore (listener). | ||
| 33 | listener = new Listener(); | ||
| 34 | addWindowListener (listener); | ||
| 35 | |||
| 36 | // Aggiungo la barra del menu con i vari sottomenu | ||
| 37 | setMenuBar (barraMenu); | ||
| 38 | |||
| 39 | // Il menu file. | ||
| 40 | NewRobot.addActionListener(listener); | ||
| 41 | NewRobot.setActionCommand("newrobot"); | ||
| 42 | |||
| 43 | ChangeRobot.addActionListener(listener); | ||
| 44 | ChangeRobot.setActionCommand("changerobot"); | ||
| 45 | |||
| 46 | DeleteRobot.addActionListener(listener); | ||
| 47 | DeleteRobot.setActionCommand("deleterobot"); | ||
| 48 | |||
| 49 | Exit.addActionListener(listener); | ||
| 50 | Exit.setActionCommand("exit"); | ||
| 51 | |||
| 52 | file.add(NewRobot); | ||
| 53 | file.add(ChangeRobot); | ||
| 54 | file.add(DeleteRobot); | ||
| 55 | file.addSeparator(); | ||
| 56 | file.add(Exit); | ||
| 57 | |||
| 58 | barraMenu.add(file); | ||
| 59 | |||
| 60 | // Il braccio sinistro. | ||
| 61 | LeftArmMove.addActionListener(listener); | ||
| 62 | LeftArmMove.setActionCommand("leftarmmove"); | ||
| 63 | |||
| 64 | LeftArmOn.addActionListener(listener); | ||
| 65 | LeftArmOn.setActionCommand("leftarmon"); | ||
| 66 | |||
| 67 | LeftArmOff.addActionListener(listener); | ||
| 68 | LeftArmOff.setActionCommand("leftarmoff"); | ||
| 69 | |||
| 70 | LeftArm.add(LeftArmMove); | ||
| 71 | LeftArm.add(LeftArmOn); | ||
| 72 | LeftArm.add(LeftArmOff); | ||
| 73 | |||
| 74 | // Il braccio destro. | ||
| 75 | RightArmMove.addActionListener(listener); | ||
| 76 | RightArmMove.setActionCommand("rightarmmove"); | ||
| 77 | |||
| 78 | RightArmOn.addActionListener(listener); | ||
| 79 | RightArmOn.setActionCommand("rightarmon"); | ||
| 80 | |||
| 81 | RightArmOff.addActionListener(listener); | ||
| 82 | RightArmOff.setActionCommand("rightarmoff"); | ||
| 83 | |||
| 84 | RightArm.add(RightArmMove); | ||
| 85 | RightArm.add(RightArmOn); | ||
| 86 | RightArm.add(RightArmOff); | ||
| 87 | |||
| 88 | // La gamba sinistra. | ||
| 89 | LeftLegMove.addActionListener(listener); | ||
| 90 | LeftLegMove.setActionCommand("leftlegmove"); | ||
| 91 | |||
| 92 | LeftLegOn.addActionListener(listener); | ||
| 93 | LeftLegOn.setActionCommand("leftlegon"); | ||
| 94 | |||
| 95 | LeftLegOff.addActionListener(listener); | ||
| 96 | LeftLegOff.setActionCommand("leftlegoff"); | ||
| 97 | |||
| 98 | LeftLeg.add(LeftLegMove); | ||
| 99 | LeftLeg.add(LeftLegOn); | ||
| 100 | LeftLeg.add(LeftLegOff); | ||
| 101 | |||
| 102 | // La gamba destra. | ||
| 103 | RightLegMove.addActionListener(listener); | ||
| 104 | RightLegMove.setActionCommand("rightlegmove"); | ||
| 105 | |||
| 106 | RightLegOn.addActionListener(listener); | ||
| 107 | RightLegOn.setActionCommand("rightlegon"); | ||
| 108 | |||
| 109 | RightLegOff.addActionListener(listener); | ||
| 110 | RightLegOff.setActionCommand("rightlegoff"); | ||
| 111 | |||
| 112 | RightLeg.add(RightLegMove); | ||
| 113 | RightLeg.add(RightLegOn); | ||
| 114 | RightLeg.add(RightLegOff); | ||
| 115 | |||
| 116 | // Menu rinomina. | ||
| 117 | Rename.addActionListener(listener); | ||
| 118 | Rename.setActionCommand("rename"); | ||
| 119 | |||
| 120 | Menu modifica = new Menu("Modifica"); | ||
| 121 | modifica.add(LeftArm); | ||
| 122 | modifica.add(RightArm); | ||
| 123 | modifica.add(LeftLeg); | ||
| 124 | modifica.add(RightLeg); | ||
| 125 | modifica.addSeparator(); | ||
| 126 | modifica.add(Rename); | ||
| 127 | |||
| 128 | barraMenu.add(modifica); | ||
| 129 | |||
| 130 | // Menu azioni. | ||
| 131 | Exploud.addActionListener(listener); | ||
| 132 | Exploud.setActionCommand("exploud"); | ||
| 133 | |||
| 134 | Bier.addActionListener(listener); | ||
| 135 | Bier.setActionCommand("bier"); | ||
| 136 | |||
| 137 | xxx.addActionListener(listener); | ||
| 138 | xxx.setActionCommand("xxx"); | ||
| 139 | |||
| 140 | Dance.addActionListener(listener); | ||
| 141 | Dance.setActionCommand("dance"); | ||
| 142 | |||
| 143 | azioni.add(Exploud); | ||
| 144 | azioni.add(Bier); | ||
| 145 | azioni.add(xxx); | ||
| 146 | azioni.add(Dance); | ||
| 147 | |||
| 148 | barraMenu.add(azioni); | ||
| 149 | |||
| 150 | // Menu info. | ||
| 151 | Porky.addActionListener(listener); | ||
| 152 | Porky.setActionCommand("porky"); | ||
| 153 | |||
| 154 | l.addActionListener(listener); | ||
| 155 | l.setActionCommand("l"); | ||
| 156 | |||
| 157 | RobotList.addActionListener(listener); | ||
| 158 | RobotList.setActionCommand("robotlist"); | ||
| 159 | |||
| 160 | info.add(Porky); | ||
| 161 | info.add(l); | ||
| 162 | info.add(RobotList); | ||
| 163 | |||
| 164 | barraMenu.add(info); | ||
| 165 | } | ||
| 166 | |||
| 167 | // Le variabili pubbliche di classe per il metodo "setBounds". | ||
| 168 | public int orizzontale = 0; | ||
| 169 | public int verticale = 0; | ||
| 170 | public int larghezza = 500; | ||
| 171 | public int altezza = 500; | ||
| 172 | |||
| 173 | // E i vari Menu e MenuItem. | ||
| 174 | MenuBar barraMenu = new MenuBar(); | ||
| 175 | Menu file = new Menu("File"); | ||
| 176 | MenuItem NewRobot = new MenuItem("Nuovo robot"); | ||
| 177 | MenuItem ChangeRobot = new MenuItem("Dai i comandi a un altro robot"); | ||
| 178 | MenuItem DeleteRobot = new MenuItem("Elimina un robot"); | ||
| 179 | MenuItem Exit = new MenuItem("Esci"); | ||
| 180 | Menu LeftArm = new Menu("Braccio sinistro"); | ||
| 181 | MenuItem LeftArmMove = new MenuItem("Cambia posizione"); | ||
| 182 | MenuItem LeftArmOn = new MenuItem("Alza"); | ||
| 183 | MenuItem LeftArmOff = new MenuItem("Abbassa"); | ||
| 184 | Menu RightArm = new Menu("Braccio destro"); | ||
| 185 | MenuItem RightArmMove = new MenuItem("Cambia posizione"); | ||
| 186 | MenuItem RightArmOn = new MenuItem("Alza"); | ||
| 187 | MenuItem RightArmOff = new MenuItem("Abbassa"); | ||
| 188 | Menu LeftLeg = new Menu("Gamba sinistra"); | ||
| 189 | MenuItem LeftLegMove = new MenuItem("Cambia posizione"); | ||
| 190 | MenuItem LeftLegOn = new MenuItem("Alza"); | ||
| 191 | MenuItem LeftLegOff = new MenuItem("Abbassa"); | ||
| 192 | Menu RightLeg = new Menu("Gamba destra"); | ||
| 193 | MenuItem RightLegMove = new MenuItem("Cambia posizione"); | ||
| 194 | MenuItem RightLegOn = new MenuItem("Alza"); | ||
| 195 | MenuItem RightLegOff = new MenuItem("Abbassa"); | ||
| 196 | MenuItem Rename = new MenuItem("Rinomina"); | ||
| 197 | Menu azioni = new Menu("Azioni"); | ||
| 198 | MenuItem Exploud = new MenuItem("Esplodi"); | ||
| 199 | MenuItem Bier = new MenuItem("Birra"); | ||
| 200 | MenuItem xxx = new MenuItem("xxx"); | ||
| 201 | MenuItem Dance = new MenuItem("Balla"); | ||
| 202 | Menu info = new Menu("?"); | ||
| 203 | MenuItem Porky = new MenuItem("Informazioni sul programmatore"); | ||
| 204 | MenuItem l = new MenuItem("Legenda Comandi"); | ||
| 205 | MenuItem RobotList = new MenuItem("Lista robot"); | ||
| 206 | } | ||
| 207 | |||
| 208 | |||
| 209 | |||
| 210 | |||
diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/Listener.java b/robottino/all_versions/v2.3/src/RobottinoUtils/Listener.java new file mode 100755 index 0000000..90e617c --- /dev/null +++ b/robottino/all_versions/v2.3/src/RobottinoUtils/Listener.java | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | // Questa classe è il listener per gli eventi relativi alle finestre. | ||
| 2 | // Dichiaro che farà parte del package RobottinoUtils | ||
| 3 | package RobottinoUtils; | ||
| 4 | |||
| 5 | // Importo i package necessari. | ||
| 6 | import java.awt.event.*; | ||
| 7 | import RobottinoMain.*; | ||
| 8 | import RobottinoAzioni.*; | ||
| 9 | |||
| 10 | public class Listener implements WindowListener, ActionListener { | ||
| 11 | |||
| 12 | RobottinoAzioni robottinoazioni = new RobottinoAzioni(); | ||
| 13 | |||
| 14 | // Ridefinisco i metodi dell'interfaccia WindowListener: | ||
| 15 | // Metodo invocato quando la finestra è stata chiusa: | ||
| 16 | public void windowClosed (WindowEvent evt) { | ||
| 17 | |||
| 18 | // Invoco il metodo sleep(int millisecondi) per mettere il programma in uno stato di attesa | ||
| 19 | // di durata pari ai millisecondi indicati come argomento. | ||
| 20 | System.out.println("La finestra è stata chiusa, il programma terminarà fra 3 secondi"); | ||
| 21 | try { | ||
| 22 | Robottino.threadMain.sleep(1000); | ||
| 23 | } catch (Exception e) { e.printStackTrace(); } | ||
| 24 | System.out.println("2"); | ||
| 25 | try { | ||
| 26 | Robottino.threadMain.sleep(1000); | ||
| 27 | } catch (Exception e) { e.printStackTrace(); } | ||
| 28 | System.out.println("1"); | ||
| 29 | try { | ||
| 30 | Robottino.threadMain.sleep(1000); | ||
| 31 | } catch (Exception e) { e.printStackTrace(); } | ||
| 32 | System.out.println("Programma terminato"); | ||
| 33 | System.exit(0); | ||
| 34 | } | ||
| 35 | |||
| 36 | // Metodo invocato quando la finestra è in fase di chiusura: | ||
| 37 | public void windowClosing (WindowEvent evt) { | ||
| 38 | System.out.println ("Chiusura finestra in corso"); | ||
| 39 | evt.getWindow().dispose(); | ||
| 40 | } | ||
| 41 | |||
| 42 | // Metodo invocato quando una finestra viene ridotta a icona: | ||
| 43 | public void windowIconified (WindowEvent evt) { | ||
| 44 | System.out.println("La finestra è stata ridotta a icona"); | ||
| 45 | } | ||
| 46 | |||
| 47 | // Metodo invocato quando una finestra ridotta a icona viene ingrandita: | ||
| 48 | public void windowDeiconified (WindowEvent evt) { | ||
| 49 | System.out.println("La finestra ridotta a icona è stata ingrandita"); | ||
| 50 | } | ||
| 51 | |||
| 52 | // Metodo invocato quando una finestra viene aperta: | ||
| 53 | public void windowOpened (WindowEvent evt) {} | ||
| 54 | |||
| 55 | // Metodo invocato quando una finestra diventa attiva: | ||
| 56 | public void windowActivated (WindowEvent evt) {} | ||
| 57 | |||
| 58 | // Metodo invocato quando una finestra viene disattivata: | ||
| 59 | public void windowDeactivated (WindowEvent evt) {} | ||
| 60 | |||
| 61 | // Metodo invocato quando viene utilizzata la barra del menu: | ||
| 62 | // descrive tutte le azioni da compiere per ogni evento ricevuto | ||
| 63 | // dal menu. | ||
| 64 | public void actionPerformed (ActionEvent e) { | ||
| 65 | System.out.println (robottinoazioni.Azioni(e.getActionCommand(), RobottinoAzioni.nomeRobot, RobottinoAzioni.pdrA)); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/PartiDelRobot.java b/robottino/all_versions/v2.3/src/RobottinoUtils/PartiDelRobot.java new file mode 100755 index 0000000..d6cf869 --- /dev/null +++ b/robottino/all_versions/v2.3/src/RobottinoUtils/PartiDelRobot.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | // Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. | ||
| 2 | package RobottinoUtils; | ||
| 3 | |||
| 4 | // Dichiaro la classe. | ||
| 5 | public class PartiDelRobot { | ||
| 6 | |||
| 7 | // Creo un costruttore senza argomenti. | ||
| 8 | // Se non lo facessi sarei obbligato a passare gli argomenti | ||
| 9 | // del secondo costruttore ogni volta che voglio istanziare la classe. | ||
| 10 | public PartiDelRobot() {} | ||
| 11 | |||
| 12 | // Il secondo costruttore riceve come argomenti un booleano che passerà il valore a "statoParte" | ||
| 13 | // e una stringa che passa il valore a "stringaParte". | ||
| 14 | public PartiDelRobot(boolean b, String s) { | ||
| 15 | this.stringaParte = s; | ||
| 16 | this.statoParte = b; | ||
| 17 | } | ||
| 18 | |||
| 19 | // Infine le due variabili pubbliche della classe. | ||
| 20 | public String stringaParte; | ||
| 21 | public boolean statoParte; | ||
| 22 | } | ||
