为什么窗口的背景颜色不能变化
import java.awt.Button;import java.awt.Color;
import java.awt.Font;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class My {
public static void main(String[] args) {
new A();
}
}
class A{
JFrame j=new JFrame("登陆验证");
Button ok=new Button("验证");
Button no=new Button("重置");
Label be=new Label("密码");
Label la=new Label("用户名");
TextField id=new TextField(15);
TextField pass=new TextField(15);
public A(){
Font f=new Font("隶书",Font.BOLD,20);
//明明设置了背景颜色,可是执行后窗口背景颜色就是没变化
j.setBackground(Color.CYAN);
j.setBounds(300,300,400,300);
j.setLayout(null);
j.setVisible(true);
j.addWindowListener(new Window());
ok.setBounds(80,200,50,30);
no.setBounds(200,200,50,30);
ok.setFont(f);
no.setFont(f);
j.add(ok);
j.add(no);
no.addActionListener(new NoActionListener());
ok.addActionListener(new OkActionListener());
la.setBounds(70,60,80,50);
be.setBounds(70,100,80,50);
la.setFont(f);
be.setFont(f);
j.add(la);
j.add(be);
pass.setEchoChar('*');
id.setBounds(160,70,120,30);
pass.setBounds(160,110,120,30);
//添加文本框
j.add(id);
j.add(pass);
}
class NoActionListener implements ActionListener
{
public void actionPerformed(ActionEvent arg0) {
id.setText("");
pass.setText("");
}
}
class OkActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(id.getText().equals("123456") && pass.getText().equals("chengkailei"))
{
JOptionPane.showMessageDialog(null,"登陆成功");
}
else
{
JOptionPane.showMessageDialog(null,"登陆失败");
}
}
}
}
class Window extends WindowAdapter
{
@Override
public void windowClosing(WindowEvent arg0) {
System.exit (0);
}
}