Hallo,
ich verstehe nicht, warum JLabel Ausgabe durch drücken des buttons nicht den text von der Eingabe übernimmt.
ich verstehe nicht, warum JLabel Ausgabe durch drücken des buttons nicht den text von der Eingabe übernimmt.
Java:
import java.awt.FlowLayout;
import java.awt.Frame;
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.JTextField;
public class GUIübung extends JFrame {
private JLabel Beschriftung1;
private JLabel Beschriftung2;
private JTextField Eingabe;
String x = "test";
private JLabel Ausgabe;
private JButton Drücker;
public GUIübung() {
setTitle("Übungsprojekt");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setSize(400, 250);
setResizable(false);
Beschriftung1 = new JLabel ("EIngabe bitte");
Beschriftung2 = new JLabel ("Ausgabe hier");
Eingabe = new JTextField(4);
Ausgabe = new JLabel (x);
Drücker = new JButton("Bäm Oida");
Drücker.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
x = Eingabe.getText();
}
});
{
add(Beschriftung1);
add(Eingabe);
add(Beschriftung2);
add(Drücker);
add(Ausgabe);
setLocationRelativeTo(null);
setVisible(true);
}
}}