package GuiOper;
import java.awt.*;
import javax.swing.*;
/*
* 标签:JLabel创建标签组件,可以用来显示文本信息和图像信息
* 按钮:Button创建按钮组件,组件有按下和释放两种状态,通过用户操作捕获按钮状态
* 文本框:JTextField创建文本框,用来输入和显示单行文本
* 文本区:JTextArea创建文本区,文本区允许输入和显示多行文本,文本区本身没有滚动条,通常
* 将文本区放入滚动面板,借助滚动面板的滚动条显示文本区内容
* 单选按钮:JRadioButton创建单选按钮,单选按钮可以单独使用。也可以和ButtonGroup类联合,
* 构成按钮组
* 复选框:JCheckBox创建复选框,复选框有选定和未选定两种状态,可同时选定多个复选框
* 选择框:JComboBox创建选择框,选择框允许用户从其列表中选择所需值,也允许用户在选择框里输入值
* 列表框:JList创建列表框,列表框也是通过列表的方式供用户选择
* 密码框:JPasswordField,用来输入密码信息,以回显字符显示用户输入的密码,可以调用密码框的
* setEchoChar(char c)方法修改回显字符
* 面框:继承于AWT的Container,因此Jcomponent的子类实例都可用于容器,但常用的
* 用来承载其他组件的容器有JPanel和JScrollPane两种;JPanel面板可以创建一个普通的面板,可以向面板
* 里添加组件,然后将面板添加到顶层窗口中,JPanel面板的默认布局是FlowLayout
* JScrollPane面板:创建一个带有滚动条的滚动面板,主要为一些不带滚动条的组件添加滚动条,并可通过滚动条使用组件,
* 如JTextArea、JList。JScrollPane的默认布局为ScrollPaneLayout,该布局将组件填满整个滚动面板。
*/
public class zuJianPanel extends JFrame{
public zuJianPanel(){setTitle("常用组件");
setBounds(100,100,400,350);
setLayout(null);//设置窗体不使用任何布局管理
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口“关闭”按钮的动作为退出
//创建按钮对象,设置位置及大小,输入 按钮信息,将按钮加入到窗体中
JButton button1=new JButton();
button1.setBounds(280,145,70,23);
button1.setText("确定");
add(button1);
JButton button2=new JButton();
button2.setBounds(280,175,70,23);
button2.setText("取消");
add(button2);
JLabel label1=new JLabel();
label1.setText("性别:");
label1.setBounds(10,36,46,15);
add(label1);
//创建按钮组对象,设置标签文本,设置标签的位置和大小,将标签加入到窗体中
ButtonGroup buttonGroup=new ButtonGroup();
JRadioButton manRadionButton=new JRadioButton();
buttonGroup.add(manRadionButton);
manRadionButton.setSelected(true);
manRadionButton.setText("男");
manRadionButton.setBounds(62,36,46,23);
add(manRadionButton);
JRadioButton womanRadioButton=new JRadioButton();
buttonGroup.add(womanRadioButton);
womanRadioButton.setText("女");
womanRadioButton.setBounds(114,36,46,23);
add(womanRadioButton);
//创建标签对象,设置标签的位置和大小,创建复选框对象,设置复选框的显示文本,设置复选框的位置和大小,将复选框添加到窗体中
JLabel label2=new JLabel();
label2.setText("爱好:");
label2.setBounds(10,70,46,15);
add(label2);
JCheckBox readingCheckBox=new JCheckBox();
readingCheckBox.setText("读书");
readingCheckBox.setBounds(62,67,55,23);
add(readingCheckBox);
JCheckBox musicCheckBox=new JCheckBox();
musicCheckBox.setText("听音乐");
musicCheckBox.setBounds(123,67,68,23);
add(musicCheckBox);
JCheckBox pingpongCheckBox=new JCheckBox();
pingpongCheckBox.setText("乒乓球");
pingpongCheckBox.setBounds(197,67,75,23);
add(pingpongCheckBox);
JLabel label3=new JLabel();
label3.setText("学历:");
label3.setBounds(10,110,46,15);
add(label3);
//设置选择框为可编辑,设置选择框弹出时显示选项的行数,并添加一个选项“大专”
String[]schoolAges={"本科","硕士","博士"};
JComboBox<String>comboBox=new JComboBox<String>(schoolAges);
comboBox.setEditable(true);
comboBox.setMaximumRowCount(3);
comboBox.addItem("大专");
comboBox.setSelectedItem("本科");
comboBox.setBounds(62,110,104,21);
add(comboBox);
JLabel label4=new JLabel();
label4.setText("姓名:");
label4.setBounds(10,10,46,15);
add(label4);
//创建文本框对象,设置文本框内容为水平对齐,设置文本框内容的显示位置和大小
JTextField textField=new JTextField();
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setFont(new Font(" ",Font.BOLD,12));
textField.setBounds(62,7,100,21);
add(textField);
//设置密码输入部分,并将回显字符为‘&’
JLabel label5=new JLabel();
label5.setText("密码:");
label5.setBounds(180,10,46,15);
add(label5);
JPasswordField passwordField=new JPasswordField();
passwordField.setEchoChar('&');
passwordField.setBounds(230,7,120,21);
add(passwordField);
//创建文本域对象,设置文本域显示的列数和行数,在文本域中加入滑动条,设置滑动板的位置大小
JLabel label6=new JLabel();
label6.setText("备注:");
label6.setBounds(10,150,46,15);
add(label6);
JTextArea textArea=new JTextArea();
textArea.setColumns(15);
textArea.setRows(3);
textArea.setLineWrap(true);
JScrollPane scrollPane=new JScrollPane();
scrollPane.setViewportView(textArea);
Dimension dime=textArea.getPreferredSize();
scrollPane.setBounds(62,145,dime.width,dime.height);
add(scrollPane);
setVisible(true);
}
public static void main(String args[])
{
zuJianPanel frame=new zuJianPanel();
}
}
import java.awt.*;
import javax.swing.*;
/*
* 标签:JLabel创建标签组件,可以用来显示文本信息和图像信息
* 按钮:Button创建按钮组件,组件有按下和释放两种状态,通过用户操作捕获按钮状态
* 文本框:JTextField创建文本框,用来输入和显示单行文本
* 文本区:JTextArea创建文本区,文本区允许输入和显示多行文本,文本区本身没有滚动条,通常
* 将文本区放入滚动面板,借助滚动面板的滚动条显示文本区内容
* 单选按钮:JRadioButton创建单选按钮,单选按钮可以单独使用。也可以和ButtonGroup类联合,
* 构成按钮组
* 复选框:JCheckBox创建复选框,复选框有选定和未选定两种状态,可同时选定多个复选框
* 选择框:JComboBox创建选择框,选择框允许用户从其列表中选择所需值,也允许用户在选择框里输入值
* 列表框:JList创建列表框,列表框也是通过列表的方式供用户选择
* 密码框:JPasswordField,用来输入密码信息,以回显字符显示用户输入的密码,可以调用密码框的
* setEchoChar(char c)方法修改回显字符
* 面框:继承于AWT的Container,因此Jcomponent的子类实例都可用于容器,但常用的
* 用来承载其他组件的容器有JPanel和JScrollPane两种;JPanel面板可以创建一个普通的面板,可以向面板
* 里添加组件,然后将面板添加到顶层窗口中,JPanel面板的默认布局是FlowLayout
* JScrollPane面板:创建一个带有滚动条的滚动面板,主要为一些不带滚动条的组件添加滚动条,并可通过滚动条使用组件,
* 如JTextArea、JList。JScrollPane的默认布局为ScrollPaneLayout,该布局将组件填满整个滚动面板。
*/
public class zuJianPanel extends JFrame{
public zuJianPanel(){setTitle("常用组件");
setBounds(100,100,400,350);
setLayout(null);//设置窗体不使用任何布局管理
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口“关闭”按钮的动作为退出
//创建按钮对象,设置位置及大小,输入 按钮信息,将按钮加入到窗体中
JButton button1=new JButton();
button1.setBounds(280,145,70,23);
button1.setText("确定");
add(button1);
JButton button2=new JButton();
button2.setBounds(280,175,70,23);
button2.setText("取消");
add(button2);
JLabel label1=new JLabel();
label1.setText("性别:");
label1.setBounds(10,36,46,15);
add(label1);
//创建按钮组对象,设置标签文本,设置标签的位置和大小,将标签加入到窗体中
ButtonGroup buttonGroup=new ButtonGroup();
JRadioButton manRadionButton=new JRadioButton();
buttonGroup.add(manRadionButton);
manRadionButton.setSelected(true);
manRadionButton.setText("男");
manRadionButton.setBounds(62,36,46,23);
add(manRadionButton);
JRadioButton womanRadioButton=new JRadioButton();
buttonGroup.add(womanRadioButton);
womanRadioButton.setText("女");
womanRadioButton.setBounds(114,36,46,23);
add(womanRadioButton);
//创建标签对象,设置标签的位置和大小,创建复选框对象,设置复选框的显示文本,设置复选框的位置和大小,将复选框添加到窗体中
JLabel label2=new JLabel();
label2.setText("爱好:");
label2.setBounds(10,70,46,15);
add(label2);
JCheckBox readingCheckBox=new JCheckBox();
readingCheckBox.setText("读书");
readingCheckBox.setBounds(62,67,55,23);
add(readingCheckBox);
JCheckBox musicCheckBox=new JCheckBox();
musicCheckBox.setText("听音乐");
musicCheckBox.setBounds(123,67,68,23);
add(musicCheckBox);
JCheckBox pingpongCheckBox=new JCheckBox();
pingpongCheckBox.setText("乒乓球");
pingpongCheckBox.setBounds(197,67,75,23);
add(pingpongCheckBox);
JLabel label3=new JLabel();
label3.setText("学历:");
label3.setBounds(10,110,46,15);
add(label3);
//设置选择框为可编辑,设置选择框弹出时显示选项的行数,并添加一个选项“大专”
String[]schoolAges={"本科","硕士","博士"};
JComboBox<String>comboBox=new JComboBox<String>(schoolAges);
comboBox.setEditable(true);
comboBox.setMaximumRowCount(3);
comboBox.addItem("大专");
comboBox.setSelectedItem("本科");
comboBox.setBounds(62,110,104,21);
add(comboBox);
JLabel label4=new JLabel();
label4.setText("姓名:");
label4.setBounds(10,10,46,15);
add(label4);
//创建文本框对象,设置文本框内容为水平对齐,设置文本框内容的显示位置和大小
JTextField textField=new JTextField();
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setFont(new Font(" ",Font.BOLD,12));
textField.setBounds(62,7,100,21);
add(textField);
//设置密码输入部分,并将回显字符为‘&’
JLabel label5=new JLabel();
label5.setText("密码:");
label5.setBounds(180,10,46,15);
add(label5);
JPasswordField passwordField=new JPasswordField();
passwordField.setEchoChar('&');
passwordField.setBounds(230,7,120,21);
add(passwordField);
//创建文本域对象,设置文本域显示的列数和行数,在文本域中加入滑动条,设置滑动板的位置大小
JLabel label6=new JLabel();
label6.setText("备注:");
label6.setBounds(10,150,46,15);
add(label6);
JTextArea textArea=new JTextArea();
textArea.setColumns(15);
textArea.setRows(3);
textArea.setLineWrap(true);
JScrollPane scrollPane=new JScrollPane();
scrollPane.setViewportView(textArea);
Dimension dime=textArea.getPreferredSize();
scrollPane.setBounds(62,145,dime.width,dime.height);
add(scrollPane);
setVisible(true);
}
public static void main(String args[])
{
zuJianPanel frame=new zuJianPanel();
}
}