Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First Java compilation problem

Status
Not open for further replies.

sedawk

Programmer
Feb 5, 2002
247
0
0
US
Hi,

This is my first Java program. When I try to compile it, I got errors. It should be very simple.

This is how I compile it:
javac testGUI.java

I got this error:

testgui.java 9: cannot find symbol
symbol: class GUI
public clas testGUI extends GUI {
^
... (and some other similar ones)

Here are my files:

Code:
// File: testGUI.java
package gui;

import java.awt.*;

public class testGUI extends GUI {

  public void init() {
    NoInput = true;
    super.init();
  }
  public void paintToDoubleBuffer(Graphics g) {
    System.out.println("entered testGUI::paintToDoubleBuffer\n");
    paintGridCell(g, 20, 20, 110, 0.5f, 0.0f, 1.0f);
  }
  public void doRunButton() {
    P("OVERRIDDEN doRunButton()\n");
  }
}

Code:
// File: GUI.java
package gui;
import java.awt.*;
import java.applet.Applet;

public class GUI extends Applet {

    // Flags to disable standard GUI components:
    public boolean NoInput       = false;
    public boolean NoOutput      = false;
    public boolean NoGraphics    = false;
    public boolean NoRunButton   = false;
    public boolean NoResetButton = false;
    public int BigText           = 0;

    public String RunLabel   = new String("Run");
    public String ResetLabel = new String("Reset");

    public String InitialInput = "";

    Graphics background;  // used for double buffering
    Image im;
    int width = 640;
    int height = 480;

    protected Panel panel;
    TextField inputText;
    TextArea outputText;
    GUICanvas canvas;

    Color colors[];
    int NumColors = 16;

    public String getAppletInfo() {
        return "GUI classes by Mark Watson";
    }

    // some other functions skipped here, e.g., paint()
}

class GUICanvas extends Canvas {
   Graphics background;  // used for double buffering
   Image im;
   public GUI parent;
   public void init() {
       //System.out.println("entering GUICanvas::init\n");
       try {
                    Dimension d = size();
                    im = createImage(d.width, d.height);
                    background = im.getGraphics();
           } catch (Exception ex) {
                    background = null;
           }
   }

   // skip some functions here too
}
 
I assume you use Microsoft Windows,you may have a directory called gui on C Drive
you should compile Java class by
c:\javac gui\testGUI.java

The following is for Linux OS:
mylinux:/# javac gui/testGUI.java
 
I am sorry for using 3 posts to answer and you can use javac *.java if you are in gui directory.
c:\gui\>javac *.java
 
Thanks Prosper.

I tried the syntax you suggested in the gui directory. Compilation fine but when using appletviewer, another error came out:

java.lang.NoClassDefFoundError: testGUI (wrong name: gui/testGUI)
at java.lang.ClassLoader.defineClass1(Native Method)
.... (a couple more lines like this)

 
You have to specify the package in your html page.
Code:
<html>
<head></head>
<body>
<applet code="gui/testGUI" width="600" height="450">
</body>
</html>

 
If you store the class testGui.class in gui in c drive like c:\gui
Your html page should be stored in c:\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top