我有一个JLabel进入JFrame,我希望在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);
答案 0 :(得分:0)
放置
final JLabel lblA = new JLabel("New label");
前
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent arg0) {
lblA.setText("Hello Java"); // Error is here
}
});
不在它之后,你的语法错误就会消失。