Hi
Ich möchte durch einen Buttonclick einen Text ausgeben, der in einem Textfeld steht.
Wie muss die Addressierung heissen??
Quelltext:
import java.awt.*;
import java.awt.event.*;
public class Fenster
extends Frame{
public static void main(String[] args) {
Fenster wnd = new Fenster();
}
public Fenster()
{
super("Fenster");
setLocation(100,100);
setBackground(Color.orange);
setVisible(true);
addWindowListener(new WindowClosingAdapter(true));
setSize(200,200);
Panel main = new Panel();
main.setLayout(new GridLayout(1,2));
Panel labels = new Panel();
labels.setLayout(new GridLayout(3,1));
labels.add(new Label("Vorname"));
labels.add(new Label("Nachname"));
Button bt = new Button();
//bt.addActionListener();
Panel panel = new Panel();
panel.setLayout(new GridLayout(2,1));
TextField tf1 = new TextField("Fredde", 20);
panel.add(tf1);
panel.add(new TextField("Poncza",20));
setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
main.add(labels);
main.add(panel);
add(main);
}
private void actionPerformed(ActionEvent event)
{
System.out.println(tf1.getText());
// ^--- Darum geht es!!
}
}