Hi, I'm trying to make a GUI that creates a random number and then you have to guess the number. I get some weird errors in the code. First of all my code is
import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Rand1 extends JFrame implements ActionListener { private int numberToGuess; Random rand = new Random (); numberToGuess = rand.nextInt(100) ; private int numTries = 0; private int guess; private boolean win = false; private JLabel instructions; private JLabel status; private JTextField enternum; private JButton button; private String convert; public Rand1(){ setLayout(null); setSize(400,400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); instructions = new JLabel("Enter name:"); button = new JButton("Enter"); enternum = new JTextField(""); instructions.setBounds(60, 30, 120, 30); enternum.setBounds(80, 160, 130, 60); button.setBounds(200, 30, 120, 30); status.setBounds(200, 200, 120, 30); public void actionPerformed(ActionEvent e){ if(e.getSource() == button){ convert = enternum.getText(); guess = Integer.parseInt(convert); numTries++; if(guess == numberToGuess){ win = true; } } if(win == true){ status = new JLabel("You Win"); status.setBounds(80, 160, 130, 60); } } }
This program is not finished but I cannot continue with these weird errors. When I compile the program I get the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token ";", , expected
Syntax error, insert "}" to complete MethodBody
at Rand1.<init>(Rand1.java:10)
at Rand2.main(Rand2.java:4)
Any help would be greatly appreciated I am completely confused because I am pretty sure nothing is wrong with my code
Thanks