我试图实现一个具有以下结构的java应用程序。
我的问题是
当我从 videoplayer 线程调用引号线程时,视频仍然在引号表单的顶部播放。
当我使用动作事件更改视频 url 时,它只会将新播放器附加到当前播放器。前任。当我按下视频 2 按钮时,视频 2 与当前正在运行的视频 1 一起附加
.
class VideoPlayer implements Runnable,ActionListener{
private videoappMidlet MIDlet;
VideoComponent vc;
Button Videos,quotes,video1,video2,video3;
Form videoplayer;
Thread thread;
public VideoPlayer(videoappMidlet MIDlet){
this.MIDlet = MIDlet;
}
public void run(){
try{
videoplayer=new Form();
video1=new Button("video1");
.......
vc = VideoComponent.createVideoPeer("http://localhost/video1.mpg");
vc.start();
quotes.addActionListener((ActionListener) this);
........
videoplayer.addComponent(vc);
........
videoplayer.show();
}catch(Exception error){
System.err.println(error.toString());
}
}
public void start(){
thread = new Thread(this);
try{ thread.start();}
catch(Exception error){}
}
public void actionPerformed(ActionEvent ae) {
if((ae.getSource()==Quotes))
{
Quotes tp = new Quotes(this.MIDlet);
tp.start();
}
if(ae.getSource()==video1)
{
try {
vc = VideoComponent.createVideoPeer("http://localhost/video1.mpg");
vc.start();
} catch (IOException ex) {
ex.printStackTrace();
}
}
....
}
}
class Quotes implements Runnable,ActionListener {
private videoappMidlet MIDlet;
Button Videos,quotes;
Form quote;
Thread thread;
public Quotes(videoappMidlet MIDlet){
this.MIDlet = MIDlet;
}
public void run(){
try{
quote=new Form();
Videos=new Button("Videos");
........
quote.addComponent(Videos);
........
Videos.addActionListener(this);
........
quote.show();
}catch(Exception error){
System.err.println(error.toString());
}
}
public void start(){
thread = new Thread(this);
try{ thread.start();}
catch(Exception error){}
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==Videos)
{
VideoPlayer vp = new VideoPlayer(this.MIDlet);
vp.start();
}
}
}
public class videoappMidlet extends MIDlet implements ActionListener{
Button play,quote;
Form home;
public void startApp() {
Display.init(this);
home=new Form();
play.addActionListener(this);
quote.addActionListener(this);
home.show();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==play)
{
VideoPlayer vp = new VideoPlayer(this);
vp.start();
}
if(ae.getSource()==quote)
{
Quotes tp = new Quotes(this);
tp.start();
}
}
}