1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class MenuProjet1 extends JFrame {
private JRadioButtonMenuItem langueItems[];
private JLabel displayLabel ;
private JMenuItem aboutItem,exitItem,DevItem,CarreItem ;
private JMenu fileMenu,langMenu,jeuMenu ;
private ButtonGroup langueGroup;
public static String s1="";
public static String s2="";
private Dev devine;
private Matr M;
private static Locale locale = null;
private static ResourceBundle bundle = null;
public MenuProjet1()
{
super( bundle.getString("lbltitle") );
JMenu fileMenu = new JMenu( bundle.getString("fileMenuCaption") );
char F;
String S1=bundle.getString("Fsym");
F=S1.charAt(0);
fileMenu.setMnemonic(F);
JMenuItem aboutItem = new JMenuItem(bundle.getString("aboutCaption"));
char A;
String S2=bundle.getString("Asym");
A=S2.charAt(0);
aboutItem.setMnemonic(A);
fileMenu.add( aboutItem );
aboutItem.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( MenuProjet1.this,
bundle.getString("msgCaption"),
bundle.getString("aboutCaption"), JOptionPane.PLAIN_MESSAGE );
}
}
);
JMenuItem exitItem = new JMenuItem( bundle.getString("exitCaption") );
char X;
String S3= bundle.getString("Xsym");
X=S3.charAt(0);
exitItem.setMnemonic(X);
fileMenu.add( exitItem );
exitItem.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent event )
{
System.exit( 0 );
}
}
);
JMenu jeuMenu = new JMenu(bundle.getString("jeuCaption"));
char J;
String S0=bundle.getString("Jsym");
J=S0.charAt(0);
jeuMenu.setMnemonic(J);
JMenuItem DevItem = new JMenuItem ( bundle.getString("devCaption"));
jeuMenu.add(DevItem);
DevItem.addActionListener(
new ActionListener() {
public void actionPerformed (ActionEvent event)
{
devine = new Dev(s1,s2);
}
}
);
JMenuItem CarreItem = new JMenuItem ( bundle.getString("CarreCaption"));
jeuMenu.add(CarreItem);
CarreItem.addActionListener(
new ActionListener() {
public void actionPerformed (ActionEvent event)
{
M = new Matr(s1,s2);
}
}
);
JMenuBar bar = new JMenuBar();
setJMenuBar( bar );
bar.add( fileMenu );
bar.add(jeuMenu);
String langues[] = { bundle.getString("agCaption"), bundle.getString("frCaption"),bundle.getString("arCaption")};
JMenu langueMenu = new JMenu( bundle.getString("langueCaption"));
char L;
String S4=bundle.getString("Lsym");
L=S4.charAt(0);
langueMenu.setMnemonic(L);
langueItems = new JRadioButtonMenuItem[ langues.length ];
langueGroup = new ButtonGroup();
ItemHandler itemHandler = new ItemHandler();
for ( int count = 0; count < langues.length; count++ ) {
langueItems[ count ] =
new JRadioButtonMenuItem( langues[ count ] );
langueMenu.add( langueItems[ count ] );
langueGroup.add( langueItems[ count ] );
langueItems[ count ].addActionListener( itemHandler );
}
langueItems[ 0 ].setSelected( true );
bar.add( langueMenu );
displayLabel = new JLabel( bundle.getString("lblCaption"), SwingConstants.CENTER );
displayLabel.setForeground( Color.BLUE );
displayLabel.setFont( new Font( "Serif", Font.PLAIN, 72 ) );
getContentPane().setBackground( Color.CYAN );
getContentPane().add( displayLabel, BorderLayout.CENTER );
setSize( 500, 200 );
setVisible( true );
}
public static void main( String args[] )
{
locale = new Locale("en","US");
bundle = ResourceBundle.getBundle("RMenuProjet", locale);
MenuProjet1 application =new MenuProjet1();
s1="en";
s2="US";
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
private class ItemHandler implements ActionListener {
public void actionPerformed( ActionEvent event )
{
if ( langueItems[ 0 ].isSelected() ) {
s1="en";
s2="US";
locale = new Locale(s1,s2);
bundle = ResourceBundle.getBundle("RMenuProjet", locale);
displayLabel.setText(bundle.getString("lblCaption"));
}
else
{
s1="fr";
s2="FR";
locale = new Locale(s1,s2);
bundle = ResourceBundle.getBundle("RMenuProjet", locale);
displayLabel.setText(bundle.getString("lblCaption"));
}
}
}
}
bonne lecture et merci
PS:Dev et Carre sont des jeux,pour le test :cry: |
Partager