语法错误不知为何故?

写了下面一段代码,但是在这两个地方老是报错,不知为何故:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FocusEvent extends JFrame{
JButton jb = new JButton("FocusTest");
jb.setBackground(Color.green);//此处“Syntax error on token "setBackground", Identifier expected after this token”
jb.addFocusListener(new FocusListener(){//此处“Syntax error on token "addFocusListener", = expected after this token”
public void focusGained(FocusEvent e){
jtf.setEditable(true);
}
});
public FocusEvent(){
setLayout(new FlowLayout());
add(jb);
add(jtf,JLabel.RIGHT);
}

final JTextField jtf = new JTextField();
public static void main(String[] args){
SwingConsole sc = new SwingConsole();
sc.run(new FocusEvent(),500,300);
}
}

你可能感兴趣的:(语法错误不知为何故?)