Dive Log tutorial
ok I have gone through the tutorial
this is what i type in to get to the compiler
C:\jdk1.3.1_01\bin
and this is where my divelog package is and in it are all the classes i have made
C:\divelog
So to compile The DiveLog.java file in the divelog package this is what i type in
sorry didnt finish what i was tellin u guys but thats ok, becuase i found some more information about how to do it, but that doesnt seem to work either.
this is where i am at right now
this is what i type in to get to my compiler
C:\jdk1.3.1_01\bin>javac
this is where my package and files reside
C:\test\divelog
Now that information i have found says not to inlucde the directory where the classes are kept.
so i type this in
C:\jdk1.3.1_01\bin>javac C:\test\ DiveLog.java
but still no joy
can anyone see where im goin wrong please. Its really doing my head in
Similar Messages
-
Dive Log Part 3 will compile but won't run
I need help I am a newbie doing this assignment for class. I am having problems with the Dive Log part 3 tutorial parts 1 & 2 went fine but 3 has given me problems. After fixing all errors to Diver.java, Divelog.java finally compiled then I went to run it and i get a list of errorssome from Diver some from DiveLog. Any help figuring out this mystery would be helpful.
Ah you have PPC version. Either you can keep using Firefox 3.6.* are try a third party version of Firefox 4.0.* at http://www.floodgap.com/software/tenfourfox/
The Firefox 4.0 and newer downloads contains the 32-bit and 64-bit version for Intel at moment. -
Dive Log Problem (Again)
yah, its me again with another problem... I got the divelog to compile correctly, and the welcome code is the same as on the site, but the images wont show up and they are name correctly and in the correct folder... could some one give me some direction in this?
no error pop up when I do it, but here is the code
package divelog;
import javax.swing.*;
import java.awt.*;
public class Welcome extends JPanel
{ // Opens class
private JLabel jl;
private JTextArea ta;
private JLabel diver;
public Welcome()
{//opens constructor
setLayout(new BorderLayout());
setBackground(Color.white);
jl = new JLabel("Java Technology Dive Log", new ImageIcon("images/diveflag.gif"), JLabel.CENTER);
jl.setFont(new Font("Times-Roman", Font.BOLD, 17));
ta = new JTextArea("This application uses a" +
" typical Graphical User Interface (GUI)," +
" featuring AWT layout managers and Project" +
" Swing components, such as buttons, borders," +
" text areas, menus, and more." +
" \n\nIn addition, the dive log's functionality" +
" uses AWT event handlers, methods to manipulate" +
" data, Java I/O to save user input to files," +
" and special classes to include HTML pages with" +
" live links.");
ta.setFont(new Font("SansSerif", Font.PLAIN, 14));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setBorder(BorderFactory.createTitledBorder(" Welcome to the Java Technology Dive Log "));
diver = new JLabel("", new ImageIcon("images/diver.jpg"), JLabel.CENTER);
add(jl, BorderLayout.NORTH);
add(ta, BorderLayout.CENTER);
add(diver, BorderLayout.SOUTH);
}//closes constructor
} // Closes class
The files are in C:\divelog
the pics are in C:\divelog\images
the pics are diver.jpg and diveflag.gif -
Yet Another Executable Jar Problem... :)
I completed the first part of the Dive Log tutorial here on Sun's website, and I decided to make an executable JAR file. I create the following manifest file and put it in the appropriate directory in the JAR:
Manifest-Version: 1.0
Created-By: Me
Main-Class: DiveLog
Note that there is a carriage return after the Main-Class statement. I run it by double-clicking and I get the usual "couldn't find main class" stuff. I open a console and run it with "java -jar divelog.jar" with the following results:
Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:
divelog/DiveLog)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Then I read somewhere that if your main class is part of a package, you must use its full name or whatever, so I change the Main-Class attribute to "divelog.DiveLog", as all the .java files were part of package "divelog", and run the JAR again, now getting this:
Exception in thread "main" java.lang.NoClassDefFoundError: divelog/DiveLog
Can anyone explain to me what is wrong here?Update: Since the
classes were all defined as part of a package, they
were expected by the interpreter to be under a
'divelog' directory within the archive. Which is why I suggested that you run it from the command line using the command I suggested.
At first I had assumed it was a
problem with the manifest, although I did have to
change the Main-Class attribute to point to
'package.Class' instead of just 'Class'.If it doesn't run the way I suggested then it is guaranteed to have nothing to do with the manifest. -
Problems with graphics display
Hi, I am doing the dive log application tutorial, I am developing the welcome class which dis palys a label with a image on it, but i cannot get it to display the image. the code is here, can someone help me
the images are in the folder called images in the tutorial pakage and this calss called welcome is also in the same package
* Welcome.java
* Created on November 16, 2002, 12:55 PM
package divelog;
import javax.swing.*;
import java.awt.*;
* @author jorge
public class Welcome extends JPanel
private JLabel jl;
private JTextArea ta;
private JLabel diver;
private ImageIcon icon = new ImageIcon("images/diver.jpg");
/** Creates a new instance of Welcome */
public Welcome()
setLayout(new BorderLayout());
diver = new JLabel("Welcome", icon, JLabel.CENTER);
//add(jl, BorderLayout.NORTH);
//add(ta, BorderLayout.CENTER);
add(diver, BorderLayout.SOUTH);
//setBackground(Color.black);
thank you:
Jorge M.hi, the clas that instatiates the class is called divelog, here is the code, the calss gets instatiated in the populateTabbedPane method.
* DiveLog.java
* Created on November 16, 2002, 12:44 PM
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
* @author jorge
public class DiveLog extends JFrame
//private JFrame dlframe; // not assigned yet without extending JFrame
private JTabbedPane tabbedPane; //not assigned yet
/** Creates a new instance of DiveLog */
public DiveLog()
//dlframe = new JFrame("The Dive Log Tutorial By Jorge M.");
super("The Dive Log Tutorial By Jorge M.");
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
buildMenu();
getContentPane().add(tabbedPane);
pack();
setSize(765,690);
//setBackground(Color.white);
setVisible(true);
}//end of constructor
private void populateTabbedPane()
// Create tabs with titles
tabbedPane.addTab( // here is where the welsome class is instatiated
"Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab(
"Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab(
"Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab(
"Statistics",
null,
new Statistics(),
"Click here to calculate" +
" dive statistics");
tabbedPane.addTab(
"Favorite Web Site",
null,
new Website(),
"Click here to see a web site");
tabbedPane.addTab(
"Resources",
null,
new Resources(),
"Click here to see a list " +
"of resources");
} //Ends populateTabbedPane method
//buold menu method header
private void buildMenu()
//insatatiates menu items
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//closes the application from the exit menu
item.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
menu.add(item);
mb.add(menu);
setJMenuBar(mb);
public static void main(String[] args)
DiveLog dl = new DiveLog(); -
Another cannot find symbol error (DiveLog)
Hi I am fairly new to java and I decided to try the tutorial DiveLog. I followed the instructions, however when I try to compile it, not with the DOS command, I keep getting an error stating that, Cannot find symbol class ..... The errors keep recurring at the tabbedPane.addTab(".....",
package DiveLog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
{ // Opens class
public JTabbedPane tabbedPane;
public JFrame dlframe;
public DiveLog()
{ // Opens contructor
//Create a frame object to add the application
//GUI components to.
dlframe = new JFrame("A Java(TM) Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
//A method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
} //Ends the constructor
private void populateTabbedPane()
{ // Opens populateTabbedPane method
// Create tabs with titles
tabbedPane.addTab("Welcome",
* null,*
* new Welcome(),*
* "Welcome to the Dive Log");*
* tabbedPane.addTab("Diver Data",*
* null,*
* new Diver(),*
* "Click here to enter diver data");*
* tabbedPane.addTab("Log Dives",*
* null,*
* new Dives(),*
* "Click here to enter dives");*
* tabbedPane.addTab("Statistics",*
* null,*
* new Statistics(),*
* "Click here to calculate dive statistics");*
* tabbedPane.addTab("Favorite Web Site",*
* null,*
* new WebSite(),*
* "Click here to see a web site");*
* tabbedPane.addTab("Resources",*
* null,*
* new Resources(),*
* "Click here to see a list of resources");*
* } //Ends populateTabbedPane method*
private void buildMenu()
{ // Opens buildMenu method
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
} //Ends the buildMenu method
} //Ends class
If you could help me, please explain it into terms that I would understand as I am still new to the entire language. Thankscannot find symbol: whatever class or method signature or variable you use was never declared. It's as simple as that. Make sure that the names are correct; if a class is missing (thanks a bunch for omitting the relevant part of the error message :p), ensure the compiled .class file is in the classpath, if a method isn't found make sure that the arguments are provided exactly in the same order, number and type as the method declaration declares, and if a variable is missing make sure that you actually declared it.
Learn about code tags when posting code next time, by the way. -
Problems compiling when calling other classes
hello,
following the Sun tutorial "How to build a application" i wrote this code...
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog extends JFrame{
// make space in memory for a tabbed pane - not a object until constructor is called to initate
private JTabbedPane tabbedPane;
public DiveLog(){ //opens constructor - constructor iniaties objects
super("Jason's DiveLog"); // super calls jframe - this is cause DiveLog extends JFrame
addWindowListener(new WindowAdapter() // closes program form clicking "x" on the Jframe
{ //opens addWindowListener method
public void windowClosing(WindowEvent e){
System.exit(0);
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
//tabbedPane.setBackground(Color.blue);
//tabbedPane.setForeground(Color.white);
// method to add tabs
populateTabbedPane();
//method builds menu
buildMenu();
// put on JFrame and set sizes
getContentPane().add(tabbedPane);
pack();
setSize(765,690);
setBackground(Color.white);
setVisible(true);
} //ends constructor started on line 13 - DiveLog()
// Methods -- for the constructor
private void populateTabbedPane(){
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to Jason's Dive Log");
tabbedPane.addTab("Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab("Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Stats",
null,
new Statistics(),
"Click here to calculate stats");
} // ends tabbed pane method
private void buildMenu(){
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("FIle");
JMenuItem item = new JMenuItem("Exit");
menu.add(item);
mb.add(menu);
setJMenuBar(mb);
item.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e){
System.exit(0);
}// ends buildMenu method
} //ends class
then... i made the welcome, dives,diver.... classes ...they look like this...
package divelog;
import javax.swing.*;
import java.awt.*;
public class Welcome extends JPanel{
}all the .java files are in /home/mohadib/java_restore/DiveLog/
so per the tutorial i try to compile with this.....
javac -classpath /home/mohadib/java_restore/ DiveLog.java
but i get this error....
mohadib@mohadib ~/java_restore/DiveLog--->javac -classpath /home/mohadib/java_restore/ DiveLog.java
DiveLog.java:48: cannot resolve symbol
symbol : class Welcome
location: class divelog.DiveLog
new Welcome(),
^
DiveLog.java:53: cannot resolve symbol
symbol : class Diver
location: class divelog.DiveLog
new Diver(),
^
DiveLog.java:58: cannot resolve symbol
symbol : class Dives
location: class divelog.DiveLog
new Dives(),
^
DiveLog.java:63: cannot resolve symbol
symbol : class Statistics
location: class divelog.DiveLog
new Statistics(),
^
4 errors
could some one please tell me what im doing wrong :)
Thanks,
jd
found the problem...
i used this at the top of all the .java files....
package divelog;
then my dir tree looked like this....
/home/mohadib/java_restore/DIveLog
so i changed to
/home/mohadib/java_restore/divelog
and compiled with this....
javac -classpath /home/mohadib/java_restore DiveLog.java
then ran it with this.....
java -classpath /home/mohadib/java_restore divelog.DiveLog
thanks,
jd -
Why do I need a constructor here?
I just started to learn how to program in java and I am taking one of the tutorials now. I have just learned about constructors and I have this code from the tutorial that I am suppose to type in:
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JFrame dlframe; //Not assingned yet
private JTabbedPane tabbedPane; //Not assigned yet
public DiveLog()
// Create a frame object to add the
// application GUI components to.
dlframe = new JFrame(
"A Java Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
}// Ends constructor
I don't understand why I most make a DiveLog constructor instead of just typing :
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JFrame dlframe = new JFrame("A Java Technology Dive Log");;
private JTabbedPane tabbedPane;
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
This is the final program link incase you need to see it: http://java.sun.com/developer/onlineTraining/new2java/divelog/part1/DiveLog.javaA constructor allows you to construct objects. You can create more than one constructors which accept different parameters, in order to create objects of different attributes.
For example...
public class Ball {
private String color="white";
private double weight=50.0;
public Ball() { // this is the default constructor, if you use new Ball() to construct an object, then this object will have these attributes: color="white", weight=50.0
public Ball(String color,double weight) { //this constructor allows you to construct an object of your preferred attributes, for example, if you use new Ball("black",30.0) to construct an object, then this object will have these attributes: color="black", weight=30.0
this.color=color;
this.weight=weight;
}Hope this helps. -
Another DiveLog can't resolve symbol error
I am using NetBeans to go through the DiveLog tutorial, which I have first typed, then cut/pasted in (hence I've not included it here). On compilation I get the following error:
divelog/DiveLog.java [41:1] cannot resolve symbol
symbol : method addTab (java.lang.String,<nulltype>,divelog.Welcome,java.lang.String)
location: class javax.swing.JTabbedPane
tabbedPane.addTab("Welcome",
^
1 error
Errors compiling divelog (->).
The rest of the line looks like this:
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
(Note that I have cut out all the other tabs, just to focus the mind)
As I am sure you expect if I set the component parameter to null (rather than new Welcome()) it compiles just fine.
I have read the troubleshooting tips on the tutorial, and understand that I am not compiling the whole package, but as far as I know I am! I highlight the package and compile all, I have compiled the project, and both with the same result. I have also read many, many newsgroup entries on the same subject and I have been trying all the various solutions for the last two days.
I note that whilst the others have an error that points to Welcome, the error message I get is on the symbol addTab.
I get the same error if I javac it too. (from the Divelog directory I typed javac -classpath d:\java\myjava\ DiveLog.java, and also tried setting a CLASSPATH environmental variable)
I have my path (environmental variable) set to: d:\java\j2sdk_nb\j2sdk1.4.2\bin
I have also set CLASSPATH to d:\java\myJava
Please remember the pain of newbie!
Thanks, Myles
PS I am working in Windows XPThe compiler is saying that in the JTabbedPane class, there is no method that takes a String, a null, a divelog.Welcome, and another String as parameters. I am guessing that in the divelog.Welcome class source code, you are missing something like the bolded text below.
public class Welcome extends JPanel
I'm making this guess because the JTabbedPane needs a Component for the third argument. If you still can't make sense of this, post the page of the tutorial so we can look at it. -
Compiling Application Help Needed
Ok, I try compiling with TextPad my first application from the application tutorial (http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1) and i get this error:
C:\Documents and Settings\Nancy Schott\My Documents\Matt's Stuff\Programming\Divelog\DiveLog.java:50: cannot resolve symbol
symbol : class Welcome
location: class divelog.DiveLog
tabbedPane.addTab("Welcome", null, new Welcome(), "Welcome to Dive Log");
(the error is at the new Welcome() spot)
1 error
but it is with all of the tabbedPane.addTab stuff. Could someone help me, because I can not figure it out and the troubleshooting thing at the end of it didn't help.
I compile useing the default TextPad command. It is something like
javac $FileDir $File
which means that for this it is saying
javac C:\My Documents\Matt's Stuff\Programming\Divelog DiveLog.java
Please Help!! Thankshere is my code for divelog:
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JFrame dlframe; //not assigned yet
private JTabbedPane tabbedPane; //not assigned yet
public DiveLog()
// Create a frame object to add the application GUI components to.
dlframe = new JFrame("A Java Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane =new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
}// Ends constructor
// Method header
private void populateTabbedPane()
//creates tabs with titles
tabbedPane.addTab("Welcome", null, new Welcome(), "Welcome to Dive Log");
//tabbedPane.addTab("Diver Data", null, new Diver(), "Click here to enter diver data");
//tabbedPane.addTab( "Log Dives", null, new Dives(), "Click here to enter dives");
//tabbedPane.addTab("Statistics", null, new Statistics(), "Click here to calculate" + " dive statistics");
//tabbedPane.addTab("Favorite Web Site", null, new WebSite(), "Click here to see a web site");
//tabbedPane.addTab("Resources", null, new Resources(), "Click here to see a list " + "of resources");
}//Ends populateTabbedPane method
private void buildMenu()
// Opens buildMenu method
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit menu item.
item.addActionListener(new ActionListener()
// Opens addActionListener method
public void actionPerformed(ActionEvent e)
// Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
} //Ends the buildMenu method
public static void main(String[] args)
DiveLog dl = new DiveLog();
}//Ends Class
And here is my welcome class
package divelog;
import javax.swing.*;
import java.awt.*;
public class Welcome extends JPanel
{ // Opens class
} // Closes class -
Hi everyone.
I am trying to compile the Divelog.java file but seem to get the following two errors.
C:\>javac c:\divelog\Divelog.java
c:\divelog\Divelog.java:7: class DiveLog is public, should be declared in a file named DiveLog.java
public class DiveLog extends JFrame
^
c:\divelog\Divelog.java:63: cannot resolve symbol
symbol : class WebSite
location: class divelog.DiveLog
tabbedPane.addTab("Favorite Web Site", null, new WebSite(), "Click here to see a web site" );
^
2 errors
I have installed j2se in the following directory c:\j2sdk1.4.2
The Divelog files are located in the following directory c:\divelog\
(so for example my Divelog.java file is located in c:\divelog\Divelog.java
Please could anyone help me with this problem, all the dive log files are correct, as i have checked several times.
Any help would be very much so aprreciatedhi, thanks for replying.
the file Divelog.java is as follows
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog extends JFrame
{ // Opens Divelog class
private JTabbedPane tabbedPane; //Not assigned yet.
public DiveLog()
{ // Opens Divelog constructor
// Create a frame object to add the
// application GUI components to.
super("A Java(TM) Technology Dive Log");
// Closes from title bar
//and from menu
addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
// Calls a method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu buildMenu();
getContentPane().add(tabbedPane);
} // Ends constructor
private void populateTabbedPane()
{ // Opens populateTabbedPane method definition
// Create tabs with titles
tabbedPane.addTab("Welcome",null,new Welcome(),"Welcometo the Dive Log");
tabbedPane.addTab("Diver Data",null,new Diver(),"Click here to enter diver data");
tabbedPane.addTab("Log Dives",null,new Dives(),"Click here to enter dives");
tabbedPane.addTab("Statistics",null,new Statistics(),"Click here to calculate" +" dive statistics");
tabbedPane.addTab("Favorite Web Site", null, new WebSite(), "Click here to see a web site" );
tabbedPane.addTab("Resources",null,new Resources(),"Click here to see a list " +"of resources");
} //Ends populateTabbedPane method
// Method header
private void buildMenu()
{ // Opens buildMenu method definition
// Instantiates JMenuBar, JMenu,
// and JMenuItem.
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Ends buildMenu method
//Adds the item to the menu object
menu.add(item);
//Adds the menu object with item
//onto the menu bar
mb.add(menu);
//Sets the menu bar in the frame
setJMenuBar(mb);
}// Closes buildMenu method
// main method and entry point for app
public static void main(String[] args)
{ // Opens main method
DiveLog dl = new DiveLog();
dl.pack();
dl.setSize(765, 690);
dl.setBackground(Color.white);
dl.setVisible(true);
} // Closes main method
} //Ends class
the divelog folder aslo contains several other filse relevent to the divelog application(as followed from the tutorial) -
J* help needed!!
Hi im trying to implement an example from the Swing Tutorial site.I have problems invoking the program.It has a "Exception in thread "main" java.lang.NoClassDefFoundError:DiveLog(wrong name:divelog/DiveLog)
my working directory for this program is
c:\program files\java\bin\divelog
my classpath is
set CLASSPATH=.;c:\programfiles\java\bin\.jar;c:\program files\java\bin
Do i have to change anything in my classpath inorder to invoke javax.swing?? coz im having tons of problems trying to get a Japplet from working!!!
Pls help!
These are the codes:
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JFrame dlframe; //not assigned yet.
private JTabbedPane tabbedPane; //not assigned yet.
public DiveLog()
// Create a frame object to add the
//application GUI components to.
dlframe = new JFrame (" A Java(TM) Technology Dive Log");
//Closes from title bar and from menu
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
//Tabbed Pane with panels for Jcomponents
//Instantiate JTabbedPane with keyboard
tabbedPane = new JTabbedPane (SwingConstants.LEFT);
//Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
private void populateTabbedPane()
//Create Tabs with titles
tabbedPane.addTab("Welcome",null,new Welcome(),"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data",null,new Diver(),"Click here to enter diver data");
tabbedPane.addTab("Log Dives",null,new Dives(),"Click here to enter dives");
tabbedPane.addTab("Statistics",null,new Statistics(),"Click here to calculate" +
"dives statistics");
tabbedPane.addTab("Favorite Web Site",null,new WebSite(),"Click here to see a web site");
tabbedPane.addTab("Resources",null,new Resources(),"Click here to see a list"+
"of resources");
}//end of populateTabbedPane method
//method header
private void bulidMenu()
//Instantiate JMenuBar,JMenu and JMenuItem
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//closes the application from the Exit menu item
item.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
//adds item to the menu object
menu.add(item);
//adds menu object with item
mb.add(menu);
//sets the menu bar in the frame
dlframe.setJMenuBar(mb);
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
}// ends bulidMenu method
public static void main(String[] args)
DiveLog dl = new DiveLog();
package divelog;
* This class creates the content on the
* Dives tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Dives extends JPanel
{ // opens class
} //closes class
package divelog;
* This class creates the content on the
* Diver tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Diver extends JPanel
{ // opens class
} //closes class
package divelog;
* This class creates the content on the
* Welcome tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Welcome extends JPanel
{ // opens class
} //closes class
package divelog;
* This class creates the content on the
* Statistics tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Statistics extends JPanel
{ // opens class
} //closes class
package divelog;
* This class creates the content on the
* WebSite tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class WebSite extends JPanel
{ // opens class
} //closes class
package divelog;
* This class creates the content on the
* Resources tabbed pane in the Dive Log
* applcation.
* @version 1.0
//import for buttons, labels and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Resources extends JPanel
{ // opens class
} //closes class
Ensure that c:\program files\java\bin\divelog (where youhav put ur file) is in your classpath
Jana -
Hi ,
I am having a wierd problem with one of th tutorials onavaiable on this site. It is the Divelog tutorial. I am running java 1.4.1_02 on windows 2000. When I run the tutorial on this machine it hangs at the point when it is supposed to build the Jframe. (I figured this out by placing some system.println commands in there) Whe one of my office mates run it on the same type of machine it works. I know this is a long shoty, but any advice or ideas???
Thanks,
Bernieok, but like I said it works on other machines with similar configs.
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
{ //Opens DiveLog class
private JTabbedPane tabbedPane;
private JFrame dlframe;
public DiveLog()
{ //Opens DiveLog constructor
//Create a frame object to add the application
//GUI components to.
System.out.println("creating frame");
dlframe = new JFrame();
System.out.println("setting title");
dlframe.setTitle("A Java Technology Dive Log");
// Closes from title bar
//and from menu
System.out.println("adding window listener");
dlframe.addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
System.out.println("creating tabbedpane");
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
// Calls a method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
} // Ends class constructor
private void populateTabbedPane()
{ // Opens populateTabbedPane method definition
// Create tabs with titles
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab("Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Statistics",
null,
new Statistics(),
"Click here to calculate dive statistics");
tabbedPane.addTab("Favorite Web Site",
null,
new WebSite(),
"Click here to see a web site");
tabbedPane.addTab("Resources",
null,
new Resources(),
"Click here to see a list of resources");
} //Ends populateTabbedPane method
private void buildMenu()
{ // Opens buildMenu method definition
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
}// Closes buildMenu method
dlframe.getContentPane().add(tabbedPane);
System.out.println("packing");
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setLocation(200,200);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
// main method and entry point for app
public static void main(String[] args)
{ // Opens main method
DiveLog dl = new DiveLog();
} // Closes main method
} //Ends class DiveLog -
Cannot Compile. Pls. help!
I cannot compile the following program which calls for another 6 class files from its code. Please note the main program (DiveLog.java)+the other 6 class files are stored in the same directory.
And also as this involves "package" I tried to compile it as "javac -classpath DiveLog.jav". But I still get the 'cannot resolve symbol' error messages.
DiveLog.java (Main Program)
package DiveLog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JFrame dlframe; //Not assigned yet.
private JTabbedPane tabbedPane; //Not assigned yet.
//Begins Constructor
public DiveLog()
// Create a frame object to add the application GUI components to.
dlframe = new JFrame("A Java(TM) Technology Dive Log");
// Closes from title bar and from menu
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
}// Ends Constructor
private void populateTabbedPane()
// Create tabs with titles
tabbedPane.addTab("Welcome", null, new Welcome(), "Welcome to the Dive Log");
tabbedPane.addTab("Diver Data", null, new Diver(), "Click here to enter diver data");
tabbedPane.addTab("Log Dives", null, new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Statistics", null, new Statistics(),
"Click here to calculate" + " dive statistics");
tabbedPane.addTab("Favorite Web Site", null, new Website(),
"Click here to see a web site");
tabbedPane.addTab("Resources", null, new Resources(),
"Click here to see a list of resources");
} //Ends populateTabbedPane method
// Method header
private void buildMenu()
// Instantiates JMenuBar, JMenu,
// and JMenuItem.
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit menu item.
item.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
//Adds the item to the menu object
menu.add(item);
//Adds the menu object with item onto the menu bar
mb.add(menu);
//Sets the menu bar in the frame
dlframe.setJMenuBar(mb);
} //Ends buildMenu method
public static void main(String[] args)
DiveLog dl = new DiveLog();
} //Ends Class
===========================================
Welcome.class (one of the 6 class files.The other 5 are identical to this.)
package divelog;
* This class creates the content on the
* Welcome tabbed pane in the Dive Log
* application.
* @version 1.0
//import for buttons, labels, and images
import javax.swing.*;
//import for layout manager
import java.awt.*;
public class Welcome extends JPanel
{ //Opens class
}//Closes class
=========================================================Might be a typo when you posted, but your DiveLog class is in package DiveLog, whereas your Welcome class is in package divelog (note the capitalization differences).
And even though they're in the same package, i'm always a fan of importing all the files you're going to need explicitly, such as
import divelog.Welcome
this applies to using the wildcard character too (as in, you shouldn't) to import files. Explicitly listing all imports allows you, and any other developer, to quickly see a list of all classes used. -
Package divelog: Class divelog.Welcome not found in declaration
DiveLog.java:61: Class divelog.Welcome not found in type declaration.
new Welcome(),
private void populateTabbedPane()
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
Welcome.class exist in same directory as DiveLog.javais it public ?
Maybe you are looking for
-
Help! My pan doesn't work..
I have a PreSonus inteface and Logic pro 9 . Everything works great except when I pan tracks I hear no panning going on. The display appears to be panning the track but it is not happening audibly, not on my headphones either. This is probably someth
-
How can I NOT have my outgoing emails accumulate on gmail?
I'm using Thunderbird with gmail via POP3, not IMAP. I want to just grab the emails, download them to my PC, and delete them from gmail. That part works great. But with both TB and my previous Outlook 2000, my outgoing emails end up staying on the gm
-
Hi All I'm knew to Logic 9 and have not been able to find information on how to setup multiple headphones. I have an Apogee Ensemble and a Nady HA 1x4 stereo headphone amp. I'd like to send individual headphone mixes thru the ensemble and logic to th
-
PrintToPrinter, ExportToDisk Problem
Hello, I am using Crystal Reports 2008 inside VS2005 and I wanna get the report in PDF format. The first thing i tried was exporting the report using the ExportToDisk function. It works ok, but the fonts of the PDF generated werent the same as the fo
-
How does the Mac App Store work?!
Hey guys i recently posted this quesiton in a different area of the community but instead of being helped was just ridiculed for posting in the wrong place... +1 for helpfulness guys :/ lol Anyways... ive been told to ask in the development section..