Ajudem por favor..iniciante em desespero

4 respostas
N

:?
Boa tarde,
gostaria de saber como atribuio o valor de uma variável a um textbox.

4 Respostas

N

tem TextField e TextArea…

o TextField tem o método setText(String s) e o TextArea tem o método append(String s)

J

Olá neto,
além dos métodos para TextField tem o memos método para TextBox, setString(String variavel);

que irá setar a string para certo campo!

Até mais

M

Pessoal To Tendo O Mesmo Problema Aki mas a dica Não Funcionou no meu Código. Deêm Uma Olhanda!

public void janela2() {
		
		String textUser; 
	
		JTextField textBox;
		textBox = new JTextField(15);
	
		btnExit = new JButton("Sair");
		btnSalva = new JButton("Salvar");
		btnMostra = new JButton("Mostrar");
		
		janela2 = new JFrame("Janela2 Teste, Calculo e JOP");
		janela2.setSize(1024,768);
		janela2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		janela2.setVisible(true);
		
		painel2 = new JPanel();
		painel2.add(btnSalva);
		painel2.add(btnMostra);
		painel2.add(btnExit);
		painel2.add(textBox);
		
		janela2.getContentPane().add(painel2);
		
		btnSalva.addActionListener(new ActionListener()
		{	public void actionPerformed(ActionEvent e)
			{	textBox.setText (String textUser);
			}
		}
		); //parentes referente a ação do btnSalva	
		
		btnMostra.addActionListener(new ActionListener()
		{	public void actionPerformed(ActionEvent e)
			{	
				if (textUser.equals(null)){
					JOptionPane.showMessageDialog(null, "Digite Algo\nOu Mande Salvar\nO Que Foi Digitado\nApós Isso Tente Novamente.", "ERRO", JOptionPane.ERROR_MESSAGE);
				} else {
					JOptionPane.showMessageDialog(null, "A Palavra Digitada Foi : " + textUser + ".", "Resposta", JOptionPane.INFORMATION_MESSAGE );
				}
			}
		}
		); //parentes referente a ação do btnMostra
		
		btnExit.addActionListener(new ActionListener() 
		{	public void actionPerformed(ActionEvent e)
			{	
				System.exit(1);
			}
		}
		); //parentes referente a ação do botao btnExit.
		
	}
}
M

Ops Me eskeci de dizer em q parte ta o erro…
Bom O Erro Ta Nessa Parte Aki

btnSalva.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textBox.setText (String textUser); } } );

Criado 14 de novembro de 2003
Ultima resposta 1 de mar. de 2007
Respostas 4
Participantes 4