Link to home
Start Free TrialLog in
Avatar of prototrumpet
prototrumpetFlag for United States of America

asked on

How to set same action event for array of JButtons

I have a 2D array of JButtons, and a method that I want each JButton to run.  The method's argument is to be the JButton's name.
Rather than make an event for each JButton, is there a way that I can set the same event for each JButton in the array using a for loop or something?  It just seems like there is a better way to do it than to have 30 different actionEvents...
Avatar of for_yan
for_yan
Flag of United States of America image

You ceartinly have one mouseClicked method
and in that you make a loop checkingfrom which button this event is coming
Avatar of Mick Barry

ActionListener listener = new ActionListener() {
   public void actionPerformed(ActionEvent event) {
      myMethod(event.getActionCommand());
   }
});

for (int i=0; i<buttons.length; i++) {
   buttons[i].addActionListener(listener);
}

Open in new window


public void mouseClicked(MouseEvent me){
int btnNumber = -1;

for(int j=0; j<buttons.length; j+=){
if(me.getSource().equals(buton[j])){
btnNumber = j;
break;
}

btnNumber - is index of your button

}

Of course you can have the same for 2-dimensional array of buttons
Avatar of prototrumpet

ASKER

I'm sorry, but I'm still having trouble with this.  I'm attaching my code so you can show me first hand.  I cleaned out my mistakes so you can read it clearly.

The method I want to use is on line 145, and what I am trying to avoid doing begins at line 175.

Thanks for your help, and sorry for any incompetence on my part.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

/*
 * This is a game of Jeopardy that can be used in classroom teaching exercises
 * 
 */

/*
 * JeopardyGUI.java
 *
 * Created on Apr 1, 2011, 1:30:07 PM
 */

/**
 *
 * @author Cliff
 */
public class JeopardyGUI extends javax.swing.JFrame
{
    protected String[][] questions= new String[5][6];
    protected String[][] answers= new String[5][6];
    protected JButton[][] board= new JButton[5][6];
    protected JLabel[] categories=new JLabel[6];
    protected String question = "";
    protected String answer = "";
    
    
    
    /** Creates new form JeopardyGUI */
    public JeopardyGUI()
    {
        initComponents();   
        
        categories[0]=cat0;     //occupying our array with our labels
        categories[1]=cat1;
        categories[2]=cat2;
        categories[3]=cat3;
        categories[4]=cat4;
        categories[5]=cat5;

        board[0][0]=q00;
        board[1][0]=q10;            //occupying our board by columns
        board[2][0]=q20;
        board[3][0]=q30;
        board[4][0]=q40;

        board[0][0].setName("q00");
        board[1][0].setName("q10");     //providing them their names
        board[2][0].setName("q20");
        board[3][0].setName("q30");
        board[4][0].setName("q40");

        board[0][1]=q01;
        board[1][1]=q11;
        board[2][1]=q21;
        board[3][1]=q31;
        board[4][1]=q41;

        board[0][1].setName("q01");
        board[1][1].setName("q11");
        board[2][1].setName("q21");
        board[3][1].setName("q31");
        board[4][1].setName("q41");

        board[0][2]=q02;
        board[1][2]=q12;
        board[2][2]=q22;
        board[3][2]=q32;
        board[4][2]=q42;

        board[0][2].setName("q02");
        board[1][2].setName("q12");
        board[2][2].setName("q22");
        board[3][2].setName("q32");
        board[4][2].setName("q42");

        board[0][3]=q03;
        board[1][3]=q13;
        board[2][3]=q23;
        board[3][3]=q33;
        board[4][3]=q43;

        board[0][3].setName("q03");
        board[1][3].setName("q13");
        board[2][3].setName("q23");
        board[3][3].setName("q33");
        board[4][3].setName("q43");

        board[0][4]=q04;
        board[1][4]=q14;
        board[2][4]=q24;
        board[3][4]=q34;
        board[4][4]=q44;

        board[0][4].setName("q04");
        board[1][4].setName("q14");
        board[2][4].setName("q24");
        board[3][4].setName("q34");
        board[4][4].setName("q44");

        board[0][5]=q05;
        board[1][5]=q15;
        board[2][5]=q25;
        board[3][5]=q35;
        board[4][5]=q45;

        board[0][5].setName("q05");
        board[1][5].setName("q15");
        board[2][5].setName("q25");
        board[3][5].setName("q35");
        board[4][5].setName("q45");

        FileReader fin = null;          //making a file reader to read the 
        try                     //games categories, questions, and answers
        {
            fin = new FileReader("data.txt");
        }
        catch(IOException exception) {};
        Scanner scan = new Scanner(fin);

        for(int i=0;scan.hasNextLine()&&i<6;i++)
        {
            categories[i].setText(scan.nextLine());     //sets Category Labels
        }

        for(int i=0;scan.hasNextLine()&&i<6;i++)
        {
            for(int j=0;scan.hasNextLine()&&j<5;j++)    //getting game data
            {
                questions[j][i]=scan.nextLine();
                answers[j][i]=scan.nextLine();
            }
        }
    }

    public void displayQuestion(JButton buttonName)     //displays the question in a new window and puts the answer into memory
    {
        for(int i=0;i<6;i++)
        {
            for(int j=0;j<5;j++)
            {
                if(buttonName.getName().equals(board[j][i].getName()))
                {
                    question=questions[j][i];
                    answer=answers[j][i];
                    JFrame frame = new JFrame(categories[i].getText()+" for "+board[j][i].getLabel());
                    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                    JLabel label = new JLabel(question);
                    frame.getContentPane().add(label);
                    frame.pack();
                    frame.setVisible(true);
                }
            }
        }
        
    }

    
    
    /** 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        cat0 = new javax.swing.JLabel();
        cat1 = new javax.swing.JLabel();
        cat4 = new javax.swing.JLabel();
        cat3 = new javax.swing.JLabel();
        cat5 = new javax.swing.JLabel();
        q00 = new javax.swing.JButton();
        q01 = new javax.swing.JButton();
        q02 = new javax.swing.JButton();
        q04 = new javax.swing.JButton();
        q05 = new javax.swing.JButton();
        q03 = new javax.swing.JButton();
        q13 = new javax.swing.JButton();
        q14 = new javax.swing.JButton();
        q15 = new javax.swing.JButton();
        q11 = new javax.swing.JButton();
        q12 = new javax.swing.JButton();
        q10 = new javax.swing.JButton();
        q21 = new javax.swing.JButton();
        q20 = new javax.swing.JButton();
        q22 = new javax.swing.JButton();
        q23 = new javax.swing.JButton();
        q25 = new javax.swing.JButton();
        q24 = new javax.swing.JButton();
        q34 = new javax.swing.JButton();
        q30 = new javax.swing.JButton();
        q33 = new javax.swing.JButton();
        q31 = new javax.swing.JButton();
        q32 = new javax.swing.JButton();
        q35 = new javax.swing.JButton();
        q41 = new javax.swing.JButton();
        q43 = new javax.swing.JButton();
        q44 = new javax.swing.JButton();
        q45 = new javax.swing.JButton();
        q42 = new javax.swing.JButton();
        q40 = new javax.swing.JButton();
        cat2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Academic Jeopardy");
        setBackground(new java.awt.Color(0, 0, 0));

        cat0.setBackground(new java.awt.Color(0, 0, 255));
        cat0.setForeground(new java.awt.Color(255, 255, 255));
        cat0.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat0.setText("jLabel1");
        cat0.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat0.setOpaque(true);

        cat1.setBackground(new java.awt.Color(0, 0, 255));
        cat1.setForeground(new java.awt.Color(255, 255, 255));
        cat1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat1.setText("jLabel1");
        cat1.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat1.setOpaque(true);

        cat4.setBackground(new java.awt.Color(0, 0, 255));
        cat4.setForeground(new java.awt.Color(255, 255, 255));
        cat4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat4.setText("jLabel1");
        cat4.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat4.setOpaque(true);

        cat3.setBackground(new java.awt.Color(0, 0, 255));
        cat3.setForeground(new java.awt.Color(255, 255, 255));
        cat3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat3.setText("jLabel1");
        cat3.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat3.setOpaque(true);

        cat5.setBackground(new java.awt.Color(0, 0, 255));
        cat5.setForeground(new java.awt.Color(255, 255, 255));
        cat5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat5.setText("jLabel1");
        cat5.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat5.setOpaque(true);

        q00.setBackground(new java.awt.Color(0, 0, 255));
        q00.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        q00.setForeground(new java.awt.Color(255, 255, 0));
        q00.setText("$200");
        q00.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q00.setOpaque(true);
        q00.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q00ActionPerformed(evt);
            }
        });

        q01.setBackground(new java.awt.Color(0, 0, 255));
        q01.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q01.setForeground(new java.awt.Color(255, 255, 0));
        q01.setText("$200");
        q01.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q01.setOpaque(true);
        q01.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q01ActionPerformed(evt);
            }
        });

        q02.setBackground(new java.awt.Color(0, 0, 255));
        q02.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q02.setForeground(new java.awt.Color(255, 255, 0));
        q02.setText("$200");
        q02.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q02.setOpaque(true);
        q02.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q02ActionPerformed(evt);
            }
        });

        q04.setBackground(new java.awt.Color(0, 0, 255));
        q04.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q04.setForeground(new java.awt.Color(255, 255, 0));
        q04.setText("$200");
        q04.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q04.setOpaque(true);

        q05.setBackground(new java.awt.Color(0, 0, 255));
        q05.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        q05.setForeground(new java.awt.Color(255, 255, 0));
        q05.setText("$200");
        q05.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q05.setOpaque(true);

        q03.setBackground(new java.awt.Color(0, 0, 255));
        q03.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q03.setForeground(new java.awt.Color(255, 255, 0));
        q03.setText("$200");
        q03.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q03.setOpaque(true);
        q03.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q03ActionPerformed(evt);
            }
        });

        q13.setBackground(new java.awt.Color(0, 0, 255));
        q13.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q13.setForeground(new java.awt.Color(255, 255, 0));
        q13.setText("$400");
        q13.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q13.setOpaque(true);
        q13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q13ActionPerformed(evt);
            }
        });

        q14.setBackground(new java.awt.Color(0, 0, 255));
        q14.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q14.setForeground(new java.awt.Color(255, 255, 0));
        q14.setText("$400");
        q14.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q14.setOpaque(true);

        q15.setBackground(new java.awt.Color(0, 0, 255));
        q15.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q15.setForeground(new java.awt.Color(255, 255, 0));
        q15.setText("$400");
        q15.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q15.setOpaque(true);

        q11.setBackground(new java.awt.Color(0, 0, 255));
        q11.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q11.setForeground(new java.awt.Color(255, 255, 0));
        q11.setText("$400");
        q11.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q11.setOpaque(true);
        q11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q11ActionPerformed(evt);
            }
        });

        q12.setBackground(new java.awt.Color(0, 0, 255));
        q12.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q12.setForeground(new java.awt.Color(255, 255, 0));
        q12.setText("$400");
        q12.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q12.setOpaque(true);
        q12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q12ActionPerformed(evt);
            }
        });

        q10.setBackground(new java.awt.Color(0, 0, 255));
        q10.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q10.setForeground(new java.awt.Color(255, 255, 0));
        q10.setText("$400");
        q10.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q10.setOpaque(true);
        q10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q10ActionPerformed(evt);
            }
        });

        q21.setBackground(new java.awt.Color(0, 0, 255));
        q21.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q21.setForeground(new java.awt.Color(255, 255, 0));
        q21.setText("$600");
        q21.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q21.setOpaque(true);
        q21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q21ActionPerformed(evt);
            }
        });

        q20.setBackground(new java.awt.Color(0, 0, 255));
        q20.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q20.setForeground(new java.awt.Color(255, 255, 0));
        q20.setText("$600");
        q20.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q20.setOpaque(true);
        q20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q20ActionPerformed(evt);
            }
        });

        q22.setBackground(new java.awt.Color(0, 0, 255));
        q22.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q22.setForeground(new java.awt.Color(255, 255, 0));
        q22.setText("$600");
        q22.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q22.setOpaque(true);
        q22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q22ActionPerformed(evt);
            }
        });

        q23.setBackground(new java.awt.Color(0, 0, 255));
        q23.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q23.setForeground(new java.awt.Color(255, 255, 0));
        q23.setText("$600");
        q23.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q23.setOpaque(true);

        q25.setBackground(new java.awt.Color(0, 0, 255));
        q25.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q25.setForeground(new java.awt.Color(255, 255, 0));
        q25.setText("$600");
        q25.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q25.setOpaque(true);

        q24.setBackground(new java.awt.Color(0, 0, 255));
        q24.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q24.setForeground(new java.awt.Color(255, 255, 0));
        q24.setText("$600");
        q24.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q24.setOpaque(true);

        q34.setBackground(new java.awt.Color(0, 0, 255));
        q34.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q34.setForeground(new java.awt.Color(255, 255, 0));
        q34.setText("$800");
        q34.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q34.setOpaque(true);

        q30.setBackground(new java.awt.Color(0, 0, 255));
        q30.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q30.setForeground(new java.awt.Color(255, 255, 0));
        q30.setText("$800");
        q30.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q30.setOpaque(true);
        q30.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q30ActionPerformed(evt);
            }
        });

        q33.setBackground(new java.awt.Color(0, 0, 255));
        q33.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q33.setForeground(new java.awt.Color(255, 255, 0));
        q33.setText("$800");
        q33.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q33.setOpaque(true);

        q31.setBackground(new java.awt.Color(0, 0, 255));
        q31.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q31.setForeground(new java.awt.Color(255, 255, 0));
        q31.setText("$800");
        q31.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q31.setOpaque(true);
        q31.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q31ActionPerformed(evt);
            }
        });

        q32.setBackground(new java.awt.Color(0, 0, 255));
        q32.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q32.setForeground(new java.awt.Color(255, 255, 0));
        q32.setText("$800");
        q32.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q32.setOpaque(true);
        q32.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q32ActionPerformed(evt);
            }
        });

        q35.setBackground(new java.awt.Color(0, 0, 255));
        q35.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q35.setForeground(new java.awt.Color(255, 255, 0));
        q35.setText("$800");
        q35.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q35.setOpaque(true);

        q41.setBackground(new java.awt.Color(0, 0, 255));
        q41.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q41.setForeground(new java.awt.Color(255, 255, 0));
        q41.setText("$1000");
        q41.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q41.setOpaque(true);
        q41.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q41ActionPerformed(evt);
            }
        });

        q43.setBackground(new java.awt.Color(0, 0, 255));
        q43.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q43.setForeground(new java.awt.Color(255, 255, 0));
        q43.setText("$1000");
        q43.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q43.setOpaque(true);

        q44.setBackground(new java.awt.Color(0, 0, 255));
        q44.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q44.setForeground(new java.awt.Color(255, 255, 0));
        q44.setText("$1000");
        q44.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q44.setOpaque(true);

        q45.setBackground(new java.awt.Color(0, 0, 255));
        q45.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        q45.setForeground(new java.awt.Color(255, 255, 0));
        q45.setText("$1000");
        q45.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q45.setOpaque(true);

        q42.setBackground(new java.awt.Color(0, 0, 255));
        q42.setFont(new java.awt.Font("Lucida Grande", 0, 36));
        q42.setForeground(new java.awt.Color(255, 255, 0));
        q42.setText("$1000");
        q42.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q42.setOpaque(true);
        q42.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q42ActionPerformed(evt);
            }
        });

        q40.setBackground(new java.awt.Color(0, 0, 255));
        q40.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        q40.setForeground(new java.awt.Color(255, 255, 0));
        q40.setText("$1000");
        q40.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        q40.setOpaque(true);
        q40.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                q40ActionPerformed(evt);
            }
        });

        cat2.setBackground(new java.awt.Color(0, 0, 255));
        cat2.setForeground(new java.awt.Color(255, 255, 255));
        cat2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        cat2.setText("jLabel1");
        cat2.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        cat2.setOpaque(true);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(cat0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cat1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cat2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cat3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cat4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(8, 8, 8))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(q00, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q20, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q30, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q40, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                        .add(9, 9, 9)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(q21, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q31, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q41, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q01, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(6, 6, 6)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(layout.createSequentialGroup()
                                .add(2, 2, 2)
                                .add(q12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(2, 2, 2)
                                .add(q02, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(2, 2, 2)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(q22, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                    .add(q32, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                    .add(q42, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(q43, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q33, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q23, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(q03, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                        .add(8, 8, 8)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(q44, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q34, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q24, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .add(q04, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(9, 9, 9)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(cat5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, q45, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, q35, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, q25, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, q15, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .add(q05, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(24, 24, 24))
        );

        layout.linkSize(new java.awt.Component[] {cat0, cat1, cat2, cat3, cat4, cat5, q00, q01, q02, q03, q04, q05, q10, q11, q12, q13, q14, q15, q20, q21, q22, q23, q24, q25, q30, q31, q32, q33, q34, q35, q40, q41, q42, q43, q44, q45}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(cat0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(cat1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(cat3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(cat4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(cat5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .add(7, 7, 7)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(q04, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q24, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q34, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q44, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(q05, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q15, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q25, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q35, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q45, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(q03, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .add(4, 4, 4)
                                .add(q13, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q23, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q33, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q43, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(q01, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .add(4, 4, 4)
                                .add(q11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q21, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q31, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(q41, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(layout.createSequentialGroup()
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 84, Short.MAX_VALUE)
                                    .add(q10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(q20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(q30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(q40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
                                        .add(q02, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(q00, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 4, Short.MAX_VALUE)
                                    .add(q12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(252, 252, 252)))))
                    .add(layout.createSequentialGroup()
                        .add(cat2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 175, Short.MAX_VALUE)
                        .add(q22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(q32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(q42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(81, 81, 81))
        );

        layout.linkSize(new java.awt.Component[] {cat0, cat1, cat2, cat3, cat4, cat5, q00, q01, q02, q03, q04, q05, q10, q11, q12, q13, q14, q15, q20, q21, q22, q23, q24, q25, q30, q31, q32, q33, q34, q35, q40, q41, q42, q43, q44, q45}, org.jdesktop.layout.GroupLayout.VERTICAL);

        pack();
    }// </editor-fold>

    private void q00ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q00);
    }

    private void q10ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q10);
    }

    private void q20ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q20);
    }

    private void q30ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q30);
    }

    private void q40ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q40);
    }

    private void q01ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q01);
    }

    private void q11ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q11);
    }

    private void q21ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q21);
    }

    private void q31ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q31);
    }

    private void q41ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q41);
    }

    private void q02ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q02);
    }

    private void q12ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q12);
    }

    private void q22ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q22);
    }

    private void q32ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q32);
    }

    private void q42ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q42);
    }

    private void q03ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q03);
    }

    private void q13ActionPerformed(java.awt.event.ActionEvent evt) {
        displayQuestion(q13);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new JeopardyGUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel cat0;
    private javax.swing.JLabel cat1;
    private javax.swing.JLabel cat2;
    private javax.swing.JLabel cat3;
    private javax.swing.JLabel cat4;
    private javax.swing.JLabel cat5;
    private javax.swing.JButton q00;
    private javax.swing.JButton q01;
    private javax.swing.JButton q02;
    private javax.swing.JButton q03;
    private javax.swing.JButton q04;
    private javax.swing.JButton q05;
    private javax.swing.JButton q10;
    private javax.swing.JButton q11;
    private javax.swing.JButton q12;
    private javax.swing.JButton q13;
    private javax.swing.JButton q14;
    private javax.swing.JButton q15;
    private javax.swing.JButton q20;
    private javax.swing.JButton q21;
    private javax.swing.JButton q22;
    private javax.swing.JButton q23;
    private javax.swing.JButton q24;
    private javax.swing.JButton q25;
    private javax.swing.JButton q30;
    private javax.swing.JButton q31;
    private javax.swing.JButton q32;
    private javax.swing.JButton q33;
    private javax.swing.JButton q34;
    private javax.swing.JButton q35;
    private javax.swing.JButton q40;
    private javax.swing.JButton q41;
    private javax.swing.JButton q42;
    private javax.swing.JButton q43;
    private javax.swing.JButton q44;
    private javax.swing.JButton q45;
    // End of variables declaration

}

Open in new window

I'm sorry I meant that the part I want to avoid doing is on line 726.  I need to wear my glasses more often...
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked great!  Thanks!