Forums Register Login

JPanel and text

+Pie Number of slices to send: Send
I have a MyClass that extends Jpanel and it only contains one private instance variable(text) of String type.

there is a constructor :

public MyClass()
{
text = "";
}

and a paintComponent method

// paintComponent to be done in (a)
public void paintComponent(Graphics g)
{
super.paintComponent(g);

g.drawString(text, 10, 10);

}

that draws the string in th JPanel.

I want to create a void setText(String s) method that will accept a string and then it will update the text instance variable but it will also draw the text in the JPanel.

Any ideas?

Thank you very much!
+Pie Number of slices to send: Send
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1000 times.
Similar Threads
JPanel + text
Taking values from a text file inside paintcomponent
repaint() becomes slower as program runs
Is this a Java Program?
a question about JPanel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:32:57.