Solved

jdk and swing.class

Posted on 1998-09-30
13
191 Views
Last Modified: 2013-11-23
D:/programs/jdk1.1.6
As you see, I installed jdk1.1.6 in my D driver.
1. What need I do the next if I want to run my program test.java which is saved in: D:/programs/jdk1.1.6/bin/version1/test.java ?
2. I have downloaded the sun.com.swing.class, could you tell me where I put it?
0
Comment
Question by:leeann
  • 7
  • 6
13 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 20 total points
ID: 1225176
Hello leeann,

Actually the swing package is much bigger than one class. It is basically a directory with some subdirectories and classes there or a .jar(.zip) archive.
In order to use the JDK and the Swing, after installing the two things, you have to modify your CLASSPATH environment variable to point to something like:
d:\programs\jdk1.1.6\lib\classes.zip;d:\programs\swing-1.2-beta\swingall.jar
Also, you have to add the d:\progrms\jdk1.1.6\bin to the PATH environment variable.

The you go to your project directory and:
javac test.java

or in case you didn't set the CLASSPATH environment variable
javac -classpath "d:\programs\jdk1.1.6\lib\classes.zip;d:\programs\swing-1.2-beta\swingall.jar" test.java

or in case you didn't modify the PATH environment variable
d:\programs\jdk1.1.6\bin\javac -classpath "d:\programs\jdk1.1.6\lib\classes.zip;d:\programs\swing-1.2-beta\swingall.jar" test.java



Cheers.
0
 

Author Comment

by:leeann
ID: 1225177
Hi diakov:
Could you please tell me more detail how I need to do in case I needn't modify the PATH environment variable? The one I downloaded is swing103.zip.
1. Can I save my programs under any directory on the same driver?
2. Which directory can I compile my programs? Under jdk or swing?

0
 
LVL 8

Expert Comment

by:diakov
ID: 1225178
Hi leeann,
Unzip the swing103.zip somewhere. Letsay d:\programs\swing
If you are under Windows, you open the control pannel, then System, then go to Environment. There you can define two variables:
- name
PATH

- value (%PATH% means you include the old path)
%PATH%;d:\programs\jdk1.1.6;

- name
CLASSPATH

- value
d:\programs\jdk1.1.6\lib\classes.zip;d:\programs\jdk1.1.6\lib;d:\programs\swing\swingall.zip

After you did this you have to close all DOS boxes and open new ones. Then type:
SET | more
to see the environment and check whether this variables are visible and with the altered by you values. If not, reboot the machine. Under NT the reboot is not needed.

After this is done, in any box and from any directory on any drive, you can compile your programs. It does not matter where they are situated. Most commonly, your program resides in one directory somewhere. When you compile it there, if no particular output directory is specified for the .class files, they will be generated in the same directory and if any classes are declared in a package, the some subdirectories will be created and the class files will be put there. The subdirectory names for the package myPackage1.Subpackage1 are myPackage1\Subpackage1 and the .class files will be stored there.

Cheers.

Nik
0
 

Author Comment

by:leeann
ID: 1225179
Sorry, I can not find Environment under System Properties. The System Properties includes: General, Device Manager, Hardware Profiles and Performance.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1225180
Hm, I'm using Windows NT.
Then edit the autoexec.bat and add:
SET CLASSPATH=...<the things I wrote before>...


There should be a PATH variable already, so edit it and add the jdk path.
0
 

Author Comment

by:leeann
ID: 1225181
I edited the autoexec.bat file:
SET CLASSPATH = d:\programs\jdk1.1.6\lib\classes.zip;d:\programs\swing\swingall.zip
PATH = d:\programs\jdk1.1.6\bin;

Now, I can compile my programs under d driver, but it can not find the package com.sun.java.swing. Could you tell me what the problem is?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:diakov
ID: 1225182
I believe the path to the swing .zip library is not correct or something. look at the file swingall, I think it is a .jar file, not a .zip file. Please, be acurate with this.
Could you try the -classpath option from the command prompt? It will be something like:

javac -classpath d:\programs\swing\swingall.jar;d:\programs\jdk1.1.6\lib\classes.zip test.java
0
 

Author Comment

by:leeann
ID: 1225183
I still can not solve my problem. Maybe I lost some files.  Here is what I have in my d driver:
1.
D:\Programs\jdk1.1.6
D:\Programs\swing
D:\Programs\test.java

2.
D:\Programs\swing\java
D:\Programs\swing\sun
D:\Programs\swing\sunw
D:\Programs\swing\swing-1.0.3

3.
D:\Programs\swing\swing-1.0.3\swingall.jar
0
 
LVL 8

Expert Comment

by:diakov
ID: 1225184
Now, lets try:

javac -classpath d:\Programs\swing\swing-1.0.3\swingall.jar;d:\programs\jdk1.1.6\lib\classes.zip test.java

Then in your source, where you include the package check carefully the correct spelling, it should be:
import com.sun.java.swing.*;

Then you can use all the classes from it.
0
 

Author Comment

by:leeann
ID: 1225185
I still get the same error message "Package com.sun.java.swing not found in import".

SET CLASSPATH = d:\Programs\jdk1.1.6\lib\classes.zip;d:\Programs\swing\swing-1.0.3\swingall.jar
PATH=D:\PROGRAMS\JDK1.1.6\BIN;


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import com.sun.java.swing.*;

public class ReportsFrame extends JFrame implements ActionListener
{  static JTextArea t;
   FileDialog fdOpen;
   FileDialog fdSave;
   Tools tl;

   public ReportsFrame(String s)
   {  
       super(s);
       setTitle( "Reports" );
       setSize(700, 450);
       JMenuBar mbar = new JMenuBar();
       JMenu m = new JMenu( "File" );
       JMenuItem open = new JMenuItem( "Open" );  
       open.addActionListener(this);
       m.add(open);
       JMenuItem c = new JMenuItem( "Close" );  
       c.addActionListener(this);
       m.add(c);      
       m.addSeparator();
       JMenuItem save = new JMenuItem( "Save as" );  
       save.addActionListener(this);
       m.add(save);
       m.addSeparator();
       JMenuItem p = new JMenuItem( "Print..." );  
       p.addActionListener(this);
       m.add(p);
       m.addSeparator();
       JMenuItem exit = new JMenuItem( "Exit" );  
       exit.addActionListener(this);
       m.add(exit);
       mbar.add(m);
       setMenuBar(mbar);
       t = new JTextArea();
       t.setEditable(false);
       add("Center", t);
       
     
       //{{REGISTER_LISTENERS
       this.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
                 dispose();
                 setVisible(false);}
       });
    }

    public void actionPerformed(ActionEvent evt)
    {
       //Check for menu items clicked
       String item = evt.getActionCommand();
       String str = null;
       String file = null;

       if(item.equals("Open")){
              FileReader fr;
              BufferedReader br;
              fdOpen = new FileDialog(this,"Open File",FileDialog.LOAD);
              fdOpen.setVisible(true);
              file = fdOpen.getDirectory() + fdOpen.getFile();
              if(file == null)
                 return;
              try{
                 fr = new FileReader(file);
                 br = new BufferedReader(fr);
              }catch(FileNotFoundException fnfe){
                  System.out.println(fnfe.getMessage());
                  return;
              }
              try{
                 while((str = br.readLine()) != null)
                     t.append(str + System.getProperty("line.separator"));
              }catch(IOException ioe){
                  System.out.println(ioe.getMessage());
              }finally{
                  try{
                      br.close();
                  }catch(IOException ioe){}
              }
           
       }
       else if(item.equals("Save as")){
              BufferedWriter bw;
              FileWriter fw;
              fdSave = new FileDialog(this, "Save File As", FileDialog.SAVE);  
              fdSave.setVisible(true);
              file = fdSave.getDirectory() + fdSave.getFile();
              if(file == null)
                  return;
              try{
                  fw = new FileWriter(file);
                  bw = new BufferedWriter(fw);
              }catch(IOException ioe){
                  System.out.println(ioe.getMessage());
                  return;
              }
              try{
                  bw.write(t.getText(), 0, t.getText().length());
              }catch(IOException ioe){
                  System.out.println(ioe.getMessage());
              }finally{
                  try{
                      bw.close();
                  }catch(IOException ioe){}
             }
       }
       else if(item.equals("Print...")){
             tl.printApp(t);
       }
       else if(item.equals("Close")){
              t.setText("");
       }
       else if(item.equals("Exit")){
              dispose();
             
       }
 
    }

  }
 
 
0
 
LVL 8

Expert Comment

by:diakov
ID: 1225186
After unsetting my path and classpath environment variables I compiled your code (well, not actually compiled, because you have some other cast error) with:

c:\My_stuff\jdk1.1.5\bin\javac.exe -classpath "d:\swing-1.1beta2\swingall.jar;c:\My_stuff\jdk1.1.5\lib\classes.zip" ReportsFrame.java

As you can see, my jdk is in c:\My_stuff\jdk1.1.5
My swing is in d:\swing-1.1beta2\swingall.jar
and I compiled from the same directory where the .java file is.
0
 

Author Comment

by:leeann
ID: 1225187
Hi, Diakov,
Why do you put the file name "ReportsFrame.java" after the path set? You mean that I need set "ReportsFrame.java" in the path? Please tell me in detail.

"d:\swing-1.1beta2\swingall.jar;c:\My_stuff\jdk1.1.5\lib\classes.zip" ReportsFrame.java
0
 
LVL 8

Expert Comment

by:diakov
ID: 1225188
In my example, I didn't put the file name in the path. This is a line from the command line. I started the java compiler from a specific directory with the parameter -classpath and provided the class archives, then I pointed out which file the compiler to compile. And then I hit enter. You can try to do the same with the correspondently substituted paths and file names, for your case.

Got it?

Cheers,
  Nik
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 50
What is JNDI datasource in spring 1 38
Python Assistance 7 36
Requested array size exceeds VM limit 3 51
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now