Witam wszystkich
Chcialbym napisac program ktory daje uzytkownikowi do wyboru co chce narysowac. Najpierw coordynaty a pozniej 2 przyciski kwadrat lub kolo ale nie do konca mi to wychodzi. Moglby ktos pomoc.
Pozdrawiam.
/*demonstrating drawRect */
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
public class RactangleOval extends Applet implements ActionListener
{
int x=0;
int y=0;
int wdth;
int height;
Label label1, label2,label3,label4, resultlabel;
//declare textfields
TextField number1, number2,number3,number4, resultnumber;
Button drawButton = new Button("Draw Oval");
Button drawButton1 = new Button("Draw Rectangle");
public void init()
{
//create labels
label1 = new Label("Enter possition X on screen:");
label2 = new Label("Enter possition Y on screen:");
label3 = new Label("Enter width co-ordinate:");
label4 = new Label("Enter hight co-ordinate:");
//create textfields
number1 = new TextField(10);
number2 = new TextField(10);
number3 = new TextField(10);
number4 = new TextField(10);
Button drawButton = new Button("Draw Oval");
Button drawButton1 = new Button("Draw Rectangle");
//add labels and textfields to applet
add(label1);
add(number1);
add(label2);
add(number2);
add(label3);
add(number3);
add(label4);
add(number4);
add(drawButton);
drawButton.addActionListener(this);
//add(resultnumber);
add(drawButton1);
drawButton1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
x = Integer.parseInt(number1.getText());
y = Integer.parseInt(number2.getText());
wdth = Integer.parseInt(number3.getText());
height = Integer.parseInt(number4.getText());
repaint();
}
public void paint(Graphics g)
{
//g.clearOval(getX(), getY(), getWidth(), getHeight());
g.drawOval(x,y,wdth,height);
g.clearRect(getX(), getY(), getWidth(), getHeight());
g.drawRect(x,y,wdth,height);
}
}