请问java JFrame窗体 怎样设置背景颜色和背景图片
展开全部
import java.awt.Color;望采纳
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class Main extends JFrame {
Image image;
public Main() {
image = Toolkit.getDefaultToolkit().getImage("B.jpg");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(400, 400);
this.setTitle("背景测试");
setBackground(Color.BLACK);
/*设置背景颜色,但是底下重写的paint函数把整个窗口覆盖了所以看不出,注释掉下面的代码就可以看见黑色的窗口了*/
}
public static void main(String args[]) {
new Main();
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.drawImage(image,0,0,400,400,this);
}
}
2015-06-16
展开全部
public void setBackground(Color c)
Sets the background color of this component.
The background color affects each component differently and the
parts of the component that are affected by the background color
may differ between operating systems.
Parameters:
c - the color to become this component's color;
if this parameter is null, then this
component will inherit the background color of its parent
Since:JDK1.0
public void setForeground(Color c)
Sets the foreground color of this component.
Parameters:
c - the color to become this component's
foreground color; if this parameter is null
then this component will inherit
the foreground color of its parent
Since:JDK1.0
Sets the background color of this component.
The background color affects each component differently and the
parts of the component that are affected by the background color
may differ between operating systems.
Parameters:
c - the color to become this component's color;
if this parameter is null, then this
component will inherit the background color of its parent
Since:JDK1.0
public void setForeground(Color c)
Sets the foreground color of this component.
Parameters:
c - the color to become this component's
foreground color; if this parameter is null
then this component will inherit
the foreground color of its parent
Since:JDK1.0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询