View Single Post
  #1 (permalink)  
Old 05-08-2008, 10:00 PM
kewlgeye kewlgeye is offline
Member
 
Join Date: Apr 2008
Posts: 33
kewlgeye is on a distinguished road
JOptionPane Display Difficulties
Hello to all

I am trying to practice with arrays and GUI's using joptionpanes or boxes as well.

I am having difficulty with viewing the resulting windows. If you enter 5 as the size of the array then the window should print 5 4 3 2 1 in the messagebox but instead it freezes after I enter 5 and nothing happens, also if I just use the CMD to deliver the message "Please enter the size of the array: " then it works but I have to select ok 5 seperate times for each number instead of one box displaying 5 4 3 2 1.

How can I fix this. Here is the code that I made


Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.JOptionPane; public class array{ static Scanner console = new Scanner(System.in); JFrame frame; public array(){ frame = new JFrame("Array"); JButton button = new JButton("Enter Here"); button.addActionListener(new MyAction()); frame.add(button); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public class MyAction implements ActionListener{ public void actionPerformed(ActionEvent e){ JOptionPane.showInputDialog(null, "" + "Enter the size of the array: "); int arraySize; arraySize = console.nextInt(); int[] list = new int[arraySize]; for (arraySize = 0; arraySize < list.length; arraySize++) if (arraySize == 0) continue; else JOptionPane.showMessageDialog(frame, "" + arraySize + " " + "is your number", "Your Silly Numbers", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(frame, "" + list.length + " " + "is your number", "Your Silly Numbers", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] args){ array db = new array(); } }
Reply With Quote
Sponsored Links