i want to move text inside JPanel like square am able to move the text from the top panel but cant move it Up from where it starts.
import java.awt.*;
import javax.swing.*;
public class test extends JPanel {
int x = 100;
int y = 100;
public void move() {
if (x < getWidth() - 100 && y < getHeight() - 100) x = x + 1;
if (x >= getWidth() - 100 && y < getHeight() - 100) y = y + 1;
if (y >= getHeight() - 100) x = x - 1;
if (x < 0) y = y - 1;
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
move();
g2d.setColor(Color.BLUE);
g2d.drawString(" X = " + x + " Y " + y, x, y);
}
public static void main(String args[]) throws InterruptedException {
JFrame frame = new JFrame("Test Frame");
test ts = new test();
frame.setSize(400, 500);
frame.add(ts);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
while (true) {
ts.repaint();
Thread.sleep(10);
}
}
}