0
    public Aufgabezwei() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            textArea1.append(e);

        }
    });
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JTextArea textArea1 = new JTextArea();
    textArea1.setText("Willkommen");
    textArea1.setBounds(111, 11, 182, 127);

    contentPane.add(textArea1);
}

Why do I get the error textArea1 can not be reslved at the mouseclicked event ? And how can I fix it ?

Joffrey
  • 32,348
  • 6
  • 68
  • 100

1 Answers1

1

This line is where you declare the variable textArea1:

JTextArea textArea1 = new JTextArea();

You are trying to use it before you declare it, which is not allowed for local variables in Java.

Move this declaration above the mouse listener creation to make it available to it.

Joffrey
  • 32,348
  • 6
  • 68
  • 100