Actionlistener in swing won't let me play with my variables!

I am sort of new to java, having done some scripting before, but not much programming experiance. OOP was, until I learned java, something I didn't use that much. All this static and public stuff was hard at first, but I finally think I understand it all.
I am still learning java, and for one of my projects, I am trying to make a small quiz game to learn swing. I am having problems. My button actionlistener complains about my variables, and I have tried many things, like wrapping them in a container and moving them, but I cannot make it compile. Any help would be appriciated. Thanks in advance!
//The program is a quiz thingy.
//the error is down in the GUI section, where I make the button respond to commands
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;//for later use, download files to read off net
import java.io.*;
import java.math.*;
import java.util.Random;
public class Main {
public static void main(String args[]) { 
  File file = new File("problems.txt");
  int probcount=5;
  int answercount=0;
  boolean onproblem = true;
  String[] Problems={"","","","","","","","","","","",""};//I find if I don't init, I get nullpointer errors
  String[] Answers={"","","","","","","","","","","",""};//sorry for the oddness
  String[] thetext=new String[100];
  int i=0;
  int t=0;
  if ( !file.exists(  ) || !file.canRead(  ) ) {
                System.out.println( "Can't read " + file );
                return;
                try {
                    FileReader fr = new FileReader ( file );
                    BufferedReader in = new BufferedReader( fr );
                    String line;
                    while ((line = in.readLine(  )) != null ){
                        thetext=line;
i++;
catch ( FileNotFoundException e ) {
System.out.println( "File Disappeared" );
catch ( IOException e ) {
System.out.println( "Error During File Reading" );
boolean writetoprob = true;
for(int y=0;y<i;y++)
System.out.println(thetext[y]);
for(int y=0;y<i;y++){
if(thetext[y].equals("-")){
if(writetoprob==true)
writetoprob=false;
else{
writetoprob=true;
t++;
else{
if(writetoprob==true)
Problems[t]=Problems[t].concat("\n").concat(thetext[y]);
else
Answers[t]=Answers[t].concat("\n").concat(thetext[y]);
System.out.println(Problems[0]);
System.out.println(Problems[1]);
//TODO:Randomize problems and display them, then answers when button clicked
boolean answerbutton=true;
int probindex=0;
Random rnums = new Random();
probindex=rnums.nextInt()%(t+1);
if(probindex<0)
probindex=-probindex;
System.out.println(probindex);
System.out.println(Problems[probindex]);
JButton action = new JButton("Click for Answer!");
JTextArea tp = new JTextArea(Problems[probindex]);
JFrame jf = new JFrame();
boolean onanswer = false;
action.addActionListener( new ActionListener( ) {
public void actionPerformed(ActionEvent theaction) {
System.out.println(answerbutton);
if(answerbutton==false){
answerbutton=true;
probindex=rnums.nextInt()%(t+1);
if(probindex<0)
probindex=-probindex;
tp.setText(Problems[probindex]);
else{
answerbutton=false;
tp.setText(Answers[probindex]);
Container content = jf.getContentPane( );
content.setLayout(new FlowLayout( ));
content.add(tp);
content.add(action);
jf.pack();
jf.setVisible(true);

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Patrick\FirstCup\build\classes
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:91: local variable answerbutton is accessed from within inner class; needs to be declared final
System.out.println(answerbutton);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:92: local variable answerbutton is accessed from within inner class; needs to be declared final
if(answerbutton==false){
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:93: local variable answerbutton is accessed from within inner class; needs to be declared final
answerbutton=true;
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable probindex is accessed from within inner class; needs to be declared final
probindex=rnums.nextInt()%(t+1);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable rnums is accessed from within inner class; needs to be declared final
probindex=rnums.nextInt()%(t+1);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable t is accessed from within inner class; needs to be declared final
probindex=rnums.nextInt()%(t+1);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:95: local variable probindex is accessed from within inner class; needs to be declared final
if(probindex<0)
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:96: local variable probindex is accessed from within inner class; needs to be declared final
probindex=-probindex;
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:96: local variable probindex is accessed from within inner class; needs to be declared final
probindex=-probindex;
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable Problems is accessed from within inner class; needs to be declared final
tp.setText(Problems[probindex]);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable probindex is accessed from within inner class; needs to be declared final
tp.setText(Problems[probindex]);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable tp is accessed from within inner class; needs to be declared final
tp.setText(Problems[probindex]);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:100: local variable answerbutton is accessed from within inner class; needs to be declared final
answerbutton=false;
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable Answers is accessed from within inner class; needs to be declared final
tp.setText(Answers[probindex]);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable probindex is accessed from within inner class; needs to be declared final
tp.setText(Answers[probindex]);
C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable tp is accessed from within inner class; needs to be declared final
tp.setText(Answers[probindex]);
16 errors
BUILD FAILED (total time: 3 seconds)

Similar Messages

Maybe you are looking for

  • Memory Problems - Advice on quality memory for 865PE Neo2

    I have 2 x 512 MB DDR400 in Dual Channel configuration in my 865PE Neo2 mobo. It's a noname brand (the only mention on it are the letters "VM"). A friend recently warned me about the problems that my arise with cheap memory, so I ran memtest-86 and W

  • Right way to add page.

    Hi, Say A.tiff contains 6 pages and B.tiff contains 5 pages. I need to 5 pages of B.tiff into A.tiff, so that A.tiff contains 11 pages. Can someone pls show me the fastest way of acheiving this ? Currently I am using ImageDecoder to decode A and B to

  • A popup stating "XP antivirus 2012" prevents Firefox from opening

    I want to open Firefox but keep getting message from "XP antivirus 2012 security center"that Firefox is infected with a Trojan and has 29 other viruses. Even when I tell this "antivirus 2012" security center I want to proceed anyway without signing u

  • Can't use encore in creative cloud

    HEY , recently joined creative cloud ... and I am currently working with premier pro ... But my encore software doesn't work ... it wants a serial number .... please help me out because i joined creative cloud just to use encore ?

  • System locking up - trying to pin down why.

    Recently my Lenovo SL 500 has been locking up completely using Arch x86_64 running kernel 2.6.31-ARCH. Its complete system hang, not just X. In fact, the laptop actually flashes the capslock LED when it happens. So far, I have not been able to pin it