为什么setBackground没有起作用的呢。

来源:互联网 发布:2017年十大网络流行语 编辑:程序博客网 时间:2024/04/29 18:32

//下面是java程序设计教程中的例子程序。不过运行这个applet小程序背景颜色没有改变。

import javax.swing.JApplet;
import java.awt.*;

public class Snowman extends JApplet
{
 public void paint(Graphics page)
 {
  final int MID = 150;
  final int TOP = 50;
 
  setBackground(Color.cyan);

  page.setColor (Color.blue);
  page.fillRect(0,175,300,50);//ground

  page.setColor (Color.yellow);
  page.fillOval (-40,-40,80,80);//sun

  page.setColor (Color.white);
  page.fillOval (MID-20,TOP,40,40);//head
  page.fillOval (MID-35,TOP+35,70,50);//upper torso
  page.fillOval (MID-50,TOP+80,100,60);//lower torso

  page.setColor (Color.black);
  page.fillOval (MID-10,TOP+10,5,5);//left eye
  page.fillOval (MID+5,TOP+10,5,5);//right eye

  page.drawArc (MID-10,TOP+20,20,10,190,160); //smile
  page.drawLine (MID-25,TOP+60,MID-50,TOP+40); //left arm
  page.drawLine (MID+25,TOP+60,MID+55,TOP+60); //right arm

  page.drawLine (MID-20,TOP+5,MID+20,TOP+5); //brim of hat
  page.drawRect (MID-15,TOP-20,30,25); //top of hat
 }
}

原创粉丝点击