Olá pessoal!
Estou com o seguinte problema: quando tento passar os valores do campo do JTextField para o metodo setNome e setIdade nao consigo. Pq quando faco o evento, na linha de codigo q faz o isso(setNome e setIdade) é mostrada a msg “Cannot find Symbol”. O msm acontece no evento do JMenuItem help com o JOptionPane.
Caso possam me ajudar…
Grato desde jah.
Ps: como faco pra identar aqui? nao consegui. desculpe se a identacao atrapalhar a leitura do codigo. aqui ta blz, mas qdo peco pra visualizar fica sem identacao.
Eis o codigo:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
-
@author GSM
*/
public class Janela extends JFrame{/** Creates a new instance of Janela */ private String nome; private int idade; JTextField campoNome; JTextField campoIdade;
private Object bar;
public Janela() { super(“Janela POO”); setLayout(new BorderLayout());//MenuBar e Menus JMenuBar bar = new JMenuBar(); JMenu sistema = new JMenu("Sistema"); JMenu ajuda = new JMenu("Ajuda"); JMenuItem sai = new JMenuItem("Sair"); JMenuItem help = new JMenuItem("Ajuda"); ajuda.add(help); sistema.add(sai); bar.add(sistema); bar.add(ajuda); setJMenuBar(bar); //Eventos do MenuItem: sai.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ //this.setNome(this.campoNome.getText()); //this.setIdade(); System.exit(0); } }); help.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ JOptionPane.showMessageDialog(this,"Messagem","Sobre",JOptionPane.INFORMATION_MESSAGE); } }); //Objetos da Janela JPanel PainelCentral = new JPanel(new GridLayout(3,2)); JLabel nomePessoa = new JLabel("Nome:"); PainelCentral.add(nomePessoa); campoNome = new JTextField(15); PainelCentral.add(campoNome); JLabel idadePessoa = new JLabel("Idade:"); PainelCentral.add(idadePessoa); campoIdade = new JTextField(5); PainelCentral.add(campoIdade); JLabel fantasma = new JLabel(""); PainelCentral.add(fantasma); JButton botao = new JButton("OK"); botao.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ this.setNome(this.campoNome.getText()); this.setIdade(Integer.parseInt(this.campoIdade.getText())); } }); PainelCentral.add(botao); add(PainelCentral,BorderLayout.CENTER);
} public String getNome(){ return nome; } public void setNome(String nome){ this.nome = nome; } public int getIdade(){ return idade; } public void setIdade(int idade){ this.idade = idade; } }