免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1347 | 回复: 2
打印 上一主题 下一主题

自定义包问题,搜索未果,紧急. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-13 18:30 |只看该作者 |倒序浏览

  1. console.java

  2. //Import this into an applet so that the applet can run as an application.

  3. package tfw;

  4. import javax.swing.*;
  5. import java.awt.event.*;

  6. public class console
  7. {
  8. public static String title(Object o)
  9. {
  10.   String t=o.getClass().toString();
  11.   if(t.indexOf("class")!=-1)
  12.    t=t.substring(6);
  13.   return t;
  14. }

  15. public static void setupClosing(JFrame frame)
  16. {
  17.   //frame.setDefaultCloseOperation(EXIT_ON_CLOSE);//???
  18.   frame.addWindowListener(
  19.    new WindowAdapter()//Event listening
  20.    {
  21.     public void windowClosing(WindowEvent e)
  22.     {
  23.      System.exit(0);
  24.     }
  25.    }
  26.   );
  27. }

  28. public static void run(JFrame frame,int width,int height)
  29. {
  30.   setupClosing(frame);
  31.   frame.setSize(width,height);
  32.   frame.setVisible(true);
  33. }

  34. public static void run(JApplet applet,int width,int height)
  35. {
  36.   JFrame frame=new JFrame(title(applet));
  37.   setupClosing(frame);
  38.   frame.getContentPane().add(applet);
  39.   frame.setSize(width,height);
  40.   applet.init();
  41.   applet.start();
  42.   frame.setVisible(true);
  43. }

  44. public static void run(JPanel panel,int width,int height)
  45. {
  46.   JFrame frame=new JFrame(title(panel));
  47.   setupClosing(frame);
  48.   frame.getContentPane().add(panel);
  49.   frame.setSize(width,height);
  50.   frame.setVisible(true);
  51. }
  52. }
复制代码


我照着书打了这个文件,并且编译通过.

我想把这个文件打进一个名为"tfw"的包里,以便今后些程序可以随时调用.

比如下面这个文件,将引用上述文件的内容:

  1. import java.lang.System;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import tfw.*;
  5. import java.awt.event.*;

  6. public class button
  7. {
  8. ......
  9. ......
  10. ......
  11. pubilc static void mian(String[] args)
  12. {
  13.   Console.run(new Jlabel2(),260,80);
  14. }
  15. }
复制代码


我的操作步骤以及提示如下:

  1. [root@TFW-RHL73 newtest]# javac -d /usr/tfw-class/ ./console-java/console.java

  2. [root@TFW-RHL73 newtest]# CLASSPATH=/usr/tfw-class/

  3. [root@TFW-RHL73 newtest]# javac button.java

  4. button.java:4: package tfw does not exist

  5. import tfw.*;

  6. ^

  7. 1 error

  8. [root@TFW-RHL73 newtest]# _
复制代码


为什么?我应该怎么做?

论坛徽章:
0
2 [报告]
发表于 2003-05-14 17:20 |只看该作者

自定义包问题,搜索未果,紧急.

补充说明:

我原先还没有设定过“CLASSPATH”……
1——我原先还没有设定过“CLASSPATH”,以前运行java程序总是先cd到*.class文件所在的目录去,还没有碰到过问题,这次要设置“CLASSPATH”,还真不知道怎么办。

2——据说,修改“/etc/profile”很可能把原来的默认“CLASSPATH”冲掉。为了防止出意外,我把它复制了一份。但是我搜索过“/etc/profile”,里没有“CLASSPATH”这个字符串。

3——能具体一点吗?命令是什么样?“/etc/profile”应该在什么地方怎么修改?

4——我的“button.java”位于“/root/work/java/newtest/”,“console.java”位于“/root/work/java/newtest/console-java/”,“console.class”和“console$1.class”位于“/usr/jclass/tfw”。包名为“tfw”。那么我在设置“CLASSPATH”的时候,应该设置为“/usr/jclass/tfw/”还是“/usr/jclass/”?

论坛徽章:
0
3 [报告]
发表于 2003-05-14 19:34 |只看该作者

自定义包问题,搜索未果,紧急.

设置为/usr/jclass/
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP