首页 文章

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

提问于
浏览
0

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

我将尝试解释我的事件 .

我为新命令"newModule"制作了一个插件,它通过"newModuleHandler.java"处理 . 所以 newModuleHandler extends AbstractHandler .

现在我想制作一个向导(小程序),帮助我完成"newModule"命令需要做出的某些选择 . 所以 newModuleHandler extends 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 . my question is how to call it?

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

这是我的新 "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 回答

  • 2

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

相关问题