OptionFrame.java (2772B)
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 default: 53 lang = "it"; 54 break; 55 } 56 formatter.format( lang ); 57 formatter.close(); 58 main.settaOpzioni(); 59 main.frame.pannello.repaint(); 60 main.frame.repaint(); 61 OptionFrame.this.dispose(); 62 JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); 63 } 64 }); 65 annulla = new JButton( main.stringaAnnulla ); 66 annulla.addActionListener( new ActionListener() { 67 public void actionPerformed( ActionEvent e ) { 68 OptionFrame.this.dispose(); 69 } 70 }); 71 lingua = new JLabel( main.stringaLingua ); 72 String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa }; 73 selezionaLingua = new JComboBox( lingueDaSelezionare ); 74 pannello1 = new JPanel( new FlowLayout() ); 75 pannello1.add( lingua ); 76 pannello1.add( selezionaLingua ); 77 pannello2 = new JPanel( new FlowLayout() ); 78 pannello2.add( ok ); 79 pannello2.add( annulla ); 80 add( pannello1, BorderLayout.CENTER ); 81 add( pannello2, BorderLayout.SOUTH ); 82 } 83 }