0

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?

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.