关于类中类的方法调用

qq_36219416 qq_36219416 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example04 extends Applet implements ActionListener {

Button buttonPlay,buttonLoop,buttonStop;
TextField text;
Thread thread;
public Example04(){
buttonPlay=new Button("开始播放");
buttonLoop=new Button("循环播放");
buttonStop=new Button("停止播放");
text=new TextField(12);
}
public void runx() {
buttonPlay.setBackground(Color.red);
buttonLoop.setBackground(Color.green);
text.setText("您可以播放了...");
System.out.println("test");
}

@Override
public void init(){
thread=new Thread(new Runnable(){
@Override
public void run(){
(new Example04()).runx();

}

public void runx(){
text.setBackground(Color.BLACK);

}

});
thread.setPriority(Thread.MIN_PRIORITY);
buttonPlay.addActionListener(this);
buttonLoop.addActionListener(this);
buttonStop.addActionListener(this);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
add(text);
}
public void start(){
thread.start();
}
public void stop(){

}
public void actionPerformed(ActionEvent e) {

}


}


在thread的参数里,有一个方法, runx(), 在example04里也有一个方法runx().
如果我想在参数里面运行一个Example04的runx()方法,那么我就要创建一个新的example04的实例,但是改变新的实例的button的颜色,不会改变现在这个applet的button的颜色。

所以想请问一下,如何在调用类外类的 同名 方法,但是是在当前的实例中改变呢?(如何调用example04的runx()的方法,改变applet的button的颜色)
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
qq_36219416
Java SE 62,621 成员 307,251 内容