title: GUI not showing up initially (netbeans)
body: <p>I'm very new to Java and even newer to NetBeans.. I just cannot figure out how to fix this issue.. </p>
  
  <p>When I run my project the GUI initially doesn't show up. There should be a menu bar with a drop down for opening and saving a file, and exiting the program. There should also be three buttons towards the bottom of the window which can be used to display the data within the file (images in this case). But instead, the window is blank when you run the program, nothing shows at all.</p>
  
  <p>When I click on the top left hand corner, where 'File' resides on the menu bar.. then it shows up and the top button shows at this point too. The second two buttons should be greyed out and only become click-able after you've clicked the first button and displayed the first image.</p>
  
  <p>I've tried searching for a solution, and fiddling with the NetBeans settings but can't seem to solve this. I'm assuming it's something to do with stuff being incorrectly placed in the foreground or background but I'm unsure.</p>
  
  <p>Also, I've discovered that if I remove the drawImage bit of code ((public void paint (Graphics g) {g.drawImage(imageToPaint, 50, 70, this);}) then the GUI shows up so I'm guessing this is conflicting with something.. somewhere?!</p>
  
  <p>Thanks in advance if anyone can shed some light on this!</p>
  
  <pre><code>package final_project;
  
  import java.awt.*;
  import java.awt.event.*;
  import java.awt.image.MemoryImageSource;
  import java.util.*;
  import javax.swing.*;
  import javax.swing.filechooser.FileFilter;
  import javax.swing.filechooser.FileNameExtensionFilter;
  
  
  public abstract class Analyst extends javax.swing.JFrame 
    implements ActionListener {
  
  double heights[][] = new double [300][300];
  double grads[][] = new double [300][300];
  double tempg[] = new double [8];
  double wgrads[][] = new double [300][300];
  
  Image imageToPaint;
  
  public boolean shouldcolourheights = false;
  
  int blue = 1;
  int green = 1;
  int red = 1;
  
  public Analyst() {
      initComponents();
  }
  
  public double [][] convertFromString(String[] stArray){
      double[][] data = new double [300][300];
      int lines = stArray.length;
      for (int i = 0; i&lt;lines; i++){
          StringTokenizer st = new StringTokenizer(stArray[i]," ");
          int j=0;
          while (st.hasMoreTokens()){
              data[i][j]=Double.parseDouble(st.nextToken());
              j++;
          }
      }
      return data;
  }
  
  
  double[] get1DArray (double[][] twoDarray) { 
      double[] tempArray = new double[twoDarray.length * twoDarray[0].length]; 
      for (int i = 0; i &lt; twoDarray.length; i++) {
          for (int j = 0; j &lt; twoDarray[i].length; j++) {
              tempArray[(i * twoDarray[0].length) + j] = twoDarray[i][j];
          }
      }
      return tempArray;
  }
  
  public double getMaxGrad (int bound){
      double maxgrad = 0.0;
      for (int k=0; k&lt;bound; k++){
          if (tempg[k]&gt;maxgrad){
              maxgrad=tempg[k];
          }
      }
      return maxgrad;
  }
  
  
  public Image getImage (double [][] array) {
      int arrayW = array[0].length;
      int [] pixels = new int [array.length * arrayW];
      double [] oneDim = get1DArray(array);
      for (int i = 0; i &lt; pixels.length; i++) {
          int value = (int) oneDim[i];
          if (value &gt; 255){
              value = 255;
          }
          if (shouldcolourheights){
              int newi = (int) Math.floor(i/300);
              int newj = (int) i-(newi*300);
              if (grads[newi][newj] &lt; 1.0){
                  blue=1; green=1; red=1;
              } else if (grads[newi][newj] &lt;=1.5) {
                  blue=0; red=0; green=1;
              } else if (grads[newi][newj] &lt;=3.0) {
                  blue=1; red=0; green=0;
              } else {blue=0; red=1; green=0;}
          }
          Color pixel;
          pixel = new Color(value * red, value * green, value * blue, 255);   
          pixels[i] = pixel.getRGB();       
      }
      MemoryImageSource memImage = new MemoryImageSource(arrayW,arrayW,pixels,0,arrayW);
      Panel p = new Panel();
      Image image = p.createImage(memImage);
      return image;
  }
  
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      fc = new javax.swing.JFileChooser();
      btnHeights = new javax.swing.JButton();
      btnGradients = new javax.swing.JButton();
      btnColourH = new javax.swing.JButton();
      jMenuBar = new javax.swing.JMenuBar();
      jMenu = new javax.swing.JMenu();
      jMenuOpen = new javax.swing.JMenuItem();
      jMenuSave = new javax.swing.JMenuItem();
      jSeparator = new javax.swing.JPopupMenu.Separator();
      jMenuExit = new javax.swing.JMenuItem();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      btnHeights.setText("Heights");
      btnHeights.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              btnHeightsActionPerformed(evt);
          }
      });
  
      btnGradients.setText("Gradients");
      btnGradients.setEnabled(false);
      btnGradients.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              btnGradientsActionPerformed(evt);
          }
      });
  
      btnColourH.setText("Colour Heights");
      btnColourH.setEnabled(false);
      btnColourH.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              btnColourHActionPerformed(evt);
          }
      });
  
      jMenu.setText("File");
  
      jMenuOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
      jMenuOpen.setText("Open");
      jMenuOpen.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuOpenActionPerformed(evt);
          }
      });
      jMenu.add(jMenuOpen);
  
      jMenuSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
      jMenuSave.setText("Save");
      jMenuSave.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuSaveActionPerformed(evt);
          }
      });
      jMenu.add(jMenuSave);
      jMenu.add(jSeparator);
  
      jMenuExit.setText("Exit");
      jMenuExit.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuExitActionPerformed(evt);
          }
      });
      jMenu.add(jMenuExit);
  
      jMenuBar.add(jMenu);
  
      setJMenuBar(jMenuBar);
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(39, 39, 39)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(btnColourH, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(btnGradients, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(btnHeights, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              .addContainerGap(258, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
              .addContainerGap(381, Short.MAX_VALUE)
              .addComponent(btnHeights)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addComponent(btnGradients)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addComponent(btnColourH)
              .addGap(27, 27, 27))
      );
  
      pack();
  }// &lt;/editor-fold&gt;                        
  
  private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {                                          
      FileFilter ft = new FileNameExtensionFilter("Text Files", "txt");
      fc.addChoosableFileFilter(ft);
      int returnVal = fc.showOpenDialog(this);
      if (returnVal==javax.swing.JFileChooser.APPROVE_OPTION) {
          java.io.File file = fc.getSelectedFile();
          String file_name = file.toString();
          try {
              ReadFile file_read = new ReadFile(file_name);
              String [] arraylines = file_read.OpenFile();
              heights = convertFromString(arraylines);
              }
          catch (java.io.IOException e) {
             JOptionPane.showMessageDialog(Analyst.this, "File does not exist");
              }
      }
  }                                         
  
  private void jMenuSaveActionPerformed(java.awt.event.ActionEvent evt) {                                          
      String tempStr = "";
      FileFilter ft = new FileNameExtensionFilter("Text Files", "txt");
      fc.addChoosableFileFilter(ft);
      int returnVal = fc.showSaveDialog(this);
      if (returnVal==javax.swing.JFileChooser.APPROVE_OPTION) {
          java.io.File saved_file = fc.getSelectedFile();
          String file_name = saved_file.toString();
          try {
              WriteFile dataOut = new WriteFile(file_name, true);
              for (int i=0; i&lt;grads.length; i++) {
                  for (int j=0; j&lt;grads[i].length; j++){
                      double rgrad = Math.floor(grads[i][j] * 10) / 10;
                      tempStr = tempStr + String.valueOf(rgrad) +" ";
                  }
                  dataOut.writeToFile(tempStr);
                  tempStr = "";
              }
          }
          catch (java.io.IOException e) {
             JOptionPane.showMessageDialog(Analyst.this, "File not written");
              }
      }
      repaint();
  }                                         
  
  private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {                                          
      System.exit(0);
  }                                         
  
  
  private void btnHeightsActionPerformed(java.awt.event.ActionEvent evt) {                                           
      shouldcolourheights=false;
      red=1; blue=1; green=1;
      imageToPaint = getImage(heights);
      repaint();
      btnGradients.setEnabled(true);
  }                                          
  
  private void btnGradientsActionPerformed(java.awt.event.ActionEvent evt) {                                             
      double root2 = Math.sqrt(2.0);
      double scaling = 1.0;                  //cells of 1m assumed
      double weighting = 40.0;               //to give more defined image
      //The 8 neighbour cells
      for (int i=1; i&lt;299; i++) {
          for (int j=1; j&lt;299; j++){
            tempg[0] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
            tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
            tempg[2] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
            tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
            tempg[4] = Math.abs(heights[i][j-1]-heights[i][j]);
            tempg[5] = Math.abs(heights[i-1][j]-heights[i][j]);
            tempg[6] = Math.abs(heights[i][j+1]-heights[i][j]);
            tempg[7] = Math.abs(heights[i+1][j]-heights[i][j]);
            grads[i][j] = getMaxGrad(8)/scaling;
          }
      }
      //The 5 neighbour cells
      int i=0;
      for (int j=1; j&lt;299; j++) {
  
          tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
          tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
          tempg[2] = Math.abs(heights[i+1][j]-heights[i][j]);
          tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
          tempg[4] = Math.abs(heights[i][j+1]-heights[i][j]);                   
          grads[i][j] = getMaxGrad(5)/scaling;     
      } 
      i=299;
      for (int j=1; j&lt;299; j++){
  
          tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
          tempg[1] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
          tempg[2] = Math.abs(heights[i-1][j]-heights[i][j]);
          tempg[3] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
          tempg[4] = Math.abs(heights[i][j+1]-heights[i][j]);
          grads[i][j] = getMaxGrad(5)/scaling;
      }
      int j=0;
      for (i=1; i&lt;299; i++){
          tempg[0] = Math.abs(heights[i-1][j]-heights[i][j]);
          tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
          tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
          tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
          tempg[4] = Math.abs(heights[i+1][j]-heights[i][j]);
          grads[i][j] = getMaxGrad(5)/scaling;
      }   
      j=299;
      for (i=1; i&lt;299; i++){
          tempg[0] = Math.abs(heights[i+1][j]-heights[i][j]);
          tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
          tempg[2] = Math.abs(heights[i][j-1]-heights[i][j]);
          tempg[3] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
          tempg[4] = Math.abs(heights[i-1][j]-heights[i][j]);
          grads[i][j] = getMaxGrad(5)/scaling;
      }   
      //The 3 neighbour cells
      i=0; j=0;
      tempg[0] = Math.abs(heights[i+1][j]-heights[i][j]);
      tempg[1] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
      tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
  
      grads[i][j] = getMaxGrad(3)/scaling;
  
      i=299; j=0;
      tempg[0] = Math.abs(heights[i-1][j]-heights[i][j]);
      tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
      tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
  
      grads[i][j] = getMaxGrad(3)/scaling;
  
      i=0; j=299;
      tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
      tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
      tempg[2] = Math.abs(heights[i+1][j]-heights[i][j]);
  
      grads[i][j] = getMaxGrad(3)/scaling;
  
      i=299; j=299;
      tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
      tempg[1] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
      tempg[2] = Math.abs(heights[i-1][j]-heights[i][j]);
  
      grads[i][j] = getMaxGrad(3)/scaling;
      //grads holds the actual 'D8' gradients and is to be written to
      //a file.  In order to display greyscale image the values need to be
      //weighted up (grads is left unchanged).
      //
      for (i=0; i&lt;300; i++) {
          for (j=0; j&lt;300; j++){
              wgrads[i][j] = grads[i][j] * weighting;
          }     
      }
      shouldcolourheights=false;
      red=1; blue=1; green=1;
      imageToPaint = getImage(wgrads);
  
      repaint();
      jMenuSave.setEnabled(true);
      btnColourH.setEnabled(true);
  }                                            
  
  public void paint (Graphics g) {
          g.drawImage(imageToPaint, 50, 70, this);
  }
  
   /**
   * Redraws the height image with colour to represent the gradients.
   * @param evt 
   */
  private void btnColourHActionPerformed(java.awt.event.ActionEvent evt) {                                           
      shouldcolourheights=true;
      imageToPaint = getImage(heights);
      repaint();
  }                                          
  
  
  
  /**
   * @param args the command line arguments
   */
   public static void main(String args[]) {
      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              new Analyst() {
  
                  public void actionPerformed(ActionEvent e) {
                      throw new UnsupportedOperationException("Not supported yet.");
                  } 
              } .setVisible(true);
          } 
      });
  }
  
  // Variables declaration - do not modify                     
  private javax.swing.JButton btnColourH;
  private javax.swing.JButton btnGradients;
  private javax.swing.JButton btnHeights;
  private javax.swing.JFileChooser fc;
  private javax.swing.JMenu jMenu;
  private javax.swing.JMenuBar jMenuBar;
  private javax.swing.JMenuItem jMenuExit;
  private javax.swing.JMenuItem jMenuOpen;
  private javax.swing.JMenuItem jMenuSave;
  private javax.swing.JPopupMenu.Separator jSeparator;
  // End of variables declaration                   
  }
  </code></pre>