ancient-projects

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

Frame.java (2389B)


      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 
     25 public class Frame extends JFrame {
     26 	public class Listener implements ActionListener {
     27 		public void actionPerformed( ActionEvent e ) {
     28 			if ( e.getSource() == exit )
     29 				System.exit(0);
     30 			else if ( e.getSource() == informazioni )
     31 				JOptionPane.showMessageDialog( main.frame, "info", "Robottino v4.0 - Informazioni", JOptionPane.INFORMATION_MESSAGE );
     32 			else if ( e.getSource() == nuovo ) {
     33 				String nome = JOptionPane.showInputDialog( main.frame, "Inserire il nome del nuovo robottino:", "Robot " + ( ++main.robots ) );
     34 				if ( nome != null )
     35 					main.list.newRobot( nome );
     36 			}
     37 		}
     38 	}
     39 	public static Listener listener;
     40 	public static Main main;
     41 	public static JMenuBar barraMenu = new JMenuBar();
     42 	public static JMenu file = new JMenu( "File" );
     43 	public static JMenu info = new JMenu( "?" );
     44 	public static JMenuItem exit = new JMenuItem( "Esci" );
     45 	public static JMenuItem informazioni = new JMenuItem( "Informazioni" );
     46 	public static JMenuItem nuovo = new JMenuItem( "Nuovo Robot" );
     47 	public Frame() {
     48 		super( "Robottino versione 4.0" );
     49 		listener = new Listener();
     50 		main = new Main();
     51 		exit.addActionListener( listener );
     52 		exit.setMnemonic( 'E' );
     53 		informazioni.addActionListener( listener );
     54 		informazioni.setMnemonic( 'I' );
     55 		nuovo.addActionListener( listener );
     56 		nuovo.setMnemonic( 'N' );
     57 		file.add( exit );
     58 		file.add( nuovo );
     59 		file.setMnemonic( 'F' );
     60 		info.add( informazioni );
     61 		info.setMnemonic( '?' );
     62 		barraMenu.add( file );
     63 		barraMenu.add( info );
     64 		setJMenuBar( barraMenu );
     65 	}
     66 }