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
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
class Menus extends JFrame implements ActionListener
{
private JPanel pan1, pan2;
private JTextArea texte;
private JPasswordField password;
private JMenuItem choix1, choix2;
private JMenu fichier;
private JMenuBar menu;
public Menus()
{
setTitle("Titre de ma page");
setBounds(50,50,800,800);
//Barre de menus
menu = new JMenuBar();
setJMenuBar(menu);
fichier = new JMenu("Fichier");
menu.add(fichier);
choix1 = new JMenuItem("Champ password");
fichier.add(choix1);
choix1.addActionListener(this);
choix2 = new JMenuItem("Champ texte");
fichier.add(choix2);
choix2.addActionListener(this);
//Différents panneaux
pan1 = new JPanel();
password = new JPasswordField(20);
pan1.add(password);
pan2 = new JPanel();
texte = new JTextArea("rrr");
pan2.add(texte);
getContentPane().add(pan1);
}
@Override
public void actionPerformed(ActionEvent arg0)
{
Object source = arg0.getSource();
if(source == choix1)
{
getContentPane().removeAll();
getContentPane().add(pan1);
}
if(source == choix2)
{
getContentPane().removeAll();
getContentPane().add(pan2);
}
// TODO Auto-generated method stub
}
public static void main(String[] args)
{
Menus fe = new Menus();
fe.setVisible(true);
fe.setDefaultCloseOperation(fe.EXIT_ON_CLOSE);
}
} |
Partager