"增長人員"界面花了一下午構思與編寫,才作出如下的效果,感受仍是不美觀:java
package com.other.gui; import java.awt.*;工具 import java.awt.event.ActionEvent;ui import java.awt.event.ActionListener;this import java.awt.event.KeyAdapter;spa import java.awt.event.KeyEvent;orm import java.util.Vector;ci import javax.swing.*;get import javax.swing.border.*;it 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(); }
} } |