Hi i have following problem my applet should print characters to applet along to vertical line, but it prints only last character from a string. i try to move repaint() method in different places outside inside the loop but it still print out only last character in string. When i use //System.out.print(letters[i]); or //System.out.println(text); to check what is the content of string or charArray it prints right output but my paint g method prints only the last char form array Any suggestions??
public class ExtensionExercise extends Applet implements ActionListener {
String text;
String output;
Label label;
TextField input;
int xCoordinates = 30, yCoordinates = 50;
char letters [];
public void init(){
label = new Label("Enter word");
add(label);
input = new TextField(10);
add(input);
input.addActionListener(this);
}
public void start(){
text = "";
}
@Override
public void actionPerformed(ActionEvent event) {
text = event.getActionCommand();
letters = text.toCharArray();
for(int i = 0; i<letters.length; i++){
text = String.valueOf(letters[i]);
xCoordinates +=10;
yCoordinates +=10;
}
repaint();
}
@Override
public void paint(Graphics g){
g.drawString(text, xCoordinates, yCoordinates);
}
}