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
| import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TP_calc_Fenetre extends JFrame {
//Creation du JPanel qui contiendra tt les autre=>le Jpanel par defaut ne sera pas supprime
JPanel pan =new JPanel();
public TP_calc_Fenetre(){
this.setTitle("TP-Calculette");
this.setSize(300, 450);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
getContentPane().add(pan);//ajout du JPanel pour le rendre visible
tableau01();
tableau02();
}
//Pour les chiffres
private void tableau01(){
//Creation d'un nouveau JPanel pour les chiffres
JPanel pan_t01= new JPanel();
pan.add(pan_t01, BorderLayout.CENTER);//ajout de ce JPanel
//Ajout des boutons ss forme de tableau
pan_t01.setLayout(new GridLayout(4,3,5,5));//ds l'ordre (ligne,colonne,espacement de 5px(x;y)
pan_t01.add(new JButton("1"));
pan_t01.add(new JButton("2"));
pan_t01.add(new JButton("3"));
pan_t01.add(new JButton("4"));
pan_t01.add(new JButton("5"));
pan_t01.add(new JButton("6"));
pan_t01.add(new JButton("7"));
pan_t01.add(new JButton("8"));
pan_t01.add(new JButton("9"));
pan_t01.add(new JButton(","));
pan_t01.add(new JButton("0"));
pan_t01.add(new JButton("="));
}
//Pour les Operations
private void tableau02(){
//Creation d'un nouveau JPanel pour les Operations
JPanel pan_t02= new JPanel();
pan.add(pan_t02, BorderLayout.WEST);//ajout de ce JPanel
//Ajout des boutons ss forme de tableau
pan_t02.setLayout(new GridLayout(5,1,15,5));//ds l'ordre (ligne,colonne,espacement de 5px(x;y)
pan_t02.add(new JButton("C"));
pan_t02.add(new JButton("+"));
pan_t02.add(new JButton("-"));
pan_t02.add(new JButton("*"));
pan_t02.add(new JButton("/"));
}
} |
Partager