Results 1 to 5 of 5
- 01-11-2011, 11:12 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
Problem returning Array values Please help
I am trying to return my array values but cant seem to get them to display. Can someone please point me in the right direction.
Java Code:private void EnterActionPerformed(java.awt.event.ActionEvent evt) { // Enter Button functionality Scanner input = new Scanner(System.in); try{ //convert text input to integer for array int timeInt = Integer.parseInt(timeField.getText()); //input array values in a loop for (index = 0; index > 0; index++) { tarray[index][0] = input.nextInt(timeInt); } index++; } catch (Exception e) { JOptionPane.showMessageDialog(this, "Invalid Input in the Time field","ERROR",JOptionPane.ERROR_MESSAGE); return; } try{ //convert text input to integer for array int moneyInt = Integer.parseInt(moneyField.getText()); //input array values in a loop for (index = 0; index > 0; index++) { tarray[index][1] = input.nextInt(moneyInt); } index++; //resets the text fields for new values // moneyField.setText(""); // timeField.setText(""); [COLOR="Red"]reportArea.append("money is at" + " " + tarray[index][1]); reportArea.append(" " + "time is at" + " " + tarray[index][0]);[/COLOR] } catch (Exception e) { JOptionPane.showMessageDialog(this, "Invalid Input in the Money field","ERROR",JOptionPane.ERROR_MESSAGE); return; } } [COLOR="Red"] private void runReportActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String tutorOutPut = Double.toString(tarray[0][0]); String tutorOutput2 = Double.toString(tarray[0][1]); reportArea.append(tutorOutPut + " " + tutorOutput2);[/COLOR] } private void quitActionPerformed(java.awt.event.ActionEvent evt) { // Exit program System.exit(0); }Last edited by drgnfire25; 01-11-2011 at 11:34 PM.
-
Your use of a Scanner that extracts information from System.in together with a GI worries me. Correct me if I'm wrong, but it looks like it should completely freeze your GUI when trying to get input this way. I strongly advise you to get rid of the Scanner object and to get your input in a different way, perhap by having an array of JTextFields or a JTable.
- 01-12-2011, 12:33 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
It seams to work... Im no programmer but it seams to take the input fine it just wont display it.
-
Sorry to be blunt, but it looks completely borked to me. It's hard to say what's going on without compilable runnable code, but you shouldn't mix GUI and console code the way you're doing it. Also, your for loops are quite strange:
Java Code:for (index = 0; index > 0; index++) {
Why have a loop that never runs?
- 01-12-2011, 12:53 AM #5
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Result set not returning values
By karthikeyan_raju in forum Advanced JavaReplies: 5Last Post: 04-14-2011, 05:24 AM -
Returning HexaDecimal Values to an Array???
By stylishkishore in forum Advanced JavaReplies: 5Last Post: 12-18-2009, 08:04 AM -
problem on returning values..
By kulangotski in forum Advanced JavaReplies: 11Last Post: 03-07-2009, 02:13 AM -
[SOLVED] Beginner, need help with Returning Values from Methods
By bobmasta5 in forum New To JavaReplies: 11Last Post: 12-08-2008, 12:29 AM -
Returning array problem.
By Chase in forum New To JavaReplies: 4Last Post: 10-21-2008, 09:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks