Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-07-2005, 10:35 AM   #1
LQ Newbie
Registered: Sep 2005
Location: Singapore
Distribution: Fedora Core / Debian
Posts: 2

Rep: Reputation: 0
Question Inconsistent behaviour of java.awt in Linux/Windows


i'm just trying out some simple java gui programming using awt classes.


import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//start of class
public class Calculator_GUI extends JFrame {

private JTextField textBox;
private JTextArea answerBox, msgBox;
private JButton resetBtn, suggestBtn;

public Calculator_GUI() {
	Container container = getContentPane();
	container.setLayout(new FlowLayout()); 

	//text box for input 
	textBox = new JTextField("0", 10);
	//reset button
	resetBtn = new JButton("RESET");
	//register the event handlers
	TextFieldHandler fieldHandler = new TextFieldHandler();
	ButtonHandler btnHandler = new ButtonHandler();

	setSize(400, 300);


//inner class for handling textbox events
private class TextFieldHandler implements ActionListener {
	//handle textbox event
	public void actionPerformed(ActionEvent e) {}

//inner class for handling button events
private class ButtonHandler implements ActionListener {
	//handle button event
	public void actionPerformed(ActionEvent e) {
		String text = textBox.getText();
		JOptionPane.showMessageDialog(null, text);


//main function
public static void main (String args[]) {

	Calculator_GUI cal = new Calculator_GUI();


} //close brkt for class
the code is very simple. just a text field and a reset button.

i get funny problems when i try to run this on linux. the main problm is with the text editing. it doesn't show the real time changes when i try to edit. nor do i see the blinking cursor. i got frustrated, and tried running the class file on windows. and it worked! now, isn't java designed to be portable?? why am i getting inconsistent behaviour across platforms?? odd... do i really need to switch to windows??

anyone knows why??

platform: FC4
java 1.5
Old 09-07-2005, 11:58 AM   #2
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,773

Rep: Reputation: 469Reputation: 469Reputation: 469Reputation: 469Reputation: 469
Your code seems to works for me on Solaris, with both JDK 1.4 and 1.5.

Are you sure of the JVM you use on FC ?

Can you explain more what happens on Linux, you do not see the text entered in the textfield ? never ?
Did you try with a different window manager ?
Old 09-08-2005, 09:34 AM   #3
LQ Newbie
Registered: Sep 2005
Location: Singapore
Distribution: Fedora Core / Debian
Posts: 2

Original Poster
Rep: Reputation: 0
thanks for testing it on solaris jlliagre! i tried it out on both KDE and Gnome, it gives me the exact same funny behaviour.

the text field is editable only at the first time. after i pressed the 'reset', the text field is frozed. i cant type in anything. the textfield does get back to '0', but you cant do anything with it after the first time. isn't that mightily odd? i don't get that in windows.

i wonder if its the JVM. i can only wonder. how do you check its its the culprit?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
downloading java AWT package zeppelin147 Linux - Software 1 11-17-2005 05:53 PM
weird behaviour while accessing Windows shares. koodoo Linux - Newbie 4 09-27-2005 06:55 PM
KDE-windows behaviour kirth SUSE / openSUSE 5 01-24-2005 06:10 AM
Java AWT not working naveenhifi Programming 1 02-26-2004 10:35 PM
fluxbox java awt no title bar Kman Linux - Software 0 06-18-2003 10:47 AM > Forums > Non-*NIX Forums > Programming

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

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