View Single Post
  #3 (permalink)  
Old 05-24-2008, 05:25 AM
kewlgeye kewlgeye is offline
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
Writing a countdown array to a file
Ok I thought I did the right thing, but apparently not. If you could have a look and maybe see what I have done. Here is the code, and then the new error that I am receiving.

Code:
import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import java.io.*; import javax.swing.JOptionPane; public class AnArrayTest{ Scanner console = new Scanner(System.in); JFrame frame; public AnArrayTest() { frame = new JFrame("Array"); JButton button = new JButton("Enter Here"); button.addActionListener(new MyAction()); JPanel panel = new JPanel(); panel.add(button); frame.add(panel); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public class MyAction implements ActionListener{ public void actionPerformed(ActionEvent e){ PrintWriter outFile; try { outFile = new PrintWriter ("C:\\Users\\Philip\\Desktop\\JavaProgramming\\GUI Array\\program.txt"); String input = JOptionPane.showInputDialog(null, "Enter the size of the array: "); int arraySize = Integer.parseInt(input.trim()); int[] list = new int[arraySize]; for (int i = 0; i < list.length; i++) { list[i] = i+1; } String values = ""; for(int i = 0; i < list.length; i++) { values += list[i]; if(i < list.length-1) values += ", "; if((i + 1) % 40 == 0) values += "\n"; } JOptionPane.showMessageDialog(frame, values + " " + "are your numbers", "Your Silly Numbers", JOptionPane.INFORMATION_MESSAGE); outFile.print(values + " " + "are your numbers"); } catch (FileNotFoundException e1) { JOptionPane.showMessageDialog(null, "" + e1.getMessage() + " File Not Found ", "Invalid Input", JOptionPane.INFORMATION_MESSAGE); } outFile.close(); } } public static void main(String[] args){ new AnArrayTest(); } }
the error pic is at the bottom
Attached Images
File Type: jpg error.jpg (48.3 KB, 1 views)
Reply With Quote