Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:30:26+00:00 2026-05-31T03:30:26+00:00

I have a raffle draw program that used to have many commands and components,

  • 0

I have a raffle draw program that used to have many commands and components, etc.
But I would like to make it a lot simpler by omitting many commands or components such as buttons or labels.
When I tried to do so, errors arose (42 errors) all of which say:

error: class, interface or enum expected.

Can somebody help me track down these errors?

BTW, here’s my code (UPDATED):

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.sql.*;

public class Case extends JFrame implements ActionListener
{

    static Case app=new Case();
    JDesktopPane desk=new JDesktopPane();

    Connection cn=null;
    ResultSet rs=null;
    Statement stat=null;

    JInternalFrame log=new JInternalFrame("WELCOME!", true,true,true,true);
    JInternalFrame game=new JInternalFrame("Hi! Welcome to RAFFLE DRAW by BSIT22C");

    int arr[]=new int[10];
    int range=0;

    JTextField gametext=new JTextField("",2);
    JTextField txtuser=new JTextField("",20);

    JMenuBar gamebar=new JMenuBar();
    JMenu mnuf=new JMenu("File");
    JMenuItem fnew=new JMenuItem("New Game");
    JMenuItem fquit=new JMenuItem("Quit Game");
    JMenuItem flogout=new JMenuItem("Logout");

    JPanel pnllog=new JPanel();
    JPanel pnlgame=new JPanel();

    JButton blog=new JButton("Login");
    JButton bcan=new JButton("Cancel");

    JButton bgen=new JButton("Generate Number Set");
    JButton bsubmit=new JButton("Submit Number");

    JCheckBox[] ck=new JCheckBox[10];

    JLabel lblives=new JLabel("");
    JLabel lbcons=new JLabel("");

    int life=5;
    int userscore=0;
    int cons=0;


    public void init()
    {

        setContentPane(desk);
        desk.add(log);
        desk.add(game);

        game.setVisible(false);
        game.setSize(800,600);
        game.setContentPane(pnlgame);
        setJMenuBar(gamebar);
        gamebar.add(mnuf);
        mnuf.add(fnew);
        mnuf.add(fscore);
        mnuf.add(flogout);
        mnuf.add(fquit);

        for(int ctr=0;ctr<10;ctr++)
        {
            ck[ctr]=new JCheckBox();
        }
        for(int ctr2=0; ctr2<10; ctr2++)
        {
            pnlgame.add(ck[ctr2]);
        }

        ck[0].setEnabled(false);
        ck[1].setEnabled(false);
        ck[2].setEnabled(false);
        ck[3].setEnabled(false);
        ck[4].setEnabled(false);
        ck[5].setEnabled(false);
        ck[6].setEnabled(false);
        ck[7].setEnabled(false);
        ck[8].setEnabled(false);
        ck[9].setEnabled(false);

        game.setSize(750,100);
        pnlgame.add(gametext);
        pnlgame.add(bsubmit);
        pnlgame.add(bgen);
        pnlgame.add(bup);
        pnlgame.add(lbtimer);
        pnlgame.add(lbtest);
        pnlgame.add(lbscore);
        pnlgame.add(lbachieve);
        pnlgame.add(lblives);
        pnlgame.add(lbcons);
        lbachieve.setText("Bonus");


        bgen.addActionListener(this);
        bsubmit.addActionListener(this);

        setJMenuBar(gamebar);
        gamebar.add(mnuf);
        mnuf.add(fnew);
        mnuf.add(fscore);
        mnuf.add(flogout);
        mnuf.add(fquit);

        log.setVisible(true);
        log.setSize(300,100);
        log.setContentPane(pnllog);

        pnllog.setLayout(new GridLayout(2,2));
        pnllog.add(blog);
        pnllog.add(bcan);


        setJMenuBar(gamebar);
        gamebar.add(mnuf);
        mnuf.add(fnew);
        mnuf.add(fscore);
        mnuf.add(flogout);
        mnuf.add(fquit);

        fnew.setEnabled(false);
        blog.addActionListener(this);
        bcan.addActionListener(this);
        fnew.addActionListener(this);
        fquit.addActionListener(this);
        flogout.addActionListener(this);
        app.setSize(1024,800);
        app.setVisible(true);
    }

