Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel and text

 
Nick Petas
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic