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
| import javax.swing.*;
import java.awt.*;
public class calculator{
public static void main(String args[]){
JFrame f=new JFrame();
f.setSize(300,300);
f.setTitle("Calculatrice");
JTextField textZone = new JTextField();
Container c =f.getContentPane();
c.setLayout(new BorderLayout());
JPanel p = new JPanel();
JPanel p1 = new JPanel();
p.setLayout(new GridLayout(3,3));
p1.setLayout(new GridLayout(4,1));
JButton b1= new JButton("1");
JButton b2= new JButton("2");
JButton b3= new JButton("3");
JButton b4= new JButton("4");
JButton b5= new JButton("5");
JButton b6= new JButton("6");
JButton b7= new JButton("7");
JButton b8= new JButton("8");
JButton b9= new JButton("9");
JButton b0= new JButton("0");
JButton div= new JButton("/");
JButton mul= new JButton("*");
JButton sous= new JButton("-");
JButton plus= new JButton("+");
textZone.setPreferredSize(new Dimension(300,30));
Dimension d=new Dimension(20,20);
b1.setPreferredSize(d);
b2.setPreferredSize(d);
b3.setPreferredSize(d);
b4.setPreferredSize(d);
b5.setPreferredSize(d);
b6.setPreferredSize(d);
b7.setPreferredSize(d);
b8.setPreferredSize(d);
b9.setPreferredSize(d);
b0.setPreferredSize(d);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(b9);
p.add(b0);
p1.add(div);
p1.add(mul);
p1.add(sous);
p1.add(plus);
c.add(p1,"East");
c.add(p,"Center");
c.add(textZone,"North");
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}} |
Partager