| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 666 人关注过本帖
标题:GridBagLayout 怎么用啊 到现在还是不会用啊???哪位大侠看看这个程序有问 ...
取消只看楼主 加入收藏
chaiyesong
Rank: 2
等 级:论坛游民
威 望:3
帖 子:70
专家分:44
注 册:2014-5-14
结帖率:77.78%
收藏
 问题点数:0 回复次数:1 
GridBagLayout 怎么用啊 到现在还是不会用啊???哪位大侠看看这个程序有问题没有???
import javax.swing.*;
import java.awt.*;
public class demo_7
{
    public static void main(String[] args)
    {
        demo_7_1 test=new demo_7_1();
    }
}

class demo_7_1 extends JFrame
{
    GridBagLayout  gridbaglayout=new GridBagLayout();
    GridBagConstraints  gridbagconstraints;
    GridBagConstraints  gridbagconstraints1;
    JPanel jp;
    JButton jbutton1;
    JButton jbutton2;
    JButton jbutton3;
    JButton jbutton4;
    JButton jbutton5;
    JButton jbutton6;
    JButton jbutton7;
    public demo_7_1()
    {
        
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(0,0,400,300);
        jp=new JPanel();
        this.setContentPane(jp);
        gridbagconstraints=new GridBagConstraints();
        this.getButton();
        this.addJpaenl();
        gridbaglayout.setConstraints(jbutton1,gridbagconstraints11(0,0,2,2,0,0,0,1,0,0));
        gridbaglayout.setConstraints(jbutton2,gridbagconstraints11(6,6,2,2,0,0,0,1,0,0));        
    }
    /*
    *初始化按钮代码块
    */
    public void getButton()
    {
        jbutton1=new JButton("jbutton1");
        jbutton2=new JButton("jbutton2");
        jbutton3=new JButton("jbutton3");
        jbutton4=new JButton("jbutton4");
        jbutton5=new JButton("jbutton5");
        jbutton6=new JButton("jbutton6");
        jbutton7=new JButton("jbutton7");
    }
    /*
    *初始化约束代码块
    */
    public GridBagConstraints gridbagconstraints11(int x,int y,int w,int h,double w1,double h1,int anchor,int fill,int ipadx,int ipady)
    {
        gridbagconstraints1=new GridBagConstraints();
        gridbagconstraints1.gridx=x;
        gridbagconstraints1.gridx=y;
        gridbagconstraints1.gridwidth=w;
        gridbagconstraints1.gridheight=h;
        gridbagconstraints1.weightx=w1;
        gridbagconstraints1.weighty=h1;
        gridbagconstraints1.anchor=anchor;
        gridbagconstraints1.fill=fill;
        gridbagconstraints1.ipadx=ipadx;
        gridbagconstraints1.ipady=ipady;
        return gridbagconstraints1;
    }
    public void addJpaenl()
    {
        jp.add(jbutton1);
        jp.add(jbutton2);
        jp.add(jbutton3);
        jp.add(jbutton4);
        jp.add(jbutton5);
        jp.add(jbutton6);
        jp.add(jbutton7);
    }
}
搜索更多相关主题的帖子: public import 
2014-05-14 15:09
chaiyesong
Rank: 2
等 级:论坛游民
威 望:3
帖 子:70
专家分:44
注 册:2014-5-14
收藏
得分:0 
这个代码是我自己写的啊
2014-05-24 10:07
快速回复:GridBagLayout 怎么用啊 到现在还是不会用啊???哪位大侠看看这个程 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022166 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved