我在 JFrame 中有一个 JLabel,我想在 JFrame 的 windowOpened 事件中将标签设置为“Hello Java”,但出现以下错误:
Syntax error on token(s), misplaced construct(s)
代码:
public p5() {
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent arg0) {
lblA.setText("Hello Java"); // Error is here
}
});
final JLabel lblA = new JLabel("New label");
lblA.setBounds(91, 68, 46, 14);
contentPane.add(lblA);