关于类中类的方法调用
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的颜色)
...全文
相关推荐
python 定义类时,实现内部方法的互相调用
今天小编就为大家分享一篇python 定义类时,实现内部方法的互相调用,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
在Python 中同一个类两个函数间变量的调用方法
今天小编就为大家分享一篇在Python 中同一个类两个函数间变量的调用方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
反射,动态加载指定类调用类中的方法
反射,动态加载指定类调用类中的方法 简单例子
JAVA类的方法调用和变量
JAVA类的方法调用和变量 一、类的分类: 1、普通类 2、抽象类(含有抽象方法的类) 3、静态类(不需要实例化,就可以使用的类) 二、方法的分类: 1、私有方法(只有类的内部才可以访问的方法) 2、保护方法(只有类的内部和该类的子类可以访问的方法) 3、共有方法(无论内部或外部均可访问的方法) 4、静态方法(可以不实例话对象,通过类名.方法就可以调用的方法) 5、抽象方法(只有方法的签名而没有实现的方法)
类的调用 和类的方法的应用
类的调用 和类的方法的应用 根据 课程ID 查找课程名和该生的成绩!!!


Java SE
