首先创建主程序,再创建一个播放器的程序,在电脑打开后运行主程序和播放器,
创建一个程序启用和关闭的接口,在每一个需要用到启用和关闭的功能时,就调用
该接口实现类,主程序需要使用这个程序时,直接调用即可。
电脑打开运行的代码:
public static void main(String[] args) {
MainRun mr = new MainRun();
mr.run();
mr.runInter(new MusicPlayer());
}
主程序运行的代码:
public void run(){
System.out.println(“主程序正在运行中。。。”);
}
public void runInter(RunInterface r){
if (r != null){
r.open();
r.close();
}
接口和播放器的代码:
public interface RunInterface {
void open();
void close();
}
public class MusicPlayer implements RunInterface {
public void open(){
System.out.println(“音乐播放器正在运行中。。。”);
}
public void close(){
System.out.println(“音乐播放器已经关闭!!!”);
}
}