Boa tarde pessoa, blz?
Então, estou precisando de uma ajudinha, precisar mostra em um JPanel o atributo nome da classe funcionário, mas só estou conseguindo fazer isso se coloco como estático e acesso diretamente a classe, segue parte do código:public class Funcionario {
static String nome;
static String empresa;
static String CPF;
double salario;
}
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Label02 extends JFrame{
private JLabel texto;
private JLabel texto2;
public Label02(){
super("Usando rótulos em JFrame");
texto = new JLabel("Informações do clientel!");
texto2 = new JLabel("Nome do Funcionario: " +Funcionario.nome);
add(texto);
add(texto2);
}
}
Parte da classe de outro JFrame:
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(Button2.this, String.format("You pressed: %s",
event.getActionCommand()));
Funcionario.nome= JOptionPane.showInputDialog("Por favor, digite seu nome: ");
String CPF = JOptionPane.showInputDialog("Por favor, digite seu CPF: ");
double rsalario = Double.parseDouble(JOptionPane.showInputDialog("Digite o seu salário :"));
Label02 label1 = new Label02();
label1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label1.setSize(321, 360);
label1.setVisible(true);
}
}
public class Testa {
public static void main(String[] args) {
Button2 bt = new Button2();
bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bt.setSize(420, 360);
bt.setVisible(true);
}
}