    public void actionPerformed(ActionEvent ex)
    {
        Object[] options={"Easy", "Normal", "Hard"};

        if(ex.getSource()==fnew)
        {
            bsubmit.setEnabled(false);
            gametext.setEditable(false);
            int option2=JOptionPane.showOptionDialog(null,"Choose difficulty", "New Game",JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
            if(option2==0)
            {
                for(int ctrck=0; ctrck<10; ctrck++)
                {
                    ck[ctrck].setSelected(false);
                }
                lbtest.setText("");
                gametext.setText("");
                lbachieve.setText("");
                lblives.setText("");
                lbcons.setText("");
                lbscore.setText("");
                life=5;
                userscore=0;
                bgen.setEnabled(true);
                cons=0;
                log.setVisible(false);
                game.setVisible(true);
                range=10;
            }
            else if(option2==1)
            {
                for(int ctre=0; ctre<10; ctre++)
                {
                    ck[ctre].setSelected(false);
                }
                lbtest.setText("");
                gametext.setText("");
                lbscore.setText("");
                lbachieve.setText("");
                lblives.setText("");
                lbcons.setText("");
                life=5;
                userscore=0;
                bgen.setEnabled(true);
                cons=0;
                log.setVisible(false);
                game.setVisible(true);
                range=20;
            }
            else if(option2==2)
            {
                for(int ctrn=0; ctrn<10; ctrn++)
                {
                    ck[ctrn].setSelected(false);
                }
                lbtest.setText("");
                gametext.setText("");
                lbachieve.setText("");
                lblives.setText("");
                lbcons.setText("");
                lbscore.setText("");
                life=5;
                userscore=0;
                bgen.setEnabled(true);
                cons=0;
                log.setVisible(false);
                game.setVisible(true);
                range=40;
            }

    }
    else if(ex.getSource()==fscore)
    {
        {
            int hsconf=JOptionPane.showConfirmDialog(null,"Do you want to view the current score rankings?","Please Confirm",JOptionPane.YES_NO_OPTION);
            if(hsconf==0)
            {
                log.setVisible(false);
                game.setVisible(false);
            }
            else
            {

            }
        }   
        log.setVisible(false);
        game.setVisible(false);
    }
    else if(ex.getSource()==flogout)
    {
        int option = JOptionPane.showConfirmDialog(null,"Do you really want to quit playing?", "Do you want to exit?",JOptionPane.YES_NO_OPTION);
        if(option==0)
        {
            for(int q=0; q<10; q++)
            {
                ck[q].setSelected(false);
            }
            lbtest.setText("");
            lbachieve.setText("");
            lblives.setText("");
            lbcons.setText("");
            lbscore.setText("");
            life=5;
            userscore=0;
            cons=0;
            bgen.setEnabled(true);
        }
        else
        {
            log.setVisible(true);
        }
        for(int e=0; e<10; e++)
        {
            ck[e].setSelected(false);
        }
        lbtest.setText("");
        lbachieve.setText("");
        lblives.setText("");
        lbcons.setText("");
        life=5;
        userscore=0;
        cons=0;
        bgen.setEnabled(true);
        log.setVisible(true);
        game.setVisible(false);
    }
    else if(ex.getSource()==fquit)
    {
        int option = JOptionPane.showConfirmDialog(null,"Do you really want to quit playing?", "Do you want to exit?",JOptionPane.YES_NO_OPTION);
        if(option==0)
        {
            for(int r=0; r<10; r++)
            {
                ck[r].setSelected(false);
            }
            lbtest.setText("");
            lbachieve.setText("");
            lblives.setText("");
            lbcons.setText("");
            life=5;
            userscore=0;
            cons=0;
            bgen.setEnabled(true);
            System.exit(0);
        }
        else
        {
            log.setVisible(true);
        }
    }
    else if(ex.getSource()==bcan)
    {
        int option = JOptionPane.showConfirmDialog(null,"Do you really want to quit playing?", "Do you want to exit?",JOptionPane.YES_NO_OPTION);
        if(option==0)
        {
            System.exit(0);
        }
        else
        {
            log.setVisible(true);
        }
    }

    else if(ex.getSource()==bgen)
    {
        bsubmit.setEnabled(true);
        gametext.setEditable(true);
        app.generate();
    }

    else if(ex.getSource()==bsubmit)
    {

    try
        {
            app.cmpans();
            if(ck[0].isSelected()&&ck[1].isSelected()&&ck[2].isSelected()&&ck[3].isSelected()&&ck[4].isSelected()&&ck[5].isSelected()&&ck[6].isSelected()&&ck[7].isSelected()&&ck[8].isSelected()&&ck[9].isSelected()==true)
            {
                int win = JOptionPane.showConfirmDialog(null,"Do you want to go for another round?","Congratulations! You WIN!",JOptionPane.YES_NO_OPTION);
                if(win==0)
                {
                    for(int r=0; r<10; r++)
                    {
                        ck[r].setSelected(false);
                    }
                    lbtest.setText("");
                    life=5;
                    userscore=0;
                    gametext.setText("");
                    lbscore.setText("");
                    lblives.setText("");
                    lbcons.setText("");
                    cons=0;
                    bgen.setEnabled(true);

                    log.setVisible(false);
                    game.setVisible(true);
                }
                else if(win==1)
                {
                    log.setVisible(false);
                    game.setVisible(false);
                }
            }
            else if(life<=0)
            {
                int gameover=JOptionPane.showConfirmDialog(null,"Sorry, you lost!","GAME OVER!",JOptionPane.OK_OPTION);
                if(gameover==0)
                {
                    game.setVisible(false);
                    log.setVisible(false);
                }
                else if(gameover==1)
                {
                    gametext.setText("");
                    lbscore.setText("");
                    lblives.setText("");
                    lbcons.setText("");
                    lbtest.setText("");
                    lbscore.setText("");
                    bgen.setEnabled(false);
                    bsubmit.setEnabled(false);
                    game.setVisible(false);
                    log.setVisible(false);
                }

            }       
        }catch(Exception ebak){}

    }   

    else if(ex.getSource()==blog)
    {   
        fnew.setEnabled(false);
        bsubmit.setEnabled(false);
        gametext.setEditable(false);
        Object[] options1={"Easy", "Normal", "Hard"};
        log.setVisible(false);
        fnew.setEnabled(true);
        int option3=JOptionPane.showOptionDialog(null,"Choose difficulty", "New Game",JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, options1[1]);
        if(option3==0)
        {
            for(int ctrck2=0; ctrck2<10; ctrck2++)
            {
                ck[ctrck2].setSelected(false);
            }
            lbtest.setText("");
            gametext.setText("");
            lbachieve.setText("");
            lblives.setText("");
            lbcons.setText("");
            lbscore.setText("");
            life=5;
            userscore=0;
            bgen.setEnabled(true);
            cons=0;
            log.setVisible(false);
            game.setVisible(true);
            range=10;
        }
        else if(option3==1)
        {
            for(int ctre=0; ctre<10; ctre++)
            {
                ck[ctre].setSelected(false);
            }
            lbtest.setText("");
            gametext.setText("");
            lbscore.setText("");
            lbachieve.setText("");
            lblives.setText("");
            lbcons.setText("");
            life=5;
            userscore=0;
            bgen.setEnabled(true);
            cons=0;
            log.setVisible(false);
            game.setVisible(true);
            range=20;
        }
        else if(option3==2)
        {
            for(int ctrn=0; ctrn<10; ctrn++)
            {
                ck[ctrn].setSelected(false);
            }
            lbtest.setText("");
            gametext.setText("");
            lbachieve.setText("");
            lblives.setText("");
            lbcons.setText("");
            lbscore.setText("");
            life=5;
            userscore=0;
            bgen.setEnabled(true);
            cons=0;
            log.setVisible(false);
            game.setVisible(true);
            range=40;
        }

    }
}


    public void generate()
    {
        for(int z=0; z<=1; z++)
        {
            for(int i=0; i<10; i++)
            {
                Random rdm=new Random();
                arr[i] = rdm.nextInt(range)+5;
            }
            lbtest.setText("Random Numbers: "+arr[0]+"-"+arr[1]+"-"+arr[2]+"-"+arr[3]+"-"+arr[4]+"-"+arr[5]+"-"+arr[6]+"-"+arr[7]+"-"+arr[8]+"-"+arr[9]);
            bgen.setEnabled(false);
            gametext.setText("");
        }

    }

    public void cmpans()
    {
        boolean success=false;
        boolean boo=false;
        String txget;
        txget=gametext.getText();
        String pars;
        int ans;
        pars=gametext.getText();
        ans=Integer.parseInt(pars);

        for(int i=0; i<10; i++)
        {

            if(ans==arr[i])
            {
                userscore=userscore+10;
                lbscore.setText("Score: "+userscore);
                ck[i].setSelected(true);
                arr[i]=0000;
                gametext.setText("");
                lblives.setText("life: "+life);
                lbcons.setText("cons: "+cons);
                success=true;
            }
            else
            {
                boo=true;
            }
        }

        gametext.setText("");
        if(success==true)
        {
            cons++;
            if(cons==2)
            {
                lbachieve.setText("You're a GOOD GUESSER!");
                userscore=userscore+20;
            }
            else if(cons==4)
            {
                lbachieve.setText("You're an AMAZING GUESSER!!");
                userscore=userscore+50;
            }
        }
        else if(boo==true)
        {
            cons=0;
            life--;
            lblives.setText("life: "+life);
            lbcons.setText("cons: "+cons);
        }

    }

}
    public static void main(String[] args)
    {
        app.init();
    }
}

