I get a strange error message in my program here is my code:
package code; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JTextField; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.Random; public class GUI extends JFrame{ private static final long serialVersionUID = 1L; private JLabel label1; private JButton button1; private JTextField textbox1; private JTextField textbox2; private JTextField textbox3; Random Rn = new Random(); int number; String p1; String p2; String p3; for(int counter=0; counter<1; counter++){ number = Rn.nextInt(3); } public GUI(){ setLayout(new FlowLayout()); label1 = new JLabel("Enter names."); add(label1); textbox1 = new JTextField("Player 1"); add(textbox1); textbox2 = new JTextField("Player 2"); add(textbox2); textbox3 = new JTextField("Player 3"); add(textbox3); button1 = new JButton("OK"); add(button1); HandlerClass handler = new HandlerClass(); button1.addActionListener(handler); } private class HandlerClass implements ActionListener{ public void actionPerformed(ActionEvent event) { switch (Rn.nextInt()){ case 1: JOptionPane.showMessageDialog(null, p1 + "IS AWESOME!"); break; case 2: JOptionPane.showMessageDialog(null, p2 + "IS AWESOME!"); break; case 3: JOptionPane.showMessageDialog(null, p3 + "IS AWESOME!"); break; } } } }
i get a error on line 25 saying: Syntax error on token ";",{ expected after this token
an a error on line 29 saying: Syntax error, inset "}" to complete Block
but if i remove
the error go's away but if i remove that the code wont workfor(int counter=0; counter<1; counter++){ number = Rn.nextInt(3); }