📄 editclientinfo.java
字号:
package catking.home.love;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public abstract class EditClientInfo extends JFrame implements ActionListener
{
protected JTextField[] tf;
protected final String[] itemNames = {"编号","姓名","性别","系别","年龄"};
private final String[] buttonNames = {"确定","清除","退出"};
private final String[] checkInfo = {
"十位数字",
"不超过4个汉字",
"",
"您所在的院系",
"1~150岁"};
public EditClientInfo(String title,String EditInfo)
{
super(title);
this.setSize(400,300);
Container c = this.getContentPane();
c.setLayout(new GridLayout(9,1,2,0));
JLabel info = new JLabel(EditInfo,SwingConstants.CENTER);
c.add(info);
int len = itemNames.length;
tf = new JTextField[len];
for(int i =0; i< len; ++i)
{
JLabel item = new JLabel(itemNames[i]);
tf[i] = new JTextField(20);
tf[i].setBackground(Color.WHITE);
JLabel check = new JLabel(checkInfo[i]);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(item,BorderLayout.WEST);
panel.add(tf[i],BorderLayout.CENTER);
panel.add(check,BorderLayout.EAST);
c.add(panel);
}
//空行
c.add(new JPanel());
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridLayout(1,3,2,0));
for(int i=0; i < buttonNames.length; ++i )
{
JButton button = new JButton(buttonNames[i]);
button.addActionListener(this);
buttonPane.add(button);
}
c.add(buttonPane);
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int temp = -1;
for(int i =0; i < buttonNames.length; ++i)
{
if(buttonNames[i].equals(e.getActionCommand()))
{
temp = i;
break;
}
}
switch(temp)
{
//确定
case 0:
isConfirm();
break;
//清除
case 1:
isClear();
break;
//退出
case 2:
isQuit();
break;
}
}
protected void isClear()
{
for(int i =1; i < tf.length; ++i)
{
tf[i].setText("");
tf[i].repaint();
}
}
private void isQuit()
{
if(JOptionPane.showConfirmDialog(null,
"Are you sure to quit?", "Confirm",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE)
== JOptionPane.YES_OPTION)
this.dispose();
}
protected abstract void isConfirm();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -