views:

11

answers:

2

This is what I currently have but its not not showing the results in two textareas.. Right now all it shows is one textarea with Odd numbers only. I'm not sure why the even numbers wont show. Any help is appreciated Thanks!

static TextFileInput inFile;
   static String inFileName = "lab12.txt";
   static JFrame myFrame;
   static Container cPane;
   static TextArea even, odd;

   public static void main(String[] args) {
      initialize();
      readNumbersFromFile(inFileName);

   }   
   public static void initialize() {
      inFile = new TextFileInput(inFileName);
      even = new TextArea();
      odd = new TextArea();
      myFrame=new JFrame();
      myFrame.setSize(400,400);
      myFrame.setLocation(200, 200);
      myFrame.setTitle("test");
      myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      myFrame.setVisible(true);
   }
   public static void readNumbersFromFile(String fileName){
        String[] num = new String[20];
        String line;
          line = inFile.readLine();
          for(int i = 0; i < inFile.getLineCount(); i++){
                num[i] = line;
                line = inFile.readLine();
                }


       cPane = myFrame.getContentPane();

       cPane.add(even);
       cPane.add(odd);
       for(int i = 0; i < inFile.getLineCount(); i++){
           if(Integer.parseInt(num[i]) % 2 == 0)
                even.append(num[i] + "\n");
           else
                odd.append(num[i] + "\n");
       }//for

        myFrame.setVisible(true);


   }//readSSNsFromFile
A: 

It is better you build the panel and division the panel by the row and column and add this panel on the frame.

doe23
The top was given.. I am suppose to fill in the readNumberfromfile method only..
eNetik
A: 

'cPane' will have a BorderLayout by default. Adding components to a BorderLayout with no constraints will result in the component being put in the CENTER constraint. Any area of a BorderLayout can only accommodate one component.

A better general approach is to instantiate a JPanel with an appropriate layout, add the components to the JPanel, then either add that JPanel to the content pane, or set it as the content pane.

Andrew Thompson