I want my java program to draw string "hello" as the input method parameter changes, without losing the previous drawings. In other words the frame has to draw many strings of "Hello" one after the other until the program is forced to stop. Currently it is showing only one word of "hello" with it's new y position changed.
How do I change the program below to draw many words of "hello" s with new y positions? Your help is much appreciated.
thanks
codes
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class test6 extends JPanel {
int x=100;
int y=30;
String text = null;
public static void main (String args[]){
JFrame frame = new JFrame("Test Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test6 gamePanel = new test6();
frame.add(gamePanel);
frame.setSize(400,400);
frame.setVisible(true);
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
input();
g.drawString("hello", x, y);
}
void input(){
try {
System.out.println("input your command?");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
text = in.readLine();
y=y+50;
} catch (IOException ex) {
Logger.getLogger(test6.class.getName()).log(Level.SEVERE, null, ex);
}
repaint();
}
}