⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridbaglayoutexample.java

📁 Java课程中所有的可运行程序 全部都是java课程中所涉及到的源码
💻 JAVA
字号:
import java.awt.event.*;
import java.awt.*;
 public class GridBagLayoutExample extends Frame {

Label l1,l2,l3;
 Button b1=new Button("登录");
Button b2=new Button("重置");
TextField txt1,txt2;
TextArea txt3;
Panel p1,p2,p3,p4,p5;

public GridBagLayoutExample(String ss)
{
    super(ss);

GridBagLayout gridbag=new GridBagLayout();
         this.setLayout(gridbag);

l3=new Label("系统登录界面");
p1=new Panel();
p1.add(l3);

    Label l1=new Label("用户名:");
	txt1=new TextField(5);

p2=new Panel();
p2.setLayout(new FlowLayout());
p2.add(l1);
p2.add(txt1);


Label l2=new Label("密码 :");
	txt2=new TextField(8);
	txt2.setEchoChar('*');

p3=new Panel();
p3.add(l2);
p3.add(txt2);

txt3=new TextArea();
txt3.setText("这里一个登录界面......"+"\n");
txt3.setRows(5);
txt3.setColumns(18);
txt3.append("这里一个登录界面......"+"\n");
txt3.insert("这里一个登录界面......"+"\n",2);
txt3.setEditable(false);
p4=new Panel();
p4.add(txt3);

p5=new Panel();
p5.add(b1);
p5.add(b2);

 GridBagConstraints c=new  GridBagConstraints();
  c.fill=GridBagConstraints.BOTH;
 // c.weighty=2;
  c.gridwidth=GridBagConstraints.REMAINDER;
  gridbag.setConstraints(p1,c);
add(p1);
  c.gridwidth=1;
          c.gridheight=1;
         gridbag.setConstraints(p2,c);
add(p2);
  gridbag.setConstraints(p3,c);
add(p3);
  //c.weighty=3;
   c.gridwidth=GridBagConstraints.REMAINDER;
    gridbag.setConstraints(p4,c);
add(p4);
 c.gridwidth=GridBagConstraints.REMAINDER;
 c.gridheight=GridBagConstraints.REMAINDER;
     gridbag.setConstraints(p5,c);
add(p5);
}

 public static void main(String args[]) {
        GridBagLayoutExample nowFrame=new GridBagLayoutExample("GridBagLayoutExample");
         nowFrame.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
         }
  });
nowFrame.pack();
  nowFrame.show();
    }

 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -