ancient-projects

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

OptionFrame.java (2833B)


      1 /*
      2 Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
      3 
      4 This file is part of JBriscola.
      5 
      6     JBriscola 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     JBriscola 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 JBriscola; 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 java.util.Formatter;
     23 import javax.swing.*;
     24 import java.awt.*;
     25 import java.awt.event.*;
     26 
     27 public class OptionFrame extends JFrame {
     28 	public static Main main = new Main();
     29 	public static Formatter formatter;
     30 	public static JButton ok, annulla;
     31 	public static JLabel lingua;
     32 	public static JComboBox selezionaLingua;
     33 	public static JPanel pannello1, pannello2;
     34 	public OptionFrame() {
     35 		super( "JBriscola - " + main.stringaModificaOpzioni );
     36 		ok = new JButton( "OK" );
     37 		ok.addActionListener( new ActionListener() {
     38 			public void actionPerformed( ActionEvent e ) {
     39 				try {
     40 					formatter = new Formatter( "JBriscolaConfig.txt" );
     41 				} catch ( Exception ex ) {
     42 					JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex );
     43 				}
     44 				String lang;
     45 				switch ( selezionaLingua.getSelectedIndex() ) {
     46 					case 0:
     47 						lang = "it";
     48 						break;
     49 					case 1:
     50 						lang = "la";
     51 						break;
     52 					case 2:
     53 						lang = "bl";
     54 						break;
     55 					case 3:
     56 						lang = "bv";
     57 						break;
     58 					default:
     59 						lang = "it";
     60 						break;
     61 				}
     62 				formatter.format( lang );
     63 				formatter.close();
     64 				main.settaOpzioni();
     65 				OptionFrame.this.dispose();
     66 				JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE );
     67 			}
     68 		});
     69 		annulla = new JButton( main.stringaAnnulla );
     70 		annulla.addActionListener( new ActionListener() {
     71 			public void actionPerformed( ActionEvent e ) {
     72 				OptionFrame.this.dispose();
     73 			}
     74 		});
     75 		lingua = new JLabel( main.stringaLingua );
     76 		String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV };
     77 		selezionaLingua = new JComboBox( lingueDaSelezionare );
     78 		pannello1 = new JPanel( new FlowLayout() );
     79 		pannello1.add( lingua );
     80 		pannello1.add( selezionaLingua );
     81 		pannello2 = new JPanel( new FlowLayout() );
     82 		pannello2.add( ok );
     83 		pannello2.add( annulla );
     84 		add( pannello1, BorderLayout.CENTER );
     85 		add( pannello2, BorderLayout.SOUTH );
     86 	}
     87 }