public class testBrick extends Applet implements ActionListener {
private Brick myBrick;
private Label lblQuestion; //create the label
private TextField txtQuestion; // create the textField
private int brickWidth =10;
public void init(){
this.setSize(500,500);
myBrick = new Brick(50,50, new Color(153,0,0),100,50);
// create the Label and TextFeild and add to the applet and ActionListener
lblQuestion = new Label("What is the width of the brick");
add(lblQuestion);
txtQuestion = new TextField();
add(txtQuestion);
txtQuestion.addActionListener(this);
}
public void paint(Graphics g){
//use the information from the TextField
myBrick.setWidth(brickWidth);
myBrick.display(g);
}
@Override
public void actionPerformed(ActionEvent e) {
//Get the information out of the TextField and parse it
if(e.getSource() == txtQuestion){
brickWidth = Integer.parseInt(txtQuestion.getText());
}
repaint();
}
}