Boa noite galera, estou tendo dificuldades em resolver um problema com minha interface, sou novato em Java e gostaria de algumas dicas:
Problema nº 1 - nenhum dos botões funcionam, eles disparam, mas não estão realizando nenhuma ação como programei.
Problema nº 2 - no terminal ele me retorna o seguinte erro: exception in thread “awt-eventqueue-0” java.lang.error: unresolved compilation problem j cannot be resolved
este é o meu código
import java.util.;
import java.awt.;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FormTP02 extends JPanel implements ActionListener{
private Button btn1 = new Button(“Ok”);
private Button btn2 = new Button(“Limpar”);
private Button btn3 = new Button(“Mostrar”);
private Button btn4 = new Button(“Sair”);
private Label lName = new Label("Nome: ");
private Label lIdade = new Label("Idade: ");
private Label lEnd = new Label("Endereço: ");
private TextField tfName = new TextField(15);
private TextField tfIdade = new TextField(15);
private TextField tfEnd = new TextField(15);
private void iniciarComponentes(){
JFrame j = new JFrame("TP02 - LP2l4");
j.setLayout(new GridLayout (3,2));
j.setSize(400,180);
JPanel painel1 = new JPanel();
painel1.setLayout(new GridLayout(3,2,10,10));
painel1.setSize(300,100);
painel1.add(lName);
painel1.add(tfName);
painel1.add(lIdade);
painel1.add(tfIdade);
painel1.add(lEnd);
painel1.add(tfEnd);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
JPanel painel2 = new JPanel();
painel2.setLayout(new GridLayout(1,4));
painel2.add(btn1);
painel2.add(btn2);
painel2.add(btn3);
painel2.add(btn4);
btn4.addActionListener(this);
painel2.setSize(100,80);
j.add(painel1);
j.add(painel2);
j.setLocationRelativeTo(null);
j.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
j.setVisible(true);
}
public void windowOpened(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void windowClosing(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void windowDeiconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void windowActivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void windowDeactivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1){
Aluno a = new Aluno();
a.setNome(tfName.getText());
a.setEndereço(tfEnd.getText());
a.setIdade(Integer.parseInt(tfIdade.getText()));
}
else
if(e.getSource() == btn2){
tfName.setText("");
tfEnd.setText("");
tfIdade.setText("");
}
else
if(e.getSource() == btn3){
Aluno a = new Aluno();
String mensagem = "Id: "+a.getUuid()+" Nome: "+a.getNome();
JOptionPane.showMessageDialog(this, mensagem);
}
else if(e.getSource() == btn4){
JFrame f = new JFrame();
System.exit(0);
btn4 = j.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
else{
System.out.println("erro");
}
}
public static void main(String[] args){
FormTP02 f = new FormTP02();
f.iniciarComponentes();
}
}