如何在eclipse中独立执行包含两个类的程序?

时间:2015-01-30 07:17:28

标签: java applet frame

如何在eclipse中执行以下代码作为一个程序?

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

   public class Keyframe extends Applet
 {
      Frame f;
      public void init()
      {
          f= new FrameHandlingUsingApplet("tarun");
          f.setSize(300,300);
          f.setVisible(true);
      }
      public void start()
      {
          f.setVisible(true);
      }
      public void stop()
      {
          f.setVisible(false);
      }
      public void paint(Graphics g)
      {
          g.drawString("this is applet window ", 20, 50);
      }
      public class FrameHandlingUsingApplet extends Frame
      {
        FrameHandlingUsingApplet(String name)
        {
            super(name);
            addWindowListener(new MyWindowAdapter(this));

        }
        public void paint(Graphics g)
        {
            g.drawString("this is frame window", 20, 30);
        }

        public class MyWindowAdapter extends WindowAdapter
        {
            FrameHandlingUsingApplet window;
            MyWindowAdapter(FrameHandlingUsingApplet window)
            {
                this.window=window;
            }
            public void windowClosing(WindowEvent m)
            {
                window.setVisible(false);
            }
        }
      }
 }
`enter code here`.*;
'

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

   public class Keyframe extends Applet
 {
      Frame f;
      public void init()
      {
          f= new FrameHandlingUsingApplet("tarun");
          f.setSize(300,300);
          f.setVisible(true);
      }
      public void start()
      {
          f.setVisible(true);
      }
      public void stop()
      {
          f.setVisible(false);
      }
      public void paint(Graphics g)
      {
          g.drawString("this is applet window ", 20, 50);
      }
      public class FrameHandlingUsingApplet extends Frame
      {
        FrameHandlingUsingApplet(String name)
        {
            super(name);
            addWindowListener(new MyWindowAdapter(this));

        }
        public void paint(Graphics g)
        {
            g.drawString("this is frame window", 20, 30);
        }

        public class MyWindowAdapter extends WindowAdapter
        {
            FrameHandlingUsingApplet window;
            MyWindowAdapter(FrameHandlingUsingApplet window)
            {
                this.window=window;
            }
            public void windowClosing(WindowEvent m)
            {
                window.setVisible(false);
            }
        }
      }
 }

1 个答案:

答案 0 :(得分:1)

使用指向另一个类的import语句导入另一个类。例如,如果您的类包含在包中:

import packagename.ClassName;