0

I've got somePanel1, somePanel2, and somePanel3 instantiated within someFrame.

If I do a drawString in somePanel form, how can I get the output to be different in somePanel1, somePanel2, and somePanel3.

For instance g.drawString("X", x, y); puts an X in all three somePanels. How do I get:

  • somePanel1 to output X,
  • somePanel2 to output Y, and
  • somePanel3 to output Z?
mKorbel
  • 109,525
  • 20
  • 134
  • 319

1 Answers1

1

From your comments SomePanel is auto-generated. You could simple add a setter method to allow the message to be changed:

class SomePanel extends JPanel {

   // message to be used in drawString
   private String message;

  public void setMessage(String message) {
      this.message = message;
  }
  ...
}

then use

somePanel1.setMessage("X");
...
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • That's pretty much what I have. I guess what I'm really asking is how do I "instantiate passing `X`, `Y`, `Z`"? – Toto Nyoob Mar 10 '13 at 17:44
  • Sorry for belaboring the point but, somePanel1 was auto created in the someFrame form... `private main somePanel somePanel1;` So I can't use that in the somePane form. If I use `somePanel1 = new SomePanel("X");` in someFrame I get a cannot find symbol error – Toto Nyoob Mar 10 '13 at 18:03
  • I meant `private Main.somePanel somePanel1;` – Toto Nyoob Mar 10 '13 at 18:10
  • ...`somePanel` is placed in `someFrame` three times so `someFrame` auto-generates `somePanel1`, `somePanel2`, and `somePanel3`. If I type in `somePanel1.` within `someFrame` source, the only pop-up option I get is `new`. – Toto Nyoob Mar 10 '13 at 20:09
  • I would recommend coding by hand here. It would not only give you greater freedom to add constructor args but you would get more familiar with the code itself :) – Reimeus Mar 10 '13 at 20:28
  • Thanks for your help. I guess unless I show you all of my code, it's hard to understand what is going on. – Toto Nyoob Mar 10 '13 at 21:31