怎么用setBackground(Color)没起作用,没颜色变化

yanxing2012 yanxing2012 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import javax.swing.*;
import java.awt.*;
public class Chuangkou {
public static void main(String[] args)
{
JFrame jf=new JFrame("按钮对象的创建");
JButton btn1=new JButton("按钮一");
JButton btn2=new JButton("");
btn2.setText("按钮二");
Container cp=jf.getContentPane();
jf.setForeground(Color.yellow);
jf.setBackground(Color.red);
cp.setLayout(null);
jf.setSize(400,250);
jf.setLocation(400,250);
cp.add(btn1);
cp.add(btn2);
btn1.setBounds(60,20,80,30);
btn2.setBounds(60,60,80,30);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);

}


}
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
yanxing2012
Java EE 67,535 成员 225,843 内容