天天看點

TestPanel_13

import java.awt.*;

public class TestPanel_13 {

 public static void main(String[] args) {

  Frame f = new Frame("Java Frame With Panel!");

  Panel p = new Panel(null);

  f.setLayout(null);

  f.setBounds(300, 300, 500, 500);      //frame的setBounds是針對螢幕左上角的像素數。

  f.setBackground(new Color(0, 0, 102));//這裡new一個color,裡面的參數是代表紅、黃、藍三元色。

  p.setBounds(50, 50, 400, 400);        //panel的setBouds是針對Frame的左上角的像素.

  p.setBackground(new Color(204, 204, 255));

  f.add(p);

  f.setVisible(true);

 }

}