import java.awt.*;import java.awt.event.*;import javax.swing.*;public class test extends JFrame implements ActionListener{ private JTextField txt; private JButton btn; public test (String title) { super (title); addWindowListener(new WindowAdapter() { public void windowClosing (WindowEvent evt) {System.exit(0);}}); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); txt = new JTextField(); txt.setPreferredSize(new Dimension(100,20)); cp.add(txt); btn = new JButton(); btn.setPreferredSize(new Dimension(100,20)); btn.addActionListener(this); cp.add(btn); setSize(300, 300); setVisible(true); } public void actionPerformed(ActionEvent actionEvent) { if (txt.getText() == "") System.out.println("Kein Text"); else System.out.println("Text vorhanden"); } public static void main (String[] args) { new test("test"); } }