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的颜色)
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的颜色)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货