NullLayout自定义布局拼一个心
作者:互联网
package Love;
import java.awt.*;
import javax.swing.*;
public class NullLayoutDemo1 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
// TODO 自动生成的方法存根
NullLayoutDemo1 A = new NullLayoutDemo1( );
A .setVisible(true);//显示
A.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭
A.setSize(1000,600);//大小
}
NullLayoutDemo1( ){
super("不被定义");
Container C = getContentPane( );
C.setLayout(null);//将自定义排版,取消默认排版
C.setBackground(Color.black);//设置背景颜色为黑色
JButton jb [] = new JButton[27];
for (int i = 0; i < 27 ; i++) {
jb [i] = new JButton ("");//添加27个按钮
C.add(jb[i]);//将按钮放到C板面当中
jb[i].setBackground(Color.RED);//设置按钮为红色背景
}
JLabel label = new JLabel("心形");
label.setBounds(450, 10,70,70);
label.setForeground(Color.white);//字体白色
label.setFont(new Font ("宋体",Font.BOLD,30));//设置字体,加粗,大小30px
C.add(label);
//将按钮位置调整为一个心形
jb[0].setBounds (300,70,50,50);//(X轴位置,Y轴位置,按钮宽度,按钮高度)
jb[1].setBounds (375,70,50,50);
jb[2].setBounds (520,70,50,50);
jb[3].setBounds (600,70,50,50);
jb[4].setBounds (260,140,50,50);
jb[5].setBounds (335,140,50,50);
jb[6].setBounds (410,140,50,50);
jb[7].setBounds (485,140,50,50);
jb[8].setBounds (560,140,50,50);
jb[9].setBounds (635,140,50,50);
jb[10].setBounds (230,210,50,50);
jb[11].setBounds (305,210,50,50);
jb[12].setBounds (380,210,50,50);
jb[13].setBounds (455,210,50,50);
jb[14].setBounds (530,210,50,50);
jb[15].setBounds (605,210,50,50);
jb[16].setBounds (680,210,50,50);
jb[17].setBounds (260,280,50,50);
jb[18].setBounds (335,280,50,50);
jb[19].setBounds (410,280,50,50);
jb[20].setBounds (485,280,50,50);
jb[21].setBounds (560,280,50,50);
jb[22].setBounds (635,280,50,50);
jb[23].setBounds (380,350,50,50);
jb[24].setBounds (455,350,50,50);
jb[25].setBounds (530,350,50,50);
jb[26].setBounds (455,420,50,50);
}
}
标签:setBounds,210,自定义,NullLayout,140,布局,50,280,jb 来源: https://www.cnblogs.com/BOKEYUAN999/p/16212584.html