I can’t figure out which of these lines make the errors arise.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:30:27+00:00Added an answer on May 31, 2026 at 3:30 am

    The problem is you’ve got too many closing braces at the end of your enormous (300+ lines!) actionPerformed method. That means you’re closing your class declaration, leading to the subsequent errors.

    To avoid this problem in the future:

    • Get your IDE to indent your code. Your indentation goes wonky on line 156 to start with (just below the declaration of option2) and also on line 382 (just below the declaration of options1). It’s distinctly odd in other places too.
    • Keep your methods much, much shorter. When a method start taking more than about a page to display, you should really be looking to refactor it into smaller methods. (Ideally, earlier than that – I like methods which are fewer than ~20 lines, personally, although I don’t have a hard and fast limit.) Methods of the size of your actionPerformed one are a maintenance nightmare.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a raffle C++ program that I use to draw out of a
Have a large amount of HTML, but where I thought the bottleneck would be
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
Have a bunch of WCF REST services hosted on Azure that access a SQL
Good Morning Stackoverflow-ka-teers, I am creating a raffle form that allows you to enter
have been trying couple of hours now to make my iphone app universal. The
Have advancements in CPU design like dynamic instruction scheduling narrowed the performance gap between
Have some dates in my local Oracle 11g database that are in this format:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.