为什么java的setBackground()不管用,代码如下,背景色一直是白的,麻烦帮忙修改下,谢了~
importjava.applet.*;importjava.awt.*;importjavax.swing.JApplet;publicclassccextendsJA...
import java.applet.*;
import java.awt.*;
import javax.swing.JApplet;
public class cc extends JApplet
{
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
int red,green,blue;
red=255;
blue=255;
green=0;
g2.setPaint(new Color(red,green,blue));
setBackground(Color.cyan);
g2.drawString("Welcome to Xi\047an",25,75);
showStatus("Current RGB:"+g2.getPaint().toString())
}
} 展开
import java.awt.*;
import javax.swing.JApplet;
public class cc extends JApplet
{
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
int red,green,blue;
red=255;
blue=255;
green=0;
g2.setPaint(new Color(red,green,blue));
setBackground(Color.cyan);
g2.drawString("Welcome to Xi\047an",25,75);
showStatus("Current RGB:"+g2.getPaint().toString())
}
} 展开
展开全部
你的代码里没绘制背景的代码 ,而且,你也没有调用父类的方法,去绘制
我帮你改改
public void paint(Graphics g) {
setBackground(Color.cyan);
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
int red, green, blue;
red = 255;
blue = 255;
green = 0;
g2.setPaint(new Color(red, green, blue));
g2.drawString("Welcome to Xi\047an", 25, 75);
showStatus("Current RGB:" + g2.getPaint().toString());
}
展开全部
this.getContentPane().setBackground(Color.cyan);
就可以了
可以参考这个
http://zhidao.baidu.com/question/263731760.html
就可以了
可以参考这个
http://zhidao.baidu.com/question/263731760.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询