用java编写一个登录界面,用SWING组件
用java编写一个登录界面,用SWING组件。要求有姓名(文本框)、专业(组合框)、性别(单选按钮)、爱好(复选按钮)、内容(文本区域)确定按钮、取消按钮。要求点确定在内...
用java编写一个登录界面,用SWING组件。要求有姓名(文本框)、专业(组合框)、性别(单选按钮)、爱好(复选按钮)、内容(文本区域)确定按钮、取消按钮。要求点确定在内容区域内显示所有信息。
展开
展开全部
import java.awt.Color;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
/**
* 一个简单的Swing窗口,输入内容单击“确定”按钮后,在文本域中显示输入的内容。
* 单击“取消”按钮,清空页面内容。
* @author yzg
*
*/
public class Register extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel nameLabel;
private JTextArea context;
private JTextField name;
private JLabel pLabel;
JList speciality;
JLabel mLabel;
String[] data = { "计算机", "英语", "机械", "化工" };
ButtonGroup bg;
JRadioButton male;
JRadioButton female;
JLabel fLabel;
JCheckBox faverite1;
JCheckBox faverite2;
JCheckBox faverite3;
JCheckBox faverite4;
public Register(String title) {
super(title);
this.getContentPane().setLayout(null);
// 下面两行是取得屏幕的高度和宽度
double lx = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double ly = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));// 设定窗口出现位置
this.setSize(340, 440);// 设定窗口大小
}
public void showWin() {
// 确保窗体有一个好的外观装饰
// setDefaultLookAndFeelDecorated(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
// 姓名
nameLabel = new JLabel("姓名 :");
nameLabel.setBounds(30, 10, 50, 25);
name = new JTextField();
name.setBounds(80, 10, 120, 20);
name.setBorder(BorderFactory.createLineBorder(Color.BLUE));
name.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
if (name.getText().length() > 6) {
name.setText(name.getText().substring(0, 6));
}
}
});
// 专业 组合框
pLabel = new JLabel("专业 :");
pLabel.setBounds(30, 40, 50, 25);
speciality = new JList(data);
speciality.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
speciality.setBounds(80, 40, 80, 85);
speciality.setBorder(BorderFactory.createLineBorder(Color.GREEN));
mLabel = new JLabel("性别 :");
mLabel.setBounds(30, 130, 50, 25);
// 性别 单选框
bg = new ButtonGroup();
male = new JRadioButton("男");
female = new JRadioButton("女");
bg.add(male);
bg.add(female);
male.setBounds(80, 130, 60, 25);
female.setBounds(140, 130, 60, 25);
fLabel = new JLabel("爱好 :");
fLabel.setBounds(30, 160, 50, 25);
// 爱好 复选框
faverite1 = new JCheckBox("音乐");
faverite2 = new JCheckBox("足球");
faverite3 = new JCheckBox("高尔夫");
faverite4 = new JCheckBox("游戏");
faverite1.setBounds(80, 160, 60, 25);
faverite2.setBounds(140, 160, 60, 25);
faverite3.setBounds(200, 160, 65, 25);
faverite4.setBounds(265, 160, 60, 25);
// 内容 文本区域
JLabel conLabel = new JLabel("输入的内容 :");
conLabel.setBounds(30, 250, 90, 25);
context = new JTextArea();
context.setBounds(30, 270, 260, 100);
context.setBorder(BorderFactory.createLineBorder(Color.black));
// 确定按钮
JButton ok = new JButton("确定");
ok.setBounds(50, 190, 60, 25);
ok.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
StringBuffer sb = new StringBuffer();
sb.append(nameLabel.getText()).append(name.getText());
sb.append("\n");
int index = speciality.getSelectedIndex();
if (index >= 0) {
sb.append(pLabel.getText()).append(data[index]);
} else {
sb.append(pLabel.getText());
}
sb.append("\n");
sb.append(mLabel.getText());
if (male.isSelected()) {
sb.append("男");
}
if (female.isSelected()) {
sb.append("女");
}
sb.append("\n");
sb.append(fLabel.getText());
if (faverite1.isSelected()) {
sb.append("音乐 ");
}
if (faverite2.isSelected()) {
sb.append("足球 ");
}
if (faverite3.isSelected()) {
sb.append("高尔夫 ");
}
if (faverite4.isSelected()) {
sb.append("游戏 ");
}
context.setText(sb.toString());
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
// 取消按钮
JButton cancel = new JButton("取消");
cancel.setBounds(120, 190, 60, 25);
cancel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
name.setText("");
speciality.clearSelection();
if (faverite1.isSelected()) {
faverite1.setSelected(false);
}
if (faverite2.isSelected()) {
faverite2.setSelected(false);
}
if (faverite3.isSelected()) {
faverite3.setSelected(false);
}
if (faverite4.isSelected()) {
faverite4.setSelected(false);
}
context.setText("");
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
this.getContentPane().add(nameLabel);
this.getContentPane().add(name);
this.getContentPane().add(pLabel);
this.getContentPane().add(speciality);
this.getContentPane().add(mLabel);
this.getContentPane().add(male);
this.getContentPane().add(female);
this.getContentPane().add(fLabel);
this.getContentPane().add(faverite1);
this.getContentPane().add(faverite2);
this.getContentPane().add(faverite3);
this.getContentPane().add(faverite4);
this.getContentPane().add(conLabel);
this.getContentPane().add(context);
this.getContentPane().add(ok);
this.getContentPane().add(cancel);
// this.pack();
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
Register reg = new Register("Register");
reg.showWin();
}
}
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
/**
* 一个简单的Swing窗口,输入内容单击“确定”按钮后,在文本域中显示输入的内容。
* 单击“取消”按钮,清空页面内容。
* @author yzg
*
*/
public class Register extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel nameLabel;
private JTextArea context;
private JTextField name;
private JLabel pLabel;
JList speciality;
JLabel mLabel;
String[] data = { "计算机", "英语", "机械", "化工" };
ButtonGroup bg;
JRadioButton male;
JRadioButton female;
JLabel fLabel;
JCheckBox faverite1;
JCheckBox faverite2;
JCheckBox faverite3;
JCheckBox faverite4;
public Register(String title) {
super(title);
this.getContentPane().setLayout(null);
// 下面两行是取得屏幕的高度和宽度
double lx = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double ly = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));// 设定窗口出现位置
this.setSize(340, 440);// 设定窗口大小
}
public void showWin() {
// 确保窗体有一个好的外观装饰
// setDefaultLookAndFeelDecorated(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
// 姓名
nameLabel = new JLabel("姓名 :");
nameLabel.setBounds(30, 10, 50, 25);
name = new JTextField();
name.setBounds(80, 10, 120, 20);
name.setBorder(BorderFactory.createLineBorder(Color.BLUE));
name.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
if (name.getText().length() > 6) {
name.setText(name.getText().substring(0, 6));
}
}
});
// 专业 组合框
pLabel = new JLabel("专业 :");
pLabel.setBounds(30, 40, 50, 25);
speciality = new JList(data);
speciality.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
speciality.setBounds(80, 40, 80, 85);
speciality.setBorder(BorderFactory.createLineBorder(Color.GREEN));
mLabel = new JLabel("性别 :");
mLabel.setBounds(30, 130, 50, 25);
// 性别 单选框
bg = new ButtonGroup();
male = new JRadioButton("男");
female = new JRadioButton("女");
bg.add(male);
bg.add(female);
male.setBounds(80, 130, 60, 25);
female.setBounds(140, 130, 60, 25);
fLabel = new JLabel("爱好 :");
fLabel.setBounds(30, 160, 50, 25);
// 爱好 复选框
faverite1 = new JCheckBox("音乐");
faverite2 = new JCheckBox("足球");
faverite3 = new JCheckBox("高尔夫");
faverite4 = new JCheckBox("游戏");
faverite1.setBounds(80, 160, 60, 25);
faverite2.setBounds(140, 160, 60, 25);
faverite3.setBounds(200, 160, 65, 25);
faverite4.setBounds(265, 160, 60, 25);
// 内容 文本区域
JLabel conLabel = new JLabel("输入的内容 :");
conLabel.setBounds(30, 250, 90, 25);
context = new JTextArea();
context.setBounds(30, 270, 260, 100);
context.setBorder(BorderFactory.createLineBorder(Color.black));
// 确定按钮
JButton ok = new JButton("确定");
ok.setBounds(50, 190, 60, 25);
ok.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
StringBuffer sb = new StringBuffer();
sb.append(nameLabel.getText()).append(name.getText());
sb.append("\n");
int index = speciality.getSelectedIndex();
if (index >= 0) {
sb.append(pLabel.getText()).append(data[index]);
} else {
sb.append(pLabel.getText());
}
sb.append("\n");
sb.append(mLabel.getText());
if (male.isSelected()) {
sb.append("男");
}
if (female.isSelected()) {
sb.append("女");
}
sb.append("\n");
sb.append(fLabel.getText());
if (faverite1.isSelected()) {
sb.append("音乐 ");
}
if (faverite2.isSelected()) {
sb.append("足球 ");
}
if (faverite3.isSelected()) {
sb.append("高尔夫 ");
}
if (faverite4.isSelected()) {
sb.append("游戏 ");
}
context.setText(sb.toString());
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
// 取消按钮
JButton cancel = new JButton("取消");
cancel.setBounds(120, 190, 60, 25);
cancel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
name.setText("");
speciality.clearSelection();
if (faverite1.isSelected()) {
faverite1.setSelected(false);
}
if (faverite2.isSelected()) {
faverite2.setSelected(false);
}
if (faverite3.isSelected()) {
faverite3.setSelected(false);
}
if (faverite4.isSelected()) {
faverite4.setSelected(false);
}
context.setText("");
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
this.getContentPane().add(nameLabel);
this.getContentPane().add(name);
this.getContentPane().add(pLabel);
this.getContentPane().add(speciality);
this.getContentPane().add(mLabel);
this.getContentPane().add(male);
this.getContentPane().add(female);
this.getContentPane().add(fLabel);
this.getContentPane().add(faverite1);
this.getContentPane().add(faverite2);
this.getContentPane().add(faverite3);
this.getContentPane().add(faverite4);
this.getContentPane().add(conLabel);
this.getContentPane().add(context);
this.getContentPane().add(ok);
this.getContentPane().add(cancel);
// this.pack();
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
Register reg = new Register("Register");
reg.showWin();
}
}
展开全部
package yu.zhong.hu;
import javax.swing.UIManager;
import java.awt.*;
public class LoginApp {
boolean packFrame = false;
//Construct the application
public LoginApp() {
FrameMain frame = new FrameMain();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new LoginApp();
}
}
//------------------------------------------------------------------
package yu.zhong.hu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class FrameMain extends JFrame {
JPanel contentPane;
JLabel lblName = new JLabel();
JTextField txtName = new JTextField();
JLabel lblField = new JLabel();
JComboBox cbField = new JComboBox();
Border border1;
JLabel lblSex = new JLabel();
JRadioButton rbMale = new JRadioButton();
JRadioButton rbFemale = new JRadioButton();
JLabel jLabel1 = new JLabel();
JCheckBox cbWX = new JCheckBox();
JCheckBox cbTY = new JCheckBox();
JCheckBox cbYS = new JCheckBox();
JLabel lblContent = new JLabel();
JTextArea areaContent = new JTextArea();
JButton btnCancel = new JButton();
JButton btnOK = new JButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
//Construct the frame
public FrameMain() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(178, 178, 178));
lblName.setFont(new java.awt.Font("宋体", 0, 12));
lblName.setText("姓名:");
lblName.setBounds(new Rectangle(13, 12, 39, 24));
contentPane.setFont(new java.awt.Font("宋体", 0, 12));
contentPane.setForeground(Color.black);
contentPane.setRequestFocusEnabled(true);
contentPane.setLayout(null);
this.setResizable(false);
this.setSize(new Dimension(400, 350));
this.setTitle("登录主界面");
txtName.setBackground(Color.white);
txtName.setFont(new java.awt.Font("宋体", 0, 12));
txtName.setBounds(new Rectangle(52, 17, 205, 20));
lblField.setFont(new java.awt.Font("宋体", 0, 12));
lblField.setText("专业:");
lblField.setBounds(new Rectangle(12, 41, 40, 25));
cbField.setFont(new java.awt.Font("宋体", 0, 12));
cbField.setBorder(BorderFactory.createEtchedBorder());
cbField.setEditor(null);
cbField.setSelectedIndex(-1);
cbField.setSelectedItem(lblField);
cbField.setBounds(new Rectangle(52, 46, 205, 20));
cbField.addItem("自动化");
cbField.addItem("计算机");
cbField.addItem("物理学");
cbField.setSelectedIndex(0);
lblSex.setFont(new java.awt.Font("宋体", 0, 12));
lblSex.setText("性别:");
lblSex.setBounds(new Rectangle(14, 68, 39, 29));
rbMale.setFont(new java.awt.Font("宋体", 0, 12));
rbMale.setSelected(true);
rbMale.setText("男性");
rbMale.setBounds(new Rectangle(48, 69, 57, 25));
rbFemale.setFont(new java.awt.Font("宋体", 0, 12));
rbFemale.setText("女性");
rbFemale.setBounds(new Rectangle(107, 70, 91, 25));
jLabel1.setFont(new java.awt.Font("宋体", 0, 12));
jLabel1.setText("爱好:");
jLabel1.setBounds(new Rectangle(14, 101, 41, 16));
cbWX.setFont(new java.awt.Font("宋体", 0, 12));
cbWX.setText("文学");
cbWX.setBounds(new Rectangle(48, 96, 56, 25));
cbTY.setFont(new java.awt.Font("宋体", 0, 12));
cbTY.setText("体育");
cbTY.setBounds(new Rectangle(107, 97, 52, 25));
cbYS.setFont(new java.awt.Font("宋体", 0, 12));
cbYS.setText("艺术");
cbYS.setBounds(new Rectangle(163, 96, 52, 25));
lblContent.setFont(new java.awt.Font("宋体", 0, 12));
lblContent.setText("选取内容:");
lblContent.setBounds(new Rectangle(15, 127, 168, 16));
areaContent.setFont(new java.awt.Font("宋体", 0, 12));
areaContent.setBorder(BorderFactory.createEtchedBorder());
areaContent.setText("");
areaContent.setBounds(new Rectangle(16, 147, 369, 122));
btnCancel.setBounds(new Rectangle(209, 276, 94, 30));
btnCancel.setText("取消");
btnCancel.addActionListener(new FrameMain_btnCancel_actionAdapter(this));
btnCancel.setFont(new java.awt.Font("宋体", 0, 12));
btnOK.setBounds(new Rectangle(89, 276, 95, 31));
btnOK.setText("确定");
btnOK.addActionListener(new FrameMain_btnOK_actionAdapter(this));
btnOK.setFont(new java.awt.Font("宋体", 0, 12));
contentPane.add(txtName, null);
contentPane.add(lblName, null);
contentPane.add(cbField, null);
contentPane.add(lblSex, null);
contentPane.add(rbFemale, null);
contentPane.add(lblField, null);
contentPane.add(jLabel1, null);
contentPane.add(rbMale, null);
contentPane.add(cbWX, null);
contentPane.add(cbTY, null);
contentPane.add(cbYS, null);
contentPane.add(lblContent, null);
contentPane.add(areaContent, null);
contentPane.add(btnCancel, null);
contentPane.add(btnOK, null);
buttonGroup1.add(rbMale);
buttonGroup1.add(rbFemale);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void btnCancel_actionPerformed(ActionEvent e) {
System.exit(0);
}
void btnOK_actionPerformed(ActionEvent e) {
this.areaContent.setText("");
String userName=this.txtName.getText();
this.areaContent.append("姓名:"+(userName==null || userName.trim().length()<=0?"未指定":userName));
this.areaContent.append("\n");
this.areaContent.append("专业:"+(String)this.cbField.getSelectedItem());
this.areaContent.append("\n");
this.areaContent.append("性别:"+(this.rbMale.isSelected()?"男性":"女性"));
this.areaContent.append("\n");
this.areaContent.append("爱好:");
this.areaContent.append("\n");
boolean checked=false;
JCheckBox[] cbes=new JCheckBox[]{this.cbWX,this.cbTY,this.cbYS};
for(int i=0;i<cbes.length;i++){
if(cbes[i].isSelected()){
this.areaContent.append(cbes[i].getText());
this.areaContent.append(" ");
checked=true;
}
}
if(checked)
this.areaContent.append("\n");
}
}
class FrameMain_btnCancel_actionAdapter implements java.awt.event.ActionListener {
FrameMain adaptee;
FrameMain_btnCancel_actionAdapter(FrameMain adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCancel_actionPerformed(e);
}
}
class FrameMain_btnOK_actionAdapter implements java.awt.event.ActionListener {
FrameMain adaptee;
FrameMain_btnOK_actionAdapter(FrameMain adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOK_actionPerformed(e);
}
}
import javax.swing.UIManager;
import java.awt.*;
public class LoginApp {
boolean packFrame = false;
//Construct the application
public LoginApp() {
FrameMain frame = new FrameMain();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new LoginApp();
}
}
//------------------------------------------------------------------
package yu.zhong.hu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class FrameMain extends JFrame {
JPanel contentPane;
JLabel lblName = new JLabel();
JTextField txtName = new JTextField();
JLabel lblField = new JLabel();
JComboBox cbField = new JComboBox();
Border border1;
JLabel lblSex = new JLabel();
JRadioButton rbMale = new JRadioButton();
JRadioButton rbFemale = new JRadioButton();
JLabel jLabel1 = new JLabel();
JCheckBox cbWX = new JCheckBox();
JCheckBox cbTY = new JCheckBox();
JCheckBox cbYS = new JCheckBox();
JLabel lblContent = new JLabel();
JTextArea areaContent = new JTextArea();
JButton btnCancel = new JButton();
JButton btnOK = new JButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
//Construct the frame
public FrameMain() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(178, 178, 178));
lblName.setFont(new java.awt.Font("宋体", 0, 12));
lblName.setText("姓名:");
lblName.setBounds(new Rectangle(13, 12, 39, 24));
contentPane.setFont(new java.awt.Font("宋体", 0, 12));
contentPane.setForeground(Color.black);
contentPane.setRequestFocusEnabled(true);
contentPane.setLayout(null);
this.setResizable(false);
this.setSize(new Dimension(400, 350));
this.setTitle("登录主界面");
txtName.setBackground(Color.white);
txtName.setFont(new java.awt.Font("宋体", 0, 12));
txtName.setBounds(new Rectangle(52, 17, 205, 20));
lblField.setFont(new java.awt.Font("宋体", 0, 12));
lblField.setText("专业:");
lblField.setBounds(new Rectangle(12, 41, 40, 25));
cbField.setFont(new java.awt.Font("宋体", 0, 12));
cbField.setBorder(BorderFactory.createEtchedBorder());
cbField.setEditor(null);
cbField.setSelectedIndex(-1);
cbField.setSelectedItem(lblField);
cbField.setBounds(new Rectangle(52, 46, 205, 20));
cbField.addItem("自动化");
cbField.addItem("计算机");
cbField.addItem("物理学");
cbField.setSelectedIndex(0);
lblSex.setFont(new java.awt.Font("宋体", 0, 12));
lblSex.setText("性别:");
lblSex.setBounds(new Rectangle(14, 68, 39, 29));
rbMale.setFont(new java.awt.Font("宋体", 0, 12));
rbMale.setSelected(true);
rbMale.setText("男性");
rbMale.setBounds(new Rectangle(48, 69, 57, 25));
rbFemale.setFont(new java.awt.Font("宋体", 0, 12));
rbFemale.setText("女性");
rbFemale.setBounds(new Rectangle(107, 70, 91, 25));
jLabel1.setFont(new java.awt.Font("宋体", 0, 12));
jLabel1.setText("爱好:");
jLabel1.setBounds(new Rectangle(14, 101, 41, 16));
cbWX.setFont(new java.awt.Font("宋体", 0, 12));
cbWX.setText("文学");
cbWX.setBounds(new Rectangle(48, 96, 56, 25));
cbTY.setFont(new java.awt.Font("宋体", 0, 12));
cbTY.setText("体育");
cbTY.setBounds(new Rectangle(107, 97, 52, 25));
cbYS.setFont(new java.awt.Font("宋体", 0, 12));
cbYS.setText("艺术");
cbYS.setBounds(new Rectangle(163, 96, 52, 25));
lblContent.setFont(new java.awt.Font("宋体", 0, 12));
lblContent.setText("选取内容:");
lblContent.setBounds(new Rectangle(15, 127, 168, 16));
areaContent.setFont(new java.awt.Font("宋体", 0, 12));
areaContent.setBorder(BorderFactory.createEtchedBorder());
areaContent.setText("");
areaContent.setBounds(new Rectangle(16, 147, 369, 122));
btnCancel.setBounds(new Rectangle(209, 276, 94, 30));
btnCancel.setText("取消");
btnCancel.addActionListener(new FrameMain_btnCancel_actionAdapter(this));
btnCancel.setFont(new java.awt.Font("宋体", 0, 12));
btnOK.setBounds(new Rectangle(89, 276, 95, 31));
btnOK.setText("确定");
btnOK.addActionListener(new FrameMain_btnOK_actionAdapter(this));
btnOK.setFont(new java.awt.Font("宋体", 0, 12));
contentPane.add(txtName, null);
contentPane.add(lblName, null);
contentPane.add(cbField, null);
contentPane.add(lblSex, null);
contentPane.add(rbFemale, null);
contentPane.add(lblField, null);
contentPane.add(jLabel1, null);
contentPane.add(rbMale, null);
contentPane.add(cbWX, null);
contentPane.add(cbTY, null);
contentPane.add(cbYS, null);
contentPane.add(lblContent, null);
contentPane.add(areaContent, null);
contentPane.add(btnCancel, null);
contentPane.add(btnOK, null);
buttonGroup1.add(rbMale);
buttonGroup1.add(rbFemale);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void btnCancel_actionPerformed(ActionEvent e) {
System.exit(0);
}
void btnOK_actionPerformed(ActionEvent e) {
this.areaContent.setText("");
String userName=this.txtName.getText();
this.areaContent.append("姓名:"+(userName==null || userName.trim().length()<=0?"未指定":userName));
this.areaContent.append("\n");
this.areaContent.append("专业:"+(String)this.cbField.getSelectedItem());
this.areaContent.append("\n");
this.areaContent.append("性别:"+(this.rbMale.isSelected()?"男性":"女性"));
this.areaContent.append("\n");
this.areaContent.append("爱好:");
this.areaContent.append("\n");
boolean checked=false;
JCheckBox[] cbes=new JCheckBox[]{this.cbWX,this.cbTY,this.cbYS};
for(int i=0;i<cbes.length;i++){
if(cbes[i].isSelected()){
this.areaContent.append(cbes[i].getText());
this.areaContent.append(" ");
checked=true;
}
}
if(checked)
this.areaContent.append("\n");
}
}
class FrameMain_btnCancel_actionAdapter implements java.awt.event.ActionListener {
FrameMain adaptee;
FrameMain_btnCancel_actionAdapter(FrameMain adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCancel_actionPerformed(e);
}
}
class FrameMain_btnOK_actionAdapter implements java.awt.event.ActionListener {
FrameMain adaptee;
FrameMain_btnOK_actionAdapter(FrameMain adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOK_actionPerformed(e);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询