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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Description
*
* @version 1.0 from 25/04/2023
* @author
*/
public class KAKA extends JFrame {
// start attributes
private JLabel jLabel1 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JTextField jTextField2 = new JTextField();
private JLabel jLabel5 = new JLabel();
private JTextField jTextField3 = new JTextField();
private JCheckBox jCheckBox1 = new JCheckBox();
private JCheckBox jCheckBox2 = new JCheckBox();
// end attributes
public KAKA(String title) {
// Frame-Init
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 297;
int frameHeight = 404;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
// start components
cp.setBackground(Color.CYAN);
jLabel1.setBounds(120, 24, 46, 41);
jLabel1.setText("Coté");
jLabel1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
cp.add(jLabel1);
jTextField1.setBounds(216, 32, 38, 36);
jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(jTextField1);
jButton1.setBounds(32, 248, 75, 25);
jButton1.setText("Périmètre");
jButton1.setMargin(new Insets(2, 2, 2, 2));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
cp.add(jButton1);
jButton2.setBounds(32, 312, 75, 25);
jButton2.setText("Surface");
jButton2.setMargin(new Insets(2, 2, 2, 2));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2_ActionPerformed(evt);
}
});
cp.add(jButton2);
jLabel2.setBounds(160, 240, 62, 36);
jLabel2.setText("");
jLabel2.setBackground(Color.WHITE);
jLabel2.setOpaque(true);
jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(jLabel2);
jLabel3.setBounds(160, 304, 62, 36);
jLabel3.setText("");
jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
jLabel3.setBackground(Color.WHITE);
jLabel3.setOpaque(true);
cp.add(jLabel3);
jLabel4.setBounds(120, 96, 85, 25);
jLabel4.setText("Longueur");
jLabel4.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
cp.add(jLabel4);
jTextField2.setBounds(216, 88, 38, 36);
jTextField2.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(jTextField2);
jLabel5.setBounds(120, 160, 78, 25);
jLabel5.setText("Largeur");
jLabel5.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
cp.add(jLabel5);
jTextField3.setBounds(216, 152, 38, 36);
jTextField3.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(jTextField3);
jCheckBox1.setBounds(16, 40, 76, 20);
jCheckBox1.setText("Carre");
jCheckBox1.setOpaque(false);
jCheckBox1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
jCheckBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jCheckBox1_ActionPerformed(evt);
}
});
cp.add(jCheckBox1);
jCheckBox2.setBounds(16, 128, 108, 28);
jCheckBox2.setText("Rectangle");
jCheckBox2.setOpaque(false);
jCheckBox2.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
jCheckBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jCheckBox2_ActionPerformed(evt);
}
});
cp.add(jCheckBox2);
// end components
setVisible(true);
} // end of public KAKA
public void jButton1_ActionPerformed(ActionEvent evt) {
//Carre
int a= Integer.parseInt(jTextField1.getText());
int c= 4*a;
String result= String.valueOf(c);
jLabel2.setText( " " +result);
// TODO add your code here
} // end of jButton1_ActionPerformed
public void jButton2_ActionPerformed(ActionEvent evt) {
//Carre
int a= Integer.parseInt(jTextField1.getText());
int c= a*a;
String result= String.valueOf(c);
jLabel3.setText( " " +result);
// TODO add your code here
} // end of jButton2_ActionPerformed
// TODO add your code here
public void jCheckBox1_ActionPerformed(ActionEvent evt) {
jCheckBox1=(JCheckBox)event.getsource();
if(jCheckBox1.isSelected()){
jCheckBox1.setSelected(true);
jLabel1.setBounds(120, 24, 46, 41);
jLabel1.setText("Coté");
jLabel1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
cp.add(jLabel1);
jTextField1.setBounds(216, 32, 38, 36);
jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(jTextField1);
}
// TODO add your code here
} // end of jCheckBox1_ActionPerformed
public void jCheckBox2_ActionPerformed(ActionEvent evt) {
jCheckBox1=(JCheckBox) event.getsource();
if(jCheckBox1.isSelected()){
jCheckBox1.setSelected(true);
}
// TODO add your code here
} // end of jCheckBox2_ActionPerformed
// end methods
public static void main(String[] args) {
new KAKA("KAKA");
} // end of main
} // end of class KAKA |
Partager