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
|
import java.awt.Button;
import java.awt.Choice;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.TextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Arafat Bouchafra
* @Date 4 déc. 2010
* @Time 09:05:07
*/
public class Dessin extends JPanel {
JLabel lChoice, lRadius, lSize, lLength;
JTextField tRadius, tSize, tLength;
Button b;
Choice ch;
TextField t;
public Dessin() {
super(new GridBagLayout());
lChoice = new JLabel("Choice what you want to draw", JLabel.LEFT);
lRadius = new JLabel("Please enter the radius", JLabel.LEFT);
lSize = new JLabel("Please enter the side", JLabel.LEFT);
lLength = new JLabel("Please enter the Length", JLabel.LEFT);
tRadius = new JTextField(15);
tSize = new JTextField(15);
tLength = new JTextField(15);
ch = new Choice();
String s[] = {"Make your Choise", "circle", "line", "square"};
for (int i = 0; i < s.length; i++) {
ch.add(s[i]);
}
add(ch);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
add(lChoice, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 0;
add(ch, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 1;
add(lRadius, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 1;
add(tRadius, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 2;
add(lSize, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 2;
add(tSize, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 3;
add(lLength, c);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 3;
add(tLength, c);
}
public static void main(String... args) {
JFrame f = new JFrame("Dessin");
f.setContentPane(new Dessin());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 500);
f.setLocationRelativeTo(null); // pour centrer la frame
f.setVisible(true);
}
} |