Ask Experts Questions for FREE Help !
Ask
    klevesque's Avatar
    klevesque Posts: 1, Reputation: 1
    New Member
     
    #1

    Dec 20, 2016, 06:12 PM
    Gui
    I am getting a start of illegal expression error for my public class event implements actionlistener my code is
    /*
    bryan argueta
    12/16/2016
    this program will be a guess the number game
    */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RandomGame extends JFrame
    {
    //declare variables
    int randomNum, guess;
    //add button
    private JButton button;
    //text field to display instructions
    private JTextfield textfield;
    //label that asks user to enter number
    private JLabel promptlabel;
    //display won or loss
    private JLabel resultlabel;
    //display how close the user was
    private JLabel randonlabel;
    //contstructor
    public RandomGame();

    public static void main (String args[]);
    {
    RandomGame gui = new RandomGame();
    gui.setDefuaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    gui.setvisible(true);
    gui.setSize(300,150);
    gui.setTitle("Guess the random number game");

    {

    //set layout
    setLayout(new FlowLayout());
    //display instructions for user and display results
    promptlabel = new JLabel("Ener a number between 1 to 10");
    add(promptlabel);

    textfield = new JTextField(5);
    add(textfield);

    button = new JButton("guess:");
    add(button);

    resultlabel = new JLabel("");
    add(resultlabel);

    randomlabel = new JLabel("");
    add(randomLabel);

    event e = new event();
    button.addActionListener(e);


    public class event implements ActionListener
    {
    public void actionPerformed(ActionEcent e);
    {

    randomNum = (int)(Math.random() * 10 + 1);

    //catch block to stop user from entering invalid
    //display the win
    if(guess == randomNum)
    {
    resultlabel.setText("woo you won");

    {
    if (guess != randomNum)
    resultlabel.setText("Sorry you have lost");

    randomlabel.setText("the correct number was: " + randomNum);





    }
    }
    }
    }
    }
    }
    }

Check out some similar questions!

Jtable in java GUI [ 0 Answers ]

a 21 s 23 c 54

Linux with a gui? [ 9 Answers ]

Hey guys need a bit of help here, I'm looking for an OS that will run on my old computer decently, I've been told that there is a Linux that isn't unlike windows if anybody knows any information about what its called and what I would need to set it up (if it exists)? Cheers for the help guys ...

Safesquid web gui [ 1 Answers ]

I have squid proxy server and safesquid web content filter installed and running on my linux box (ubuntu)... I need to change something in the config file of squid because When I try to go to the safesquid web gui browser, I get this error: The requested URL could not be retrieved While trying...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.