图形用户界面(二)

package com.imau.gui;

import java.awt.;
import javax.swing.
;
public class FrameDemo extends JFrame{
private JLabel label;
private JButton button;
private JButton bts[]=new JButton[16];
private void init(){
label=new JLabel(“姓名”);
label,size
label.setHorizontalAlignment(JLabel.CENTER);
label.setForeground(Color.ORANGE);
label.setBackground(Color.RED);
button=new JButton(“按钮”);
for(int i=0;i<bts.length;i++){
bts[i]=new JButton(“按钮”+i);
} }
public FrameDemo(){
}
public FrameDemo(){
init();
4.设置布局
setLayout(new GridLayout(4,4));
for(int i=0;i<bts.length;i++){
this.add(bts[i]);
}
this.add(label);
this.button(button);
for(int i=0;i<bts.length;i++){
this.add(bts[i]);
}
3.设置布局
setLayout(new BorderLayout());
add(bts[0],BorderLayout.NORTH);
add(bts[1],BorderLayout.EAST);
add(bts[2],BorderLayout.SOUTH);
add(bts[3],BorderLayout.WEST);
add(bts[4],BorderLayoutCENTER);
2.设置布局
setLayout(new FlowLayout(FloeLayout.LEFT));
1.设置标题、图标、大小、位置、可见性 窗口的事件
this.setTitle(“这是一个窗口”);
this.setSize(300,300);
this.setLocation(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
2.用对象的形式创建窗体
public void tset(){
Jframe frame=new JFrame;
frame.setTitle(“这是一个窗口”);
frame.setSize(300,300);
frame.setLocation(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
11.Java中的布局类型:流式布局(FlowLayout)可以设定组件间的水平和垂直距离、边界布局(Border)

猜你喜欢

转载自blog.csdn.net/weixin_45802395/article/details/106876285