GUI Help

I'm working on a GUI for my high school computer science class. In the code, I have told the score variable to update if a particular event happens. For some reason the score doesn't update. Please help me fix this problem. Thanks.

import java.awt.*; //import statements

import java.awt.event.*;

import javax.swing.* ;

import java.io.*; //Used to import info

import javax.swing.event.* ;

public class Jeopardy extends JFrame implements ActionListener //class declaration

{

JPanel textPanel1, textPanel2, textPanel3, textPanel4, textPanel5, textPanel6, textPanel7, textPanel8, textPanel9, textPanel10, textPanel11, textPanel12;//variable declaration

int score=0;

//button declaration

JButton Box1a = new JButton("$400");//1 refers to column and a refers to position of box

JButton Box1b = new JButton("$800");

JButton Box1c = new JButton("$1200");

JButton Box1d = new JButton("$1600");

JButton Box1e = new JButton("$2000");

JButton Box2a = new JButton("$400");

JButton Box2b = new JButton("$800");

JButton Box2c = new JButton("$1200");

JButton Box2d = new JButton("$1600");

JButton Box2e = new JButton("$2000");

JButton Box3a = new JButton("$400");

JButton Box3b = new JButton("$800");

JButton Box3c = new JButton("$1200");

JButton Box3d = new JButton("$1600");

JButton Box3e = new JButton("$2000");

JButton Enter = new JButton("Complete");

protected CardLayout layout;

//inText field and inLabel declarations

JLabel inLabel1 = new JLabel("American History");

JLabel inLabel2 = new JLabel(" "+"Calculus");

JLabel inLabel3 = new JLabel("Computer Science");

//outText field and inLabel declarations

JLabel outLabel2 = new JLabel("What is your name?");

JTextField outText2 = new JTextField( 7 );

JLabel outLabel = new JLabel("'s score");

JTextField outText = new JTextField( 7 );

//creating questions & answer boxes

JLabel ahistQ1 = new JLabel("He was the first President of the United States.");

JTextField ahistA1 = new JTextField( 7 );

Jeopardy() //constructor

{

Box1a.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));//the changing of the font

Box1b.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box1c.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box1d.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box1e.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box2a.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box2b.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box2c.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box2e.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box3a.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box3b.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box3c.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box3d.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

Box3e.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));

inLabel1.setFont(new Font("Comic Sans MS", Font.BOLD, 14));

inLabel2.setFont(new Font("Comic Sans MS", Font.BOLD, 14));

inLabel3.setFont(new Font("Comic Sans MS", Font.BOLD, 14));

ahistQ1.setFont(new Font("Comic Sans MS", Font.BOLD, 14));

Box1a.addActionListener( this ); //Listeners

Box1b.addActionListener( this );

Box1c.addActionListener( this );

Box1d.addActionListener( this );

Box1e.addActionListener( this );

Box2a.addActionListener( this );

Box2b.addActionListener( this );

Box2c.addActionListener( this );

Box2d.addActionListener( this );

Box2e.addActionListener( this );

Box3a.addActionListener( this );

Box3b.addActionListener( this );

Box3c.addActionListener( this );

Box3d.addActionListener( this );

Box3e.addActionListener( this );

outText2.addActionListener( this );

ahistA1.addActionListener( this );

Enter.addActionListener(this );

textPanel1 = new JPanel();

textPanel1.setLayout(new GridLayout(6, 1));

textPanel1.add( inLabel1 );

textPanel1.add( Box1a );

textPanel1.add( Box1b );

textPanel1.add( Box1c );

textPanel1.add( Box1d );

textPanel1.add( Box1e );

textPanel2 = new JPanel();

textPanel2.setLayout(new GridLayout(6, 1));

textPanel2.add( inLabel2 );

textPanel2.add( Box2a );

textPanel2.add( Box2b );

textPanel2.add( Box2c );

textPanel2.add( Box2d );

textPanel2.add( Box2e );

textPanel3 = new JPanel();

textPanel3.setLayout(new GridLayout(6, 1));

textPanel3.add( inLabel3 );

textPanel3.add( Box3a );

textPanel3.add( Box3b );

textPanel3.add( Box3c );

textPanel3.add( Box3d );

textPanel3.add( Box3e );

textPanel4 = new JPanel();

textPanel4.setLayout(new BoxLayout(textPanel4, BoxLayout.X_AXIS));

textPanel4.add( textPanel1 );

textPanel4.add( textPanel2 );

textPanel4.add( textPanel3 );

textPanel5 = new JPanel();

textPanel5.setLayout(new BoxLayout(textPanel5, BoxLayout.Y_AXIS));

textPanel5.add( outLabel );

textPanel5.add( outText );

textPanel6 = new JPanel();

textPanel6.setLayout(new BoxLayout(textPanel6, BoxLayout.Y_AXIS));

textPanel6.add( textPanel4 );

textPanel6.add( textPanel5 );

textPanel7 = new JPanel();

textPanel7.setLayout(new BoxLayout(textPanel7, BoxLayout.Y_AXIS));

textPanel7.add( outLabel2 );

textPanel7.add( outText2 );

textPanel8 = new JPanel();

textPanel8.setLayout(new BoxLayout(textPanel8, BoxLayout.Y_AXIS));

textPanel8.add( ahistQ1 );

textPanel8.add( ahistA1 );

textPanel8.add( Enter );

layout = new CardLayout();

getContentPane().setLayout(layout);

getContentPane().add( textPanel7, "One" );

getContentPane().add( textPanel6, "Two" );

getContentPane().add( textPanel8, "Three" );

//Set Action Commands

Box1a.setActionCommand( "us1" );

outText.setEditable( false ); //keeps user from typing in the out panels

setTitle("This is JEOPARDY!!");//sets Title

}

public void actionPerformed( ActionEvent evt)

{

if(outText2.getText() != null)

{

layout.show(this.getContentPane(), "Two");

outLabel.setText((outText2.getText()) + "'s score");

//moves to the next panel

}

if(evt.getActionCommand().equals("us1"))

{

layout.show(this.getContentPane(), "Three");

}

if(evt.getActionCommand().equals("Enter") && ahistA1 != null)

{

if(ahistA1.getText().equalsIgnoreCase("1"))

{

score+=400;

outText.setText(score + " ");

repaint();

layout.show(this.getContentPane(), "Two");

}

else

{

score-=400;

outText.setText(score + " ");

layout.show(this.getContentPane(), "Two");

repaint();

}

}

}

public static void main ( String[] args )

{

Jeopardy echo = new Jeopardy() ;

WindowQuitter wquit = new WindowQuitter();

echo.addWindowListener( wquit );

echo.setSize( 450, 350 );

echo.setVisible( true );

}

}

class WindowQuitter extends WindowAdapter

{

public void windowClosing( WindowEvent e )

{

System.exit( 0 );

}

}

[7627 byte] By [newjavaa] at [2007-11-27 3:08:34]
# 1
Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57
DrLaszloJamfa at 2007-7-12 3:56:44 > top of Java-index,Java Essentials,New To Java...