title: Global Variable in buttons
body: <p>How do I make the exit button a global variable? I am making a gui for my teacher for a grade and I have to make it 'global' so the jframe can get to it. Here is the code:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.event.ActionListener;
  import java.awt.event.*;
  import java.awt.*;
  
  
  
  public class StudentGUI extends JFrame implements ActionListener {
      public StudentGUI()
      {
      super("StudentGUI Frame");
  
  
  
        //TopPanel
       TopPanel tp;
       tp=new TopPanel();
  
       Dimension d = new Dimension(800,600);
       tp.setPreferredSize(d);
       this.add (tp, BorderLayout.NORTH);
       tp.setVisible(true);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.setSize(800,600);
          setBackground(Color.PINK);
  
          tp.setVisible(true);
  
          //TopPanel End
  
  
          //BottomPanel
          BottomPanel bp;
       bp=new BottomPanel();
  
  
       this.add (bp, BorderLayout.SOUTH);
       tp.setVisible(true);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.setSize(800,600);
  
          exitBtn.addActionListener(this);
  
          //BottomPanel End
  
          //MiddlePanel 
  
      MiddlePanel mp;
       mp=new MiddlePanel();
  
  
       this.add (mp, BorderLayout.CENTER);
       mp.setVisible(true);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.setSize(800,600);
  
          //MiddlePanel End
  
          this.setVisible(true);
      }
  
      public void actionPerformed(ActionEvent e){
  
  
  int selectedOption = JOptionPane.showConfirmDialog(null, 
                                    "Do you want to close the window?", 
                                    "Choose", 
                                    JOptionPane.YES_NO_OPTION); 
  if (selectedOption == JOptionPane.YES_OPTION) {
      System.exit(0);
  
  
  //ExitBtn.addActionListener(this);
  
  }
  }
      public static void main(String[] args)
      {
          new StudentGUI();
      }
  
  
  }
  </code></pre>
  
  <p>Now that is the frame. Here is the panel that is having the problem to get the exit button to do the action performed. </p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionListener;
  import java.awt.event.*;
  
  public class BottomPanel extends JPanel {
  
  public String findbtn="";
  public String insertBtn="";
  public String updateBtn="";
  public String deleteBtn="";
  Button exitBtn;
  
  public BottomPanel() {
     JButton findbtn;
       findbtn=new JButton("Find");
          add(findbtn);
  
             JButton insertBtn;
       insertBtn=new JButton("Insert");
          add(insertBtn);
  
             JButton updateBtn;
       updateBtn=new JButton("Update");
          add(updateBtn);
  
             JButton deleteBtn;
       deleteBtn=new JButton("Delete");
          add(deleteBtn);
  
          JButton exitBtn;
       exitBtn=new JButton("Exit");
          add(exitBtn);
  
  
  
  }
  }
  </code></pre>
  
  <p>Help!</p>