import javax.swing.*;
public class HelloJava{
public static void main(String[] args){
JFrame frame = new JFrame("Hello Java!");
JLabel label = new JLabel("Hello Java!", JLabel.CENTER);
frame.getContentPane().add(label);
frame.setSize(300,300);
frame.setVisible(true);
}
}
This code ran easily on Windows but when I tried to run it on my
univ's Sun machines I got the following errors:
Exception in thread "main" java.lang.InternalError: Can't connect to
X11 window
server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:1
26)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvi
ronment.java:62)
at java.awt.Window.init(Window.java:223)
at java.awt.Window.<init>(Window.java:267)
at java.awt.Frame.<init>(Frame.java:398)
at javax.swing.JFrame.<init>(JFrame.java:198)
at HelloJava.main(HelloJava.java:5)
Can someone tell me why this is happening?
Thanks,
Santosh
Did you launch the program from a bare login shell, rather than an
xterm window? If so, then you need to get your graphical environment
started first. I can't give you much help there, but you might try the
command:
startx
which usually works in Linux. If not, ask how to start an X desktop on
Solaris (I assume that's what your Sun box is running) in any Unix
newsgroup, or at the help desk in your schools computer lab, and you
should get help.
If you already have an X desktop running, and you're running the
command to start your program from an xterm window, then maybe it's
your DISPLAY environment variable. Try these commands before you
launch your program
DISPLAY=127.0.0.1:0.0
export DISPLAY
and it might help.
----
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.
Santosh
Dave Glasser <dgla...@pobox.com> wrote in message news:<947CDB7C2A35C1E0.54B0EB13...@lp.airnews.net>...
Franck
"santosh" <santo...@yahoo.com> a écrit dans le message de news:
6484d538.03040...@posting.google.com...
>If you don't want to run any x-server on your sun
>(good way for a production machine) add this param
>to your java process :
>-Djava.awt.headless=true
He needs an X server to display his app's JFrame though. My
understanding is that that the java.awt.headless property is only used
to simulate a headless environment, probably so you can test code to
make sure it will run in a headless environment before deploying it as
a Unix daemon or Windows service. For more info:
http://mindprod.com/jglossheadless.html
>Thanks Dave. You did point me in the right direction. I havent still
>been able to correct the problem yet but I am working on it.
You're welcome, glad I could help. BTW, are you telnetting into that
Sun machine, or actually sitting down in front of it? If you're
telnetting in, you'll have to have the X server running on whatever
box you're telnetting from, which is probably a Windows box. A lot of
universities, I imagine, have X server software installed on their
Windows machines, but again you'll have to have someone knowledgeable
help you.