java 中为什么用setBackground()不能设置背景色
写了一个简单的java 小程序,但是为什么设置背景色不能生效呢?
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class EndingListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Color;
public class FirstJFrame
{
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setSize(500, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton closeButton = new JButton("click the button to end close window");
EndingListener listener = new EndingListener();
closeButton.addActionListener(listener);
window.getContentPane().setBackground(Color.BLACK); window.getContentPane().add(closeButton);
window.setVisible(true);
}
}
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class EndingListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Color;
public class FirstJFrame
{
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setSize(500, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton closeButton = new JButton("click the button to end close window");
EndingListener listener = new EndingListener();
closeButton.addActionListener(listener);
window.getContentPane().setBackground(Color.BLACK); window.getContentPane().add(closeButton);
window.setVisible(true);
}
}
...全文
相关推荐
java GUI界面设计练习
练习GUI基本内容,gui界面设计基本内容入门知识。有需要的可以拿去练手
java图形用户界面设计Swing常用组件PPT课件PPT学习教案.pptx
java图形用户界面设计Swing常用组件PPT课件PPT学习教案.pptx
中级SWING-JTable属性
中级SWING-J中级中级SWING-JTable属性SWING-JTable属性Table属性
java图形用户界面设计Swing常用组件PPT教案学习.pptx
java图形用户界面设计Swing常用组件PPT教案学习.pptx
Java贪吃蛇游戏 代码
Java贪吃蛇游戏 代码 Java贪吃蛇游戏 代码


Java SE
