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.
I'm trying to get into programming with Java, and I can't seem to make GUI applications. Here's the code:
test.java
Code:
import javax.swing.*;
public class test
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"Hello");
}
}
Here's what happens. The message box opens and shows hello, but then I can't click on the OK button to close the program. I can't even click on the close button in the title bar.
When I run java test in Windows, it works flawlessly, but in Xubuntu, it just sits there. I use the exact same class file in each case, so what's the deal? It can't be the compiler, can it? It must be the JRE I've got.
I'm trying to get into programming with Java, and I can't seem to make GUI applications. Here's the code:
test.java
Code:
import javax.swing.*;
public class test
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"Hello");
}
}
Here's what happens. The message box opens and shows hello, but then I can't click on the OK button to close the program. I can't even click on the close button in the title bar.
When I run java test in Windows, it works flawlessly, but in Xubuntu, it just sits there. I use the exact same class file in each case, so what's the deal? It can't be the compiler, can it? It must be the JRE I've got.
I don't see anything wrong with the code. Can you post the output of this command:
Any ideas?
I don't see anything wrong with the code. Can you post the output of this command:
me@mycomputer:~$ java -version
java version "1.5.0"
gij (GNU libgcj) version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR PARTICULAR PURPOSE.
I compiled the code without any errors using gjc -C test.java
Just to repeat: I use the Windows terminal and got a working dialog box, but it freezes up in Linux. The little alert icon is also kind of funky. I downloaded java and the gjc from synaptic package manager just the other night.
Last time I check on gjc, it had less than complete support for swing. You should use the sun jdk or opendjk, really. Both are available from the repositories, by the way.
Thank you for your help, jay73. It turns out that it was not the gjc that was the issue, it was my runtime environment (just like I thought). When I downloaded the OpenJDK JRE, it ran the applications without any issues. Now I have three more questions regarding Linux Java.
But I'm confused now about how the "java" command works. What exactly does this command call? The most recent runtime environment?
Furthermore, why is everyone saying that gjc is not fully compatible with GTK and whatnot? Is that only considered for compiling java binaries instead of class files? After all, the class files are working just fine. Am I doing something wrong by typing gcj -C name.java?
Finally, is there anything that OpenJDK can't do that the official one can?
But I'm confused now about how the "java" command works. What exactly does this command call? The most recent runtime environment?
Java calls the default runtime. This default can be changed by running update-alternatives --config java, update-alternatives --config javac, etc. Personally, I like to use galternatives (it is in the repositories too and will appear under Systems Tools > Alternatives configurator), which allows you to do all of this without any typing. I imagine that this was done automatically when you installed openJDK but it does not hurt to check. For a quick check, run the java -version command.
Quote:
Furthermore, why is everyone saying that gjc is not fully compatible with GTK and whatnot?
It should be compatible with GTK but is relies on older specifications of the java language so it generally will not work without issues if you try to use recent features.
Quote:
Finally, is there anything that OpenJDK can't do that the official one can?
For most practical purposes, no. OpenJDK is essentially the official Sun JDK with proprietary code removed and reimplemented. That being said, not everything works flawlessly. For example, one of the advantages of openJDK is that, unlike the sun jdk, it provides a 64 bit plug-in; but its downside is that this plug-in appears to have issues with certain sites that the sun version has not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.