jdk and swing.class

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?
leeannAsked:
Who is Participating?
 
diakovConnect With a Mentor Commented:
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
 
leeannAuthor Commented:
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
 
diakovCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
leeannAuthor Commented:
Sorry, I can not find Environment under System Properties. The System Properties includes: General, Device Manager, Hardware Profiles and Performance.
0
 
diakovCommented:
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
 
leeannAuthor Commented:
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
 
diakovCommented:
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
 
leeannAuthor Commented:
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
 
diakovCommented:
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
 
leeannAuthor Commented:
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
 
diakovCommented:
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
 
leeannAuthor Commented:
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
 
diakovCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.