?? customerlayout.java
字號:
import javax.swing.*;
import java.awt.*;
// <applet code=Customer width=500 height=200>
// </applet>
public class CustomerLayout extends JApplet
{
//Variable for the panel
JPanel panelObject;
//variables for labels
JLabel labelCustName;
JLabel labelCustNo;
JLabel labelCustSex;
JLabel labelCustAge;
//variables for data entry controls
JTextField textCustName;
JTextField textCustNo;
JComboBox comboCustSex;
JTextField textCustAge;
//Variables for the layout
GridBagLayout gbObject;
GridBagConstraints gbc;
public void init()
{
//Initialize the layout variables
gbObject = new GridBagLayout();
gbc = new GridBagConstraints();
panelObject = (JPanel)getContentPane();
panelObject.setLayout(gbObject);
//Initialize label controls
labelCustName = new JLabel("Customer Name");
labelCustNo = new JLabel("Customer Number");
labelCustSex = new JLabel("Sex");
labelCustAge = new JLabel("Age");
//Initialize data entry controls
textCustName = new JTextField(30);
textCustNo = new JTextField(15);
textCustAge = new JTextField(2);
String Sex[] = { "Male", "Female"};
comboCustSex = new JComboBox(Sex);
//Add controls for Customer Name
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gbObject.setConstraints(labelCustName,gbc);
panelObject.add(labelCustName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 5;
gbObject.setConstraints(textCustName,gbc);
panelObject.add(textCustName);
//Add controls for Customer Number
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbObject.setConstraints(labelCustNo,gbc);
panelObject.add(labelCustNo);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbObject.setConstraints(textCustNo,gbc);
panelObject.add(textCustNo);
//Add controls for Sex
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbObject.setConstraints(labelCustSex,gbc);
panelObject.add(labelCustSex);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbObject.setConstraints(comboCustSex,gbc);
panelObject.add(comboCustSex);
//Add controls for Customer Age
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 14;
gbObject.setConstraints(labelCustAge,gbc);
panelObject.add(labelCustAge);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 14;
gbObject.setConstraints(textCustAge,gbc);
panelObject.add(textCustAge);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -