CenterPanel

//CenterPanel.java
import java.awt.*;

public class CenterPanel{
public static void main(String[] args){
new MyFrame("Hello",300,300,400,400);
}
}

class MyFrame extends Frame{
MyFrame(String s,int x,int y,int w,int h){
super(s);
setLayout(null);
setBackground(Color.RED);
setBounds(x,y,w,h);
Panel p=new Panel(null);
p.setBounds(w/4,h/4,w/2,h/2);
p.setBackground(Color.YELLOW);
add(p);
setVisible(true);
}
}

运行效果:

posted on 2017-05-21 19:21  Iitb  阅读(129)  评论(0)    收藏  举报

导航