使用这个setBackGround()设置背景色
使用这个setForeGround()设置前景色

解决方案 »

  1.   

    JApplet中getContentPane().setBackground(Color color);
      

  2.   

    kypfos(大学里没有回忆) 
    在哪写?我在init()中和paint()中都写了,没有效果啊。
      

  3.   

    Color hyel = new Color(192,192,192); 
    JPanel Top1Panel = new JPanel(); 
    Top1Panel.setBackground(hyel);
      

  4.   

    不行不行,背景色怎么都是灰的,真是难看。import java.util.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;public class Applet_vector_demo
        extends JApplet {
      private int[] data_int;
      private int i, n;
      private String[] data_string;  Collection c = new Vector();  public Applet_vector_demo() {}  public void init() {
       //getContentPane().setBackground(Color.red);
        for (i = 1; ; i++) {
          String param = this.getParameter("text" + i);
          if (param == null) {
            break;
          }
          c.add(param);
        }    n = c.size();
        //System.out.println("c.size() = " + n);
        data_int = new int[n];
        data_string = new String[n];
        c.toArray( (Object[]) data_string);    for (i = 0; i < n; i++) {
          data_int[i] = Integer.parseInt(data_string[i]);
        }
      }  public void paint(Graphics g) {
       //getContentPane().
       setBackground(Color.red);
        Font f1 = new Font("宋体", Font.BOLD, 25);
        g.setFont(f1);
        g.drawString("年度销售报表", 150, 25);
        
        Font f2 = new Font("宋体", Font.BOLD, 11);
        g.setFont(f2);    for (i = 0; i <= 7; i++) {
          g.drawString(700 - i * 100 + "", 0, 52 + i * 25);
        }    g.drawLine(8, 30, 10, 224);
        g.drawLine(8, 224, 700, 224);    for (i = 0; i < n; i++) {
          g.drawLine(50 + i * 50, 30, 50 + i * 50, 224);    }
        for (i = 0; i < n; i++) {
          g.setColor(Color.BLACK);
          g.drawString(i + 1 + "月份", 50 + i * 50, 240);
        }    g.setColor(Color.BLUE);    for (i = 0; i < n; i++) {
          g.drawString(data_int[i] + "", 50 + i * 50, 220 - data_int[i] / 4);
        }    for (i = 0; i < n - 1; i++) {
          g.drawLine(50 + i * 50, 225 - data_int[i] / 4, 50 + (i + 1) * 50,
                     225 - data_int[i + 1] / 4);
        }  }
    }
      

  5.   

    搞定了,原来是在init()中写,paint()中不用写
    OK,结贴。
      

  6.   

    哪儿都能写吧!
    继承Applet后 this.setBackground(new Color(r,g,b))