LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 945|回复: 4

自己创建的“包”的引用问题。

[复制链接]
发表于 2004-9-6 18:25:55 | 显示全部楼层 |阅读模式
创建包:

package kkk;
public class kkk
{
   public void add(int i ,int j)
     {System.out.println(i+j);}
}

在当前目录下用下面的程序引用这个包

public class AA
{
   public static void main(String argv[])
    {
      kkk test=new kkk();
      test.add(6,8);
    }
}

老是显示下面的错误
AA.java:1: '.' expected
应该怎样引用呀!
发表于 2004-9-6 18:36:04 | 显示全部楼层
import kkk.kkk;

对了 你的classpath中有 . 么?
 楼主| 发表于 2004-9-6 22:13:38 | 显示全部楼层

谢谢,问题解决,药到病除!

package Threader;
import java.awt.*;


public class Threader extends Canvas implements Runnable
{
          int myPosition =0;
        String myName;
        int numberofSteps=600;
        boolean keepRunning =true;

        public Threader (String inName)
        { myName=new String (inName); }
       
        public synchronized void paint(Graphics g)
        { g.setColor (Color.black);
         g.drawLine (0,getSize().height/2,getSize().width,getSize().height/2);
        g.setColor (Color.yellow);
        g.fillOval((myPosition*getSize().width/numberofSteps),0, 15,getSize().height);
        }
               
        public void stop()
        { keepRunning = false; }
         
        public void run()
        { while (myPosition <numberofSteps)
               myPosition=myPosition+1;     }
}

import java.awt.*;
import java.applet.*;
import Threader.Threader;

public class testThread extends Applet implements Runnable
{
        Threader theRacers[];
        static int racerCount = 3;
        Thread theThreads[];
        Thread thisThread;
        static boolean inApplet=true;
        int numberofThreadsAtStart;
         
        public void init()
        {
                numberofThreadsAtStart = Thread.activeCount();
                setLayout(new GridLayout(racerCount,1));
                theRacers = new Threader [racerCount];
                theThreads = new Thread[racerCount];
                for (int x=0;x<numberofThreadsAtStart;x=x+2)
                {
                        try
                                {
                                        thisThread.sleep(100);
                                }
                        catch (InterruptedException e)
                                {
                                        System.out.println("thisThread was interrupted");
                                }
                }
                if (inApplet)
                {
                        stop();
                        destroy();
                }
                else
                        System.exit(0);
        }
        public static void main (String argv[])
        {
                inApplet=false;
                if (argv.length>0)
                racerCount = Integer.parseInt(argv[0]);
                Frame theFrame = new Frame("The Great Thread Race");
                testThread theRace = new testThread();
                theFrame.setSize(400,200);
                theFrame.add ("Center",theRace);
                theFrame.show();
                theRace.init();
                theFrame.pack();
                theRace.start();
        }
}


出现下面的错误,怎么回事?
--------------------Configuration: j2sdk1.4.2 <Default>--------------------
testThread.java:5: testThread is not abstract and does not override abstract method run() in java.lang.Runnable
public class testThread extends Applet implements Runnable
       ^
1 error

Process completed.
发表于 2004-9-7 09:27:43 | 显示全部楼层
实现Runnable接口的话,当然要实现其中的run()方法了。找个书上的例子看看吧。关键还是要把基础的东西学好先。
 楼主| 发表于 2004-9-7 09:41:06 | 显示全部楼层

谢谢!

我感觉好象也是,就是太心急了。马上补课!!!;)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表