Sto iniziando a programmare in java, leggendo da un libro funziona tutto ma non riesco a recuperare il valore di una TextField
codice:import java.awt.*; import java.awt.event.*; class GestoreBottone implements ActionListener { private TextArea a; private TextField nome; private String nomet; public GestoreBottone(TextArea a, TextField nome) { this.a = a; this.nomet = nome.getText(); } public void actionPerformed(ActionEvent e) { String bottone = e.getActionCommand(); if(bottone.equals("OK")) { a.append("Bottone ok \n\r"); a.append("Nome:"+nomet); System.out.println(nomet); } } } class Fin { public static void main(String argv[]) { Frame f = new Frame("Finestra vuota 1"); Panel p = new Panel(); Label l_nome = new Label("Nome"); Label l_cognome = new Label("Cognome"); Button ok = new Button("OK"); TextArea a = new TextArea(10, 20); TextField nome = new TextField(20); TextField cognome = new TextField(15); f.setSize(300, 400); f.add(p); p.add(l_nome); p.add(nome); p.add(l_cognome); p.add(cognome); p.add(new Label()); p.add(a); p.add(ok); ok.addActionListener(new GestoreBottone(a, nome)); f.setVisible(true); p.setVisible(true); } }

Rispondi quotando