LinuxQuestions.org
Help answer threads with 0 replies.
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 09-07-2005, 11:35 AM   #1
liangzan
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


hi,

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

Code:
/* 
Calculator_GUI.java
*/

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

//start of class
public class Calculator_GUI extends JFrame {

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


//constructor
public Calculator_GUI() {
	super("Calculator");
	
	Container container = getContentPane();
	container.setLayout(new FlowLayout()); 

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

	setSize(400, 300);
	setVisible(true);

	
}

//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);
		textBox.setText("0");

	}
}


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

	Calculator_GUI cal = new Calculator_GUI();
	cal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

} //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, 12:58 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
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, 10:34 AM   #3
liangzan
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?
 
  


Reply


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


All times are GMT -5. The time now is 09:51 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration