Java 小程序图形
我有 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
}
}
如何从 C 类底部绘制小程序屏幕上“第一个”文本的文本?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西吗?
如果没有看到更多代码,或者不知道您实际上在这里想要做什么,就很难有意义地回答这个问题。
如果您希望 C 对象调用 A 对象中的方法来添加新的 JLabel,那么 C 将需要 A 的句柄(我想您可以通过 B 构造函数将其传递给 C 构造函数)。
Something like this?
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).
干净的方式是这样的。
这样做的原因是您可能想在 Applet 之外的其他东西中使用此类,可能是具有多个内容窗格的东西。在您的小程序中,您可能只有一个 AppContext 实例,这使得它有点多余,但您可能还觉得需要使用 InternalFrame 或其他可能需要您跟踪多个窗格的组件。
在此处输入代码
The clean way would be something like this.
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