Panel in the Frame,手动居中

来源:互联网 发布:微信会员积分系统源码 编辑:程序博客网 时间:2024/05/10 17:22
import java.awt.*;public class TestCenterPanel {public static void main(String[] args) {new SelfFrame("FrameWithPanel", 50,50,400,400);}}class SelfFrame extends Frame{private Panel pn;SelfFrame(String str, int x, int y, int width, int height){super(str);super.setBackground(Color.blue);super.setVisible(true);super.setBounds(x, y, width, height);super.setLayout(null);pn = new Panel(null);pn.setBackground(Color.yellow);pn.setBounds((width-width/2)/2, (height-height/2)/2, width/2, height/2);super.add(pn);}}

0 0