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
|
import java.lang.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class Dessin extends Frame implements ItemListener, MouseListener
{
Label textChoise;
Label textRadius;
Label textSize;
Label textLength;
Button b;
Choice ch;
TextField t;
public Dessin()
{
textChoise = new Label("Choice what you want to draw",Label.LEFT);
textRadius =new Label("Please enter the radius",Label.LEFT);
textSize =new Label("Please enter the side",Label.LEFT);
textLength =new Label("Please enter the Length",Label.LEFT);
b = new Button("Draw");
add(textChoise);
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);
setLayout(new GridLayout(4,2));
setBackground(Color.pink);
addWindowListener(new w());
t = new TextField(10);
add(textRadius).setVisible(false);
add(textSize).setVisible(false);
add(textLength).setVisible(false);
add(t).setVisible(false);
add(b).setVisible(false);
ch.addItemListener(this);
b.addMouseListener(this);
}
public class w extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
Dessin ff = new Dessin();
ff.setSize(1000,500);
ff.setVisible(true);
}
public void itemStateChanged(ItemEvent f)
{
String st;
if(f.getSource()==ch) //Font Style
{
st =ch.getSelectedItem();
if(st.equals("circle"))
{
this.add(textSize).setVisible(false);
this.add(textLength).setVisible(false);
this.add(textRadius).setVisible(true);
this.add(t).setVisible(true);
this.add(b).setVisible(true);
}
else if(st.equals("square"))
{
this.add(textRadius).setVisible(false);
this.add(textLength).setVisible(false);
this.add(textSize).setVisible(true);
this.add(t).setVisible(true);
this.add(b).setVisible(true);
}
else if(st.equals("line"))
{
this.add(textRadius).setVisible(false);
this.add(textSize).setVisible(false);
this.add(textLength).setVisible(true);
this.add(t).setVisible(true);
this.add(b).setVisible(true);
}
}
}
public void mouseClicked(MouseEvent e)
{
System.out.println("azerty");
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
} |
Partager