9_1_030421217.java

来自「开始学JAVA老师布置的作业一学期的哦希望新手有用」· Java 代码 · 共 49 行

JAVA
49
字号
import javax.swing.*;
import java.awt.*;
public class GblTest extends JFrame
{
	GblTest(String a)
	{
		super(a);
	}

	public static void main(String[] args)
	{
		GblTest frame=new GblTest("GridBagLayoutTest");
		GridBagLayout gridBagLayout=new GridBagLayout();
		GridBagConstraints gridBagConstraints1=new GridBagConstraints();
		frame.setSize(300,200);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(gridBagLayout);
		JButton jbutton1=new JButton("Button1");
		JButton jbutton2=new JButton("Button2");
		JButton jbutton3=new JButton("Button3");
		JButton jbutton4=new JButton("Button4");
		JButton jbutton5=new JButton("Button5");
		JButton buttontemp=new JButton();
		Container container=frame.getContentPane();	
		gridBagConstraints1.gridx=0;
		gridBagConstraints1.gridy=0;
		gridBagConstraints1.fill=GridBagConstraints.BOTH;
		gridBagLayout.setConstraints(jbutton1,gridBagConstraints1);
		container.add(jbutton1);				
		gridBagConstraints1.gridx=2;
		gridBagConstraints1.gridy=0;
		gridBagLayout.setConstraints(jbutton2,gridBagConstraints1);
		container.add(jbutton2);		
		gridBagConstraints1.gridx=1;
		gridBagConstraints1.gridy=1;
		gridBagLayout.setConstraints(jbutton3,gridBagConstraints1);
		container.add(jbutton3);		
		gridBagConstraints1.gridx=0;
		gridBagConstraints1.gridy=2;
		gridBagLayout.setConstraints(jbutton4,gridBagConstraints1);
		container.add(jbutton4);								
		gridBagConstraints1.gridx=2;
		gridBagConstraints1.gridy=2;
		gridBagLayout.setConstraints(jbutton5,gridBagConstraints1);
		container.add(jbutton5);
		frame.setVisible(true);
	}
		
}

⌨️ 快捷键说明

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