ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi everyone
i'm a linux newbie who's only installed mandrake 9.2 a few months ago....
the problem is, i'm trying to javac this .java file i made to try to understand java gui application, and i got an error message saying
Cannot locate class "JFrame"
and the only class in the file extends JFrame. i tried looking around and heard some stuff about classpath, but i still don't know anything. can anybody help?
thanks
I think you need to set your CLASSPATH.. or you could try typing javac while you are in the directory where the binary(executable) is stored.. try looking in BIN directories..
HOPE this helped..
could you look also at my post and help me with JDBC problem.. i used jcreator to program in java and use microsoft access database thru ODBC.. id appreciate any suggestion you could give me.. to find my post just search for JAVA.. the title of my post is JDBC problem......
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class StopGo extends JFrame
{
private final int d = 100, o=50;
public void paint (Graphics g)
{
boolean condition = (Math.random() >= 0.5);
if (condition)
g.setColor(Color.red);
else
g.setColor(Color.green);
g.fillOval(d,d,d,d);
g.drawString ("Hello world!", 150, 150);
g.setColor(Color.blue);
g.drawOval(50, 100, 50, 50);
}
}
here's the code... the compilation error pointed to the class name with the first mention of JFrame. no compilation errors occured on the import lines though.
any help is greatly appreciated >_< thank you!
isolated the problem some more. i couldn't import JFrame in javax.swing
but i could import anything in java.awt, and i'm guessing most of the other libraries as well.
in javax/swing/
there is a JFrame.h file, but that's it. um.......anybody help? ^^;;;;;;;
i tried removing import javax.swing.JFrame AND "extends JFrame" and it compiled.
thanks
Hi
I was able to compile it or Eclipse does it automatically, when saving the file. It doesn't contain a main method
In order to run it under Eclipse it's just go to Run/Run As/Java Application.
I recommend take a look on the Eclipse SDK. Especially for Java beginners, Eclipse has nice editing features like auto completion, rename, auto import selector and lot more.
Just go to http://www.eclipse.org and download the latest stable release and unix examples for Linux. If you're using Gnome or KDE select the GTK version. Installation is even easier: change to root and cd to /opt. Do a unzip <dist.package> and unzip eclipse-example.... as user just change to /opt/eclipse and start ./eclipse Take time and make familiar with the GUI (there's a tutorial within the product).
Your code is mostly fine (it compiles properly as is), the problem is with your Java installation. Make sure you have the Sun Java SDK 1.2 or greater.
Here's your code, modified to run properly (it compiled before, just didn't run properly):
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; //for timed task's ActionListener
import java.io.*;
public class StopGo extends JFrame
{
public static final int DELAY = 5000; //timer delay in milliseconds
public static void main(String[] args)
{
//create new instance of StopGo
final StopGo demo = new StopGo();
//300x300 window
demo.setSize(300, 300);
//close when 'x' is pressed
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//show it
demo.setVisible(true);
//create task to perform
ActionListener repaintJob = new ActionListener(){
public void actionPerformed(ActionEvent e)
{
demo.repaint(); //JFrame's repaint()
}
};
//timer will perform it over specified interval
Timer timer = new Timer(DELAY, repaintJob);
timer.start(); //repeat repaintJob every DELAY milliseconds
}
//---- original code
private final int d = 100, o=50;
public void paint (Graphics g)
{
boolean condition = (Math.random() >= 0.5);
if (condition)
g.setColor(Color.red);
else
g.setColor(Color.green);
g.fillOval(d,d,d,d);
g.drawString ("Hello world!", 150, 150);
g.setColor(Color.blue);
g.drawOval(50, 100, 50, 50);
}
}
This adds a main method so it'll run. paint() is executed only once (other than during window resizing), so a timer executes repaint() every 5 seconds, causing the paint() method to be called repeatedly.
ummm thanks for the code i learn some stuff too but the problem is not the code. i think i have java 1.4 or something like that, i'll check again when i'm from that computer. but as i said, the problem is specifically in JFrame, since import javax.swing.*; didn't return any compilation error.
neither is any of the classes in awt. read my previous posts for more info :P
do i need to set a classpath? thanks...
The exact version is displayed via java -version
In most cases you do not need to set the classpath, except you're using libraries, that are not under $JAVA_HOME/ and it's subdirectories.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.