PDA

View Full Version : JOption not working properly



green_lantern
February 10th, 2009, 02:54 AM
couldn't find a fitting directory for this thread, mods please help

Hello,

I wrote a java program with a JOption input box, using the text editor. It compiles and doesnt give runtime errors with the terminal but when the first dialog box appears the programs seems to stop. However using an IDE the dialog boxes work as expected. Something im not doing?

dmizer
February 10th, 2009, 05:06 AM
Moved to programming talk.

HotCupOfJava
February 10th, 2009, 05:08 AM
Please post your code. Then we can probably spot the problem quickly.

green_lantern
February 11th, 2009, 03:43 AM
Please post your code. Then we can probably spot the problem quickly.

the code is fine, as I implied it works with an IDE but here it is:


import javax.swing.*;
public class multidimArrays
{
public static void main(String args[])
{
int table[][] = new int[13][13];
String strFirstFactor,
strSecondFactor;
int firstFactor,
secondFactor,
i,
j;
for(i=0; i<=12; i++)
{
for (j=0; j<=12; j++)
{
table[i][j] = i * j;
}
}
strFirstFactor = JOptionPane.showInputDialog("First Factor");
strSecondFactor = JOptionPane.showInputDialog("Second Factor");
firstFactor = Integer.parseInt(strFirstFactor);
secondFactor = Integer.parseInt(strSecondFactor);
JOptionPane.showMessageDialog(null, "The product is " + table[firstFactor][secondFactor],"Multiplication Table" ,JOptionPane.PLAIN_MESSAGE);
}
}


This program works fine in linux with an IDE and on windows with command line and IDE. The problem is that the terminal doesent seem to manage the dialogs well.

HotCupOfJava
February 11th, 2009, 04:05 AM
This program works fine in linux with an IDE and on windows with command line and IDE. The problem is that the terminal doesent seem to manage the dialogs well.

Ah, I wasn't aware of this part. I originally thought perhaps the IDE had done some automatic packaging or something else that might be throwing you. That's why I wanted to see. I just tested your code from the terminal on my Linux box and it executes fine. I'm curious: which Java Virtual Machine are you using? Did you get your Java through the repositories? I have noticed little bugs with some of the GNU project java packages (no offense Richard). I prefer to use Sun's stuff.

green_lantern
February 11th, 2009, 04:10 AM
Ah, I wasn't aware of this part. I originally thought perhaps the IDE had done some automatic packaging or something else that might be throwing you. That's why I wanted to see. I just tested your code from the terminal on my Linux box and it executes fine. I'm curious: which Java Virtual Machine are you using? Did you get your Java through the repositories? I have noticed little bugs with some of the GNU project java packages (no offense Richard). I prefer to use Sun's stuff.

I think that is it my friend. I will uninstall the JVM form the repos use sun's instead.