-1

Galera, to tentando fazer um programa que ao clicar no botão confirmar, abra outra JFrame, mas fica dando o erro

error: ")" expected } 
                    ^

e o erro

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

a

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 Resposta 1

3

Só pela mensagem de erro já dá para deduzir: faltou fechar algum parenteses ou chaves.

No seu método addActionListener você implementa uma interface functional dessa forma:

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

Faltou fechar os parenteses do método:

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

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .