multiple Inheritance ..类需要扩展abstractHandler以及Applet

时间:2011-10-27 00:20:21

标签: eclipse-plugin applet command multiple-inheritance abstract-syntax-tree

我正在尝试创建一个自动化向导,它将从系统中获取一些文件(通过命令处理程序)并生成相关的applet。

我将尝试解释我的事件。

我为新命令“newModule”创建了一个插件,它通过“newModuleHandler.java”处理。所以 newModuleHandler扩展了AbstractHandler

现在我想创建一个向导(applet),它可以帮助我完成“newModule”命令所需的某些选择。所以 newModuleHandler也扩展了Applet

我写了这样的newModuleHandler。

    package archetypedcomponent.commands;

    import org.eclipse.core.commands.AbstractHandler;
    import org.eclipse.core.commands.ExecutionEvent;
    import org.eclipse.core.commands.ExecutionException;
    import java.applet.*;// required when you create an applet 
    import java.awt.Graphics;


    public class newModuleHandler extends AbstractHandler {

    @Override
public boolean isEnabled() {
    // TODO Auto-generated method stub
    return true;
}

@Override
public boolean isHandled() {
    // TODO Auto-generated method stub
    return true;
}

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub

    return null;
}

public class HelloWorld extends Applet 
{
    // The method that will be automatically called  when the applet is started 
     public void init() 
     { 
         // It is required but does not need anything. 
         System.out.println("Applet initiated");
     } 


    // This method gets called when the applet is terminated 
    // That's when the user goes to another page or exits the browser. 
     public void stop() 
     { 
         //     no actions needed here now.
         System.out.println("Applet Stopped");
     } 


    // The standard method that you have to use to paint things on screen 
    // This overrides the empty Applet method, you can't called it "display" for example.

     public void paint(Graphics g) 
     { 
         //method to draw text on screen 
         // String first, then x and y coordinate. 
         System.out.println("Applet in paint");
          g.drawString("Hey hey hey",20,20); 
          g.drawString("Hellooow World",20,40);

     }
}

}

现在当命令将给出时,这个方法将被称为

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub

    return null;
}

并且必须在其中调用applet。 我的问题是如何调用它?

=============================================== ========================================= 我能够解决我的问题,但我在这里回复,以便那些也面临同样问题的人可以指导

这是我的新“newModuleHandler.java”

    package archetypedcomponent.commands;

    import org.eclipse.core.commands.AbstractHandler;
   import org.eclipse.core.commands.ExecutionEvent;
  import org.eclipse.core.commands.ExecutionException;
    import java.applet.*;// required when you create an applet 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;


public class newModuleHandler extends AbstractHandler {

    @Override
public boolean isEnabled() {
    // TODO Auto-generated method stub
    return true;
}

@Override
public boolean isHandled() {
    // TODO Auto-generated method stub
    return true;
}

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub
//  call applet here
     JFrame jp1 = new JFrame();
        Loader a=new Loader ();
        jp1.getContentPane().add(a, BorderLayout.CENTER);
        jp1.setSize(new Dimension(500,500));
        jp1.setVisible(true);

    return null;
}

}

我制作了一个新的 Loader.java ,它扩展了applet

    package archetypedcomponent.commands;

    import java.applet.Applet;
    import java.awt.Graphics;

    public class Loader extends Applet 
    {
// The method that will be automatically called  when the applet is started 
 public void init() 
 { 
     // It is required but does not need anything. 
     System.out.println("Applet initiated");
//   Graphics g=new ;

 } 


// This method gets called when the applet is terminated 
// That's when the user goes to another page or exits the browser. 
 public void stop() 
 { 
     //     no actions needed here now.
     System.out.println("Applet Stopped");
 } 


// The standard method that you have to use to paint things on screen 
// This overrides the empty Applet method, you can't called it "display" for example.

 public void paint(Graphics g) 
 { 
     //method to draw text on screen 
     // String first, then x and y coordinate. 
     System.out.println("Applet in paint");
      g.drawString("Hey hey hey",20,20); 
      g.drawString("Hellooow World",20,40);

 }

}

现在无论我需要applet做什么都可以在Loader的绘画中完成。

1 个答案:

答案 0 :(得分:2)

applet可以包含多个Object,因此applet可以引用其他类中的extends AbstractHandler