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
| import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Font;
import java.awt.Dimension;
public class My_Window extends JFrame {
private static final String Listeners = null;
JLabel screen = new JLabel();
JPanel container = new JPanel();
JPanel operateurs = new JPanel();
JPanel numbers = new JPanel();
JPanel panScreen = new JPanel();
public My_Window()
{
this.setTitle("Simple Count");
this.setSize(300, 400);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.container.setBackground(Color.GRAY);
this.setContentPane(container);
this.setVisible(true);
}
public void Panel_Police()
{
Font police = new Font("Arial", Font.BOLD, 30);
this.screen.setFont(police);
this.screen.setHorizontalAlignment(JLabel.CENTER);
this.screen.setPreferredSize(new Dimension(200, 300));
this.screen.setHorizontalAlignment(JLabel.RIGHT);
this.screen.setPreferredSize(new Dimension(220, 20));
this.operateurs.setPreferredSize(new Dimension(55, 225));
this.numbers.setPreferredSize(new Dimension(220, 300));
this.panScreen.setPreferredSize(new Dimension(220, 50));
}
public void My_Buttons()
{
String[] numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
String[] pad = {"C", "=", ".", "+", "-", "*", "/"};
JButton[] nbButtons = new JButton[numbers.length];
JButton[] opButtons = new JButton[pad.length];
int i = 0;
while (numbers.length != i)
{
nbButtons[i] = new JButton(numbers[i]);
this.numbers.add(nbButtons[i]);
nbButtons[i].addActionListener(new Listeners.nbListener()/*new nbListener()*/);
this.setPreferredSize(new Dimension(50, 100));
i++;
}
i = 0;
while (pad.length != i)
{
if (pad[i] != "C")
this.operateurs.add(new JButton(pad[i]));
else
this.operateurs.add(new JButton(pad[i])).setForeground(Color.red);
this.setPreferredSize(new Dimension(200, 100));
i++;
}
}
public void Add_to_container()
{
this.panScreen.add(screen);
this.panScreen.setBorder(BorderFactory.createLineBorder(Color.black));
this.container.add(panScreen, BorderLayout.NORTH);
this.container.add(numbers, BorderLayout.CENTER);
this.container.add(operateurs, BorderLayout.EAST);
}
public JLabel getScreen()
{
return (this.screen);
}
} |
Partager