Evgeniy Altynpara
Evgeniy Altynpara

Reputation: 1

Java Applet Graphics

I have class A

class A extends JApllet {
private B b;
....
public void init() {
 // draw text
  getContentPane().add(new JLabel("First"), BorderLayout.CENTER);
 b = new B();
}

}

class B{

private C c;

   b(){
       c = new C();
   }

}

class C{
    C(){
    // And there I need draw Text ("Second") on Applet Panel 

  }
}

How I can draw text from C class bottom the "First" text on Applets screen?

Upvotes: 0

Views: 404

Answers (2)

user1657170
user1657170

Reputation: 322

The clean way would be something like this.

class C{
  C(AppContext context){
    c.getContentPane().add(..)
  }
}

The reason for this are that you may want to use this class in something else than an Applet, possibly something with more than one content pane. In your applet you may have only one AppContext instance making it a bit redundant, but you may also feel the need to use InternalFrame or other components that may require you to keep track of more than one pane.enter code here

Upvotes: 0

Rob Whelan
Rob Whelan

Reputation: 1291

Something like this?

getContentPane().add(new JLabel(b.c.getText()), BorderLayout.SOUTH);

This is hard to answer meaningfully without seeing more of your code, or knowing what you're actually trying to do here.

If you want your C object to call a method in your A object to add a new JLabel, then C will need a handle to A (you could pass that through the B constructor to the C constructor, I suppose).

Upvotes: 1

Related Questions