LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2008, 01:26 PM   #1
IsharaComix
Member
 
Registered: Sep 2008
Location: Raleigh
Distribution: Ubuntu 8.10
Posts: 88
Blog Entries: 1

Rep: Reputation: 15
My Java Swing Programs behave strangely.


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.

Any ideas?
 
Old 10-18-2008, 02:01 PM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Quote:
Originally Posted by IsharaComix View Post
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:

java -version
 
Old 10-18-2008, 04:01 PM   #3
IsharaComix
Member
 
Registered: Sep 2008
Location: Raleigh
Distribution: Ubuntu 8.10
Posts: 88

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Output

Code:
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.
 
Old 10-18-2008, 07:19 PM   #4
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
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.
 
Old 10-18-2008, 07:54 PM   #5
IsharaComix
Member
 
Registered: Sep 2008
Location: Raleigh
Distribution: Ubuntu 8.10
Posts: 88

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Thank you, but I have further questions.

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?
 
Old 10-18-2008, 08:10 PM   #6
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Quote:
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
a java-swing problem... shosh Programming 2 06-26-2009 05:38 AM
java swing hangs tERn Programming 2 06-12-2008 07:59 AM
Java swing problem Veteq Programming 4 11-28-2006 03:06 PM
java swing JTextArea gauravbagga Programming 1 05-23-2005 04:34 AM
Java help! Using Swing and Layouts Mega Man X Programming 7 02-05-2004 05:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration