"增加人员"界面花了一下午构思与编写,才做出以下的效果,感觉还是不美观:
package com.other.gui; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.Vector; import javax.swing.*; import javax.swing.border.*; import Experience_ALL.NewJFrame; import com.mhl.tools.MyTools; import com.mhl.view.UserLogin; public class Log_Add extends JFrame implements ActionListener{
JLabel JL1,JL2,JL3,JL4,JL5,JL6,JL7,JL8; JLabel JL9,JL10,JL11,JL12,JL13,JL14,JL15,JL16,JL17; JButton JB1,JB2,JB3,JB4,JB5,JB6,JB7; JTextField JT1,JT2,JT3,JT4,JT5,JT6,JT7; JTextField JT8,JT9,JT10,JT11,JT12,JT13; JRadioButton JR1,JR2,JR3,JR4,JR5,JR6,JR7; ButtonGroup BG1; JComboBox JC1,JC2,JC3,JC4,JC5,JC6; JTextField editor; JPanel A1,B1,B2; public Log_Add() {
setLayout(new GridLayout(2, 1)); A1 = new JPanel(); A1.setLayout(new GridLayout(3, 1));
A1.add(showBorder1(new TitledBorder("登陆信息"))); A1.add(showBorder2(new TitledBorder("权限信息"))); A1.add(showBorder4(new TitledBorder("最终信息"))); add(showBorder3(new TitledBorder("基本信息"))); add(A1);
int width = 550; int height = 480; this.setSize(width,height); this.setTitle("增加人员"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Toolkit tk = this.getToolkit(); //得到窗口工具条 Dimension dm = tk.getScreenSize(); //设置程序的大小 this.setLocation((int)(dm.getWidth()-width)/2,(int)(dm.getHeight()-height)/2);//显示在屏幕中央 this.setResizable(false); this.setVisible(true); } public JPanel showBorder4(Border b) { JPanel jp = new JPanel(); jp.setLayout(null);
JB1 = new JButton("确定(Y)"); JB1.setMnemonic('Y'); JB1.setBounds(145, 25, 90, 32); JB1.addActionListener(this); JB2 = new JButton("取消(N)"); JB2.setBounds(285, 25, 90, 32); JB1.setMnemonic('N'); JB2.addActionListener(this); jp.add(JB1); jp.add(JB2); jp.setBorder(b); return jp; }
public JPanel showBorder1(Border b) { JPanel jp = new JPanel(); jp.setLayout(null); //jp.setLayout(new GridLayout(3,2,5,5));
JL1 = new JLabel("用户姓名",JLabel.CENTER); JL1.setBounds(5, 15, 90, 25); JT1 = new JTextField(10); JT1.setBounds(85, 15, 90, 25);
JL2 = new JLabel("用户帐号",JLabel.CENTER); JL2.setBounds(165, 15, 90, 25); JT2 = new JTextField(10); JT2.setBounds(240, 15, 90, 25);
JL3 = new JLabel("用户密码",JLabel.CENTER); JL3.setBounds(320, 18, 90, 25); JT3 = new JTextField(10); JT3.setBounds(400, 18, 90, 25);
JL4 = new JLabel("组 别",JLabel.CENTER); JL4.setBounds(5, 45, 90, 25);
Vector<String> tempu=new Vector<String>();
tempu.add("MI"); tempu.add("CAM"); tempu.add("治具"); tempu.add("菲林房"); tempu.add("其它");
JC1 = new JComboBox<String>(tempu); //将JComboBox设成是可编辑时,以下的不能有 // JC1.setFocusable(false); JC1.setBounds(85, 45, 90, 25); JC1.setEditable(true);//将JComboBox设成是可编辑的. ComboBoxEditor editor = JC1.getEditor(); String defaultMessage = "MI"; JC1.configureEditor(editor, defaultMessage); JL5 = new JLabel("职 位",JLabel.CENTER); JL5.setBounds(165, 45, 90, 25); JT5 = new JTextField(10); JT5.setBounds(240, 45, 90, 25);
jp.add(JL1); jp.add(JT1); jp.add(JL2); jp.add(JT2); jp.add(JL3); jp.add(JT3);
jp.add(JL4); jp.add(JC1);
jp.add(JL5); jp.add(JT5);
jp.setBorder(b); return jp; } public Boolean isEditable() { return true; } public JPanel showBorder2(Border b) { JPanel jp = new JPanel(); //jp.setLayout(new FlowLayout()); jp.setLayout(new GridLayout(3,2,5,2)); JR1 = new JRadioButton("访客权限",true); JR2 = new JRadioButton("普通权限",true); JR3 = new JRadioButton("高级权限",true); JR4 = new JRadioButton("管理员权限",true);
BG1 = new ButtonGroup(); BG1.add(JR1); BG1.add(JR2); BG1.add(JR3); BG1.add(JR4);
jp.add(JR1); jp.add(JR2); jp.add(JR3); jp.add(JR4);
jp.setBorder(b); return jp; } public JPanel showBorder3(Border b) { JPanel jp = new JPanel(); //jp.setLayout(new FlowLayout()); jp.setLayout(new GridLayout(6,2,5,5)); JL7 = new JLabel("入职日期",JLabel.CENTER); JT7 = new JTextField(10); JL8 = new JLabel("联系电话",JLabel.CENTER); JT8 = new JTextField(10); JL9 = new JLabel("出生年月",JLabel.CENTER); JT9 = new JTextField(10); JL10 = new JLabel("身份证号",JLabel.CENTER); JT10 = new JTextField(10); JL11 = new JLabel("婚姻状况",JLabel.CENTER); Vector<String> tempk=new Vector<String>();
tempk.add("已"); tempk.add("否");
JC5 = new JComboBox<String>(tempk); JC5.setFocusable(false); JC5.setOpaque(false); JC5.setBackground(Color.white); JC5.setFont(MyTools.f2);
JL12 = new JLabel("性 别",JLabel.CENTER); Vector<String> tempu=new Vector<String>();
tempu.add("男"); tempu.add("女");
JC2 = new JComboBox<String>(tempu); JC2.setFocusable(false); JC2.setOpaque(false); JC2.setBackground(Color.white); JC2.setFont(MyTools.f2);
JL13 = new JLabel("年 龄",JLabel.CENTER); JT11 = new JTextField(10); JL14 = new JLabel("学 历",JLabel.CENTER); Vector<String> tempx=new Vector<String>();
tempx.add("高中"); tempx.add("大专"); tempx.add("本科"); tempx.add("其它");
JC3 = new JComboBox<String>(tempx); JC3.setEditable(true);//将JComboBox设成是可编辑的. ComboBoxEditor editor = JC3.getEditor(); String defaultMessage = "大专"; JC3.configureEditor(editor, defaultMessage);
JL15 = new JLabel("民 族",JLabel.CENTER); Vector<String> tempy=new Vector<String>();
tempy.add("汉族"); tempy.add("其它"); JC4 = new JComboBox<String>(tempy); JC4.setEditable(true);//将JComboBox设成是可编辑的. ComboBoxEditor editorc4 = JC4.getEditor(); String defaultMessagec4 = "汉族"; JC4.configureEditor(editorc4, defaultMessagec4);
JL16 = new JLabel("住 址",JLabel.CENTER); JT12 = new JTextField(10); JL17 = new JLabel("备 注",JLabel.CENTER); JT13 = new JTextField(10);
jp.add(JL7); jp.add(JT7);
jp.add(JL8); jp.add(JT8); jp.add(JL9); jp.add(JT9); jp.add(JL10); jp.add(JT10); jp.add(JL11); jp.add(JC5); jp.add(JL12); jp.add(JC2); jp.add(JL13); jp.add(JT11); jp.add(JL14); jp.add(JC3); jp.add(JL15); jp.add(JC4);
jp.add(JL17); jp.add(JT13);
jp.add(JL16); jp.add(JT12); jp.setBorder(b); return jp; }
public static void main(String[] args) { new Log_Add();
} @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == this.JB1) { System.out.println("fdgdfg+++");
}else if(e.getSource() == this.JB2){ this.dispose(); }
} } |