[兔年惊喜]Java语言程序设计 实验九 第八章 Swing图形用户界面程(2)

2019-03-09 15:41

public class GridLayout1 {

public static void main(String[] args) { JFrame jf=new JFrame(\网格布局管理器窗体\);

Container c=jf.getContentPane(); JPanel p=new JPanel();

p.setLayout(new GridLayout(2,5,20,20)); p.add(new JButton(\)); p.add(new JButton(\)); p.add(new JButton(\)); p.add(new JButton(\));

p.add(new JButton(\)); c.add(p,BorderLayout.CENTER);

jf.setSize(300,300); } }

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setLocationRelativeTo(null); jf.setVisible(true);

8. GridBagLayout布局管理器问题及实现

import java.awt.BorderLayout; import java.awt.Container;

import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout;

import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel;

public class GridBagLayout1 {

public static void main(String[] args) { JFrame jf=new JFrame(\网格包布局管理器窗体\);

Container c=jf.getContentPane();

JPanel p=new JPanel();

GridBagLayout gr=new GridBagLayout();

p.setLayout(gr);

GridBagConstraints gc=new GridBagConstraints(); gc.fill=GridBagConstraints.BOTH; gc.gridx=0; gc.gridy=0; gc.gridwidth=2; gc.gridheight=1;

JButton bt1=new JButton(\); gr.setConstraints(bt1,gc); p.add(bt1,gc);

gc.gridx=2; gc.gridy=0; gc.gridwidth=1;

gc.gridheight=2;

JButton bt2=new JButton(\); gr.setConstraints(bt2,gc);

p.add(bt2,gc);

gc.gridx=0; gc.gridy=1;

gc.gridwidth=1; gc.gridheight=2;

JButton bt3=new JButton(\); gr.setConstraints(bt3,gc); p.add(bt3,gc);

gc.gridx=1; gc.gridy=1; gc.gridwidth=1; gc.gridheight=1;

JButton bt4=new JButton(\); gr.setConstraints(bt4,gc); p.add(bt4,gc);

gc.gridx=1; gc.gridy=2; gc.gridwidth=2;

gc.gridheight=1;

JButton bt5=new JButton(\); gr.setConstraints(bt5,gc); p.add(bt5,gc);

c.add(p,BorderLayout.CENTER);

jf.setSize(300,300); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

}

jf.setLocationRelativeTo(null); jf.setVisible(true);

五、实验总结


[兔年惊喜]Java语言程序设计 实验九 第八章 Swing图形用户界面程(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:江苏南京仙林大学城某培训中心2号教学楼设计

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: