首页 > 其他 > 详细

利用awt网格包布局管理器做课程表

时间:2021-05-24 22:37:43      阅读:26      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

import java.awt.*;

import javax.swing.*;
class layout extends JFrame {
public layout(String title) {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(layout);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent("课程表", layout, c);
c.gridwidth = 1;
c.weightx = 1;
c.weighty = 1;
this.addComponent(" ", layout, c);
this.addComponent("星期一", layout, c);
this.addComponent("星期二", layout, c);
this.addComponent("星期三", layout, c);
this.addComponent("星期四", layout, c);
this.addComponent("星期五", layout, c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent("星期六", layout, c);
c.gridwidth = 1;
this.addComponent("第一二节", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent(" ", layout, c);
c.gridwidth = 1;
this.addComponent("第三四节", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent(" ", layout, c);
c.weightx = 0;
c.weighty = 0;
this.addComponent("午休", layout, c);
c.weightx = 1;
c.weighty = 1;
c.gridwidth = 1;
this.addComponent("第五六节", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent(" ", layout, c);
c.gridwidth = 1;
this.addComponent("第七八节", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
this.addComponent(" ", layout, c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.addComponent(" ", layout, c);
c.gridwidth = 1;
// c.gridx
this.setTitle(title);
this.pack();
this.setVisible(true);
}
private void addComponent(String name,GridBagLayout layout,GridBagConstraints c) {
Button bt = new Button(name);
layout.setConstraints(bt,c);
this.add(bt);
}
}

public class Example{
public static void main(String[] args) {
new layout("GridBagLayout");
}
}

利用awt网格包布局管理器做课程表

原文:https://www.cnblogs.com/moaying/p/14806044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!