title: Count occurrences of all 256 characters (GUI/Arrays)
body: <p>I need help tweaking my code. I need to write a program that outputs the count of individual ascii characters in a txt file that the user uploads, but I'm having a lot of problems trying to get the array that I count into the GUI portion of the program that "draws" the data on the screen. 
  I have the output looking how I want, but I can't figure out how to get the character count up there</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  
  import javax.swing.*;
  
  import java.io.FileReader;      // both needed
  import java.io.BufferedReader;
  import java.io.IOException;
  
  
  public class textreader extends Frame implements ActionListener
  {
  String dataFilePath = null;
  String dataFileName = null;
  int[] counter = new int[256];
  
  String command = "";
  
  public static void main(String[] args)
  {
      Frame frame = new textreader();
      frame.setResizable(true);
      frame.setSize(1000,850);
      frame.setVisible(true);
  }
  
   public textreader()
  {
       setTitle("Text File Processing");
  
      // Menu Creation
       MenuBar mn = new MenuBar();
      setMenuBar(mn);
  
      // Create "File" and add it
      Menu fileMenu = new Menu("File");
       mn.add(fileMenu);
  
      // Create Menu Items, Add action Listener, Add to "File" Menu Group
  
      // Open file
      MenuItem miOpen = new MenuItem("Open");
      miOpen.addActionListener(this);
      fileMenu.add(miOpen);
  
      // Process file
      MenuItem miProcess = new MenuItem("Process");
      miProcess.addActionListener(this);
      fileMenu.add(miProcess);
  
      // Exit program
      MenuItem miExit = new MenuItem("Exit");
      miExit.addActionListener(this);
      fileMenu.add(miExit);
  
      // To Terminate
      WindowListener d = new WindowAdapter()
      {
          public void windowClosing(WindowEvent ev)
          {
              System.exit(0);
          }
  
          public void windowActivated(WindowEvent ev)
          {
              repaint();
          }
  
          public void windowStateChanged(WindowEvent ev)
          {
              repaint();
          }
      };
  
      ComponentListener k = new ComponentAdapter()
      {
          public void componentResized(ComponentEvent e) 
          {
              repaint();           
          }
      };
  
      // listener registry
      this.addWindowListener(d);
      this.addComponentListener(k);
  }
  
  public void actionPerformed (ActionEvent ev)
  {
  // which command was issued?
  command = ev.getActionCommand();
  
  // act          
  if("Open".equals(command))
  {
      dataFilePath = null;
      dataFileName = null;
  
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogType(JFileChooser.OPEN_DIALOG );
        chooser.setDialogTitle("Open Data File");
  
        int returnVal = chooser.showOpenDialog(null);
        if( returnVal == JFileChooser.APPROVE_OPTION) 
          {
            dataFilePath = chooser.getSelectedFile().getPath();
            dataFileName = chooser.getSelectedFile().getName();
          }
      repaint();
  }
  else
      if("Process".equals(command))
      {
          try 
          {   
              // Initialize
              int[] aCount = new int[256];
  
              // "Instantiate" streams
              BufferedReader inputStream  = new BufferedReader(new FileReader(dataFilePath));
  
              // read the file line by line and count the characters read
  
              String line = null;
              char c = 0;
              int lineLength = 0;
              int charValue = 0;
  
              while ((line = inputStream.readLine()) != null)
              {
              // *********  process line
                  for (int i = 0; i &lt; line.length(); i++)
                  {
                      char ch = line.charAt(i);
  
                      if (ch &gt;= 0 &amp;&amp; ch &lt;= 255)
                      {
                          counter[(int)ch]++;
                      }
                      else
                      {    // silently ignore non-ASCII characters
                      }
                      // count newline at the end
                      counter['\n']++;
                      }
                  }
          }
  
          catch(IOException ioe)
          {
              System.out.print("You want to run that by me again?"); 
          }
  
          repaint();
      }
  else
      if("Exit".equals(command))
      {
          System.exit(0);
      }
  
  }
  //********************************************************
  //called by repaint() to redraw the screen
  //********************************************************
  
  public void paint(Graphics g)
  {               
  if("Open".equals(command))
  {
      // Acknowledge that file was opened
      if (dataFileName != null)
      {
          g.drawString("File --  "+dataFileName+"  -- was successfully opened", 400, 400);
      }
      else
      {
          g.drawString("NO File is Open", 400, 400);
      }
  
      return; 
  }
  else
  if("Process".equals(command))
      {
          for(int i = 0; i &lt; 256; i++)
          {
               int x = 100;
               int y = 100;
  
               g.drawString("Int", x, y);
               g.drawString("Char", x+50, y);
               g.drawString("Count", x+100, y);
               g.drawLine(100, y+15, x+120, y+15);
  
               y = y + 30;
  
               int line = 0;
  
              for(int j = 0; j &lt; 256; j++)
              {
                   line++;
                   g.drawString(Integer.toString(j), x, y);
                  g.drawString(Character.toString((char)j), x + 50, y);   // Converts the # to a char, then to a String
  
                  // This part of the code adds a new column when    the flag reaches 43
  
                  if(line == 45)
                   {
                      x = x + 150;
                       y = 100;
                      g.drawString("Int", x, y);
                      g.drawString("Char", x+50, y);
                      g.drawString("Count", x+100, y);
                      g.drawLine(100, y+15, x+120, y+15);
                      y = y + 15;
                      line = 0;
                      }
                  y = y+15;
                  }
  
          }
          return; 
      }
  
      }
  }
  </code></pre>