error: ")" expected } <

Asked

Viewed 40 times

-1

Guys, I’m trying to make a program that by clicking the confirm button, open another Jframe, but keeps giving the error

error: ")" expected } 
                    ^

and error

"teladelogin.java:48: error: class, interface, or enum expected"

to

import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.awt.event.ActionListener;


 public class teladelogin implements ActionListener{

     public static void main(String[] args){
         JFrame frame = new JFrame();
         JTextField cx = new JTextField(30);
         JPasswordField cs = new JPasswordField(30);
         JButton prime = new JButton("CONFIRMAR");
         frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);  
         JPanel painel = new JPanel();
         frame.add(painel);
         JLabel login = new JLabel("Login: ");
         JLabel senha = new JLabel("Senha: ");
         painel.add(login);
         painel.add(senha);
         painel.add(cx);
         painel.add(cs);
         painel.add(prime);
         prime.setBounds(60,90,120,40);
         cs.setBounds(100,50,80,25);
         cx.setBounds(100,25,80,25);
        painel.setLayout(null);
        senha.setBounds(50,38,60,50);
        login.setBounds(50,10,50,50);
        frame.setVisible(true);
        frame.setSize(200,200);
        frame.setLocationRelativeTo(null);
        prime.addActionListener(new ActionListener(){
            public void actionPerformed(ActioEvent e){
                 JFrame fr = new JFrame();
                 fr.setVisible();

                }


        }
   }
}

1 answer

3

Only by error message you can already deduce: missed close some parentheses or keys.

In his method addActionListener you implement a Functional interface this way:

prime.addActionListener(new ActionListener(){
    public void actionPerformed(ActioEvent e){
         JFrame fr = new JFrame();
         fr.setVisible();
    }
}

Failed to close the parentheses of the method:

prime.addActionListener(new ActionListener(){
    public void actionPerformed(ActioEvent e){
         JFrame fr = new JFrame();
         fr.setVisible();
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.