-   Programming (
-   -   Inconsistent behaviour of java.awt in Linux/Windows (

liangzan 09-07-2005 11:35 AM

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

jlliagre 09-07-2005 12:58 PM

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 ?

liangzan 09-08-2005 10:34 AM

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? :scratch:

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