Hi, I am trying to make a Java Applet where the user can input a number then a rectangle would be shown on the screen that is the height that the user entered and Im having trouble working out what to do. I rather new to Java as well. Here is the code for my program:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class GraphGenerator extends Applet implements Runnable {
Thread t;
int c=0,inputfinal;
Label lab1;
TextField text1;
Button okButton;
public void init(){
t = new Thread(this);
t.start();
lab1 = new Label("Enter a number");
add(lab1);
text1 = new TextField(20);
add(text1);
okButton = new Button("Update");
add(okButton);
}
public void run(){
while(true){
c++;
repaint();
try {t.sleep(1000/30);}
catch(InterruptedException e){;}
}
}
public void paint(Graphics g){
g.drawString("You typed: "+text1.getText(),10,100);
g.drawString("c = "+c,10,120);
g.drawRect(10, 200, 20, inputfinal);
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == okButton){
String input = text1.getText();
inputfinal = Integer.parseInt(input);
repaint(); }
}
}