- 论坛徽章:
- 0
|
- console.java
- //Import this into an applet so that the applet can run as an application.
- package tfw;
- import javax.swing.*;
- import java.awt.event.*;
- public class console
- {
- public static String title(Object o)
- {
- String t=o.getClass().toString();
- if(t.indexOf("class")!=-1)
- t=t.substring(6);
- return t;
- }
- public static void setupClosing(JFrame frame)
- {
- //frame.setDefaultCloseOperation(EXIT_ON_CLOSE);//???
- frame.addWindowListener(
- new WindowAdapter()//Event listening
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- }
- );
- }
- public static void run(JFrame frame,int width,int height)
- {
- setupClosing(frame);
- frame.setSize(width,height);
- frame.setVisible(true);
- }
- public static void run(JApplet applet,int width,int height)
- {
- JFrame frame=new JFrame(title(applet));
- setupClosing(frame);
- frame.getContentPane().add(applet);
- frame.setSize(width,height);
- applet.init();
- applet.start();
- frame.setVisible(true);
- }
- public static void run(JPanel panel,int width,int height)
- {
- JFrame frame=new JFrame(title(panel));
- setupClosing(frame);
- frame.getContentPane().add(panel);
- frame.setSize(width,height);
- frame.setVisible(true);
- }
- }
复制代码
我照着书打了这个文件,并且编译通过.
我想把这个文件打进一个名为"tfw"的包里,以便今后些程序可以随时调用.
比如下面这个文件,将引用上述文件的内容:
- import java.lang.System;
- import javax.swing.*;
- import java.awt.*;
- import tfw.*;
- import java.awt.event.*;
- public class button
- {
- ......
- ......
- ......
- pubilc static void mian(String[] args)
- {
- Console.run(new Jlabel2(),260,80);
- }
- }
复制代码
我的操作步骤以及提示如下:
- [root@TFW-RHL73 newtest]# javac -d /usr/tfw-class/ ./console-java/console.java
- [root@TFW-RHL73 newtest]# CLASSPATH=/usr/tfw-class/
- [root@TFW-RHL73 newtest]# javac button.java
- button.java:4: package tfw does not exist
- import tfw.*;
- ^
- 1 error
- [root@TFW-RHL73 newtest]# _
复制代码
为什么?我应该怎么做? |
|