-2

我正在使用 API 编写一个项目。所以总的来说我的程序看起来像这样。

public class Programm extends bridge {
Client Eclient = new Client() ;
public static void main(String[] args) {
Programm MyProgramm = new Programm();
MyProgramm.MyMethod();
public void MyMethod(){
 Runnable countdown = new flipper();
 Thread worker = new Thread(countdown);
 worker.start();
}
}
abstract bridge implements API{}
class flipper implements runnable {
public void run(){MyProgramm.Eclient.ApiMethod()}
}

基本上我需要访问 EClient 类实例,因为它会被 MyProgramm 实例从类翻转器访问

4

2 回答 2

0
class flipper implements Runnable {
private ESocket lEClient;
   public flipper (Object pEClient) {
     lEClient = pEClient;
   }

然后你调用使用这样的构造函数:

public void MyMethod()
 {

   Runnable countdown = new flipper(Eclient);

  Thread worker = new Thread(countdown);
   worker.start();
 }

public void run() {lEClient .Apimethod()}
于 2012-09-06T21:45:53.910 回答
0

选项 2:使 Flipper 成为内部类

public class Program extends bridge {
   Client eClient = new Client() ;
   public void main(String[] args) {...}
   public void myMethod(){...}
   class Flipper implements Runnable {
      public void run(){Program.eClient.apiMethod()}
   }
}
于 2012-09-06T21:54:17.850 回答