/* Copyright 2009 Sebastiano Tronto This file is part of JBriscola. JBriscola 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. JBriscola 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 JBriscola; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.util.Formatter; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class OptionFrame extends JFrame { public static Main main = new Main(); public static Formatter formatter; public static JButton ok, annulla, scegliColore; public static JLabel lingua, sfondo; public static JComboBox selezionaLingua; public static JCheckBox suono; public static JPanel[] pannello = new JPanel[5]; public OptionFrame() { super( "JBriscola - " + main.stringaModificaOpzioni ); ok = new JButton( "OK" ); ok.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { try { formatter = new Formatter( "JBriscolaConfig.txt" ); } catch ( Exception ex ) { JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); } String lang; switch ( selezionaLingua.getSelectedIndex() ) { case 0: lang = "it"; break; case 1: lang = "la"; break; case 2: lang = "bl"; break; case 3: lang = "bv"; break; default: lang = "it"; break; } String suonosiono; if ( suono.isSelected() ) suonosiono = "suono=si"; else suonosiono = "suono=no"; formatter.format( lang ); formatter.format( "\n" ); formatter.format( suonosiono ); formatter.format( "\n" ); formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); formatter.close(); main.settaOpzioni(); OptionFrame.this.dispose(); //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); } }); annulla = new JButton( main.stringaAnnulla ); annulla.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { OptionFrame.this.dispose(); } }); scegliColore = new JButton( " " ); scegliColore.setBackground( main.color ); scegliColore.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); if ( colore != null ) main.color = colore; OptionFrame.scegliColore.setBackground( main.color ); } } ); lingua = new JLabel( main.stringaLingua ); sfondo = new JLabel( main.stringaSfondo ); String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; selezionaLingua = new JComboBox( lingueDaSelezionare ); int linguaPreselezionata = 0; if ( main.lang.equals( "it" ) ) linguaPreselezionata = 0; else if ( main.lang.equals( "la" ) ) linguaPreselezionata = 1; else if ( main.lang.equals( "bl" ) ) linguaPreselezionata = 2; else if ( main.lang.equals( "bv" ) ) linguaPreselezionata = 3; selezionaLingua.setSelectedIndex( linguaPreselezionata ); suono = new JCheckBox( main.stringaSuono ); suono.setSelected( main.sound ); pannello[0] = new JPanel( new GridLayout( 3, 1 ) ); pannello[1] = new JPanel( new FlowLayout() ); pannello[2] = new JPanel( new FlowLayout() ); pannello[3] = new JPanel( new FlowLayout() ); pannello[4] = new JPanel( new FlowLayout() ); pannello[4].add( ok ); pannello[4].add( annulla ); pannello[3].add( sfondo ); pannello[3].add( scegliColore ); pannello[2].add( suono ); pannello[1].add( lingua ); pannello[1].add( selezionaLingua ); pannello[0].add( pannello[1] ); pannello[0].add( pannello[2] ); pannello[0].add( pannello[3] ); add( pannello[0], BorderLayout.CENTER ); add( pannello[4], BorderLayout.SOUTH ); } }