📄 vipinfo.java
字号:
package classfile;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Vector;
class VIPInfo extends JFrame implements ActionListener,ListSelectionListener{
private int flag=1;
private static Vector v = new Vector();
static JLabel vid,vname,vage,vdate,vtype,jlyear,jlmonth,jlday;
static JTextField vtid,vtname,vtage,vtdate,vttype;
static JComboBox jcyear,jcmonth,jcday;
static JList jls=new JList();
static JScrollPane js;
static JPanel jp1,jp2;
static JButton jb1,jb2,jb3;
VIPInfo(){
vid = new JLabel("V I P编号 :");
vname = new JLabel("姓 名 :");
vage = new JLabel("家庭住址 :");
vdate = new JLabel("出生日期 :");
vtype = new JLabel("职 业 :");
jlyear = new JLabel("年");
jlmonth = new JLabel("月");
jlday = new JLabel("日");
vtid = new JTextField(8);
InputVerifier iv = new InputVerifier(){
public boolean verify(JComponent input){
JTextField t = (JTextField)input;
try{
Integer.parseInt(t.getText());
}catch(Exception e){
return false;
}
if(t.getText().length() > 4)
return false;
return true;
}
};
vtid.setInputVerifier(iv);
vtname = new JTextField(18);
vtage = new JTextField(18);
vtdate = new JTextField(18);
vttype = new JTextField(18);
jcyear = new JComboBox();
for(int i=1950;i<2005;i++){
jcyear.addItem(""+i);
}
jcmonth = new JComboBox();
for(int i=1;i<=12;i++){
if(i<10)
jcmonth.addItem("0"+i);
else
jcmonth.addItem(""+i);
}
jcday = new JComboBox();
for(int i=1;i<=30;i++){
if(i<10)
jcday.addItem("0"+i);
else
jcday.addItem(""+i);
}
jb1 = new JButton("清空");
jb2 = new JButton("保存");
jb3 = new JButton("删除");
jp1 = new JPanel();
jp2 = new JPanel();
}
VIPInfo(JDesktopPane jd){
if((jd.getAllFrames().length)>=1)
return;
setLayout(new BorderLayout());
JInternalFrame vip = new JInternalFrame("VIP基本信息",false,true,false,true);
new VIPInfo();
readData();
js = new JScrollPane(jls);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jls.addListSelectionListener(this);
jp1.add(js);
jp2.add(vid);jp2.add(vtid);jp2.add(new JLabel("(不大于4位的数字)"));
jp2.add(vname);jp2.add(vtname);
jp2.add(vage);jp2.add(vtage);
jp2.add(vdate);jp2.add(jcyear);jp2.add(jlyear);jp2.add(jcmonth);jp2.add(jlmonth);jp2.add(jcday);jp2.add(jlday);//jp2.add(vtdate);
jp2.add(vtype);jp2.add(vttype);
jp2.add(jb1);jp2.add(jb2);jp2.add(jb3);
vip.add(jp1,BorderLayout.WEST);
vip.add(jp2,BorderLayout.CENTER);
jd.add(vip);
vip.setSize(390,220);
vip.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="清空"){
clear();
}
if(e.getActionCommand()=="保存"){
if(flag==1){
if(vtid.getText().length()!=0 && vtname.getText().length()!=0 && vtage.getText().length()!=0 && vttype.getText().length()!=0){
MakeDatebase conn = new MakeDatebase();
conn.connectionSql();
String sql="insert into VIPID(vip_no,vip_name,vip_age,vip_date,vip_type) values(" + vtid.getText() + ",'" + vtname.getText() + "'," + vtage.getText() + ",'" + jcyear.getSelectedItem() + "-"+ jcmonth.getSelectedItem() + "-"+ jcday.getSelectedItem() + "','" + vttype.getText() + "')";
conn.updateDate(sql);
if(MakeDatebase.dataCleck){
JOptionPane.showMessageDialog(null,"添加成功");
vtid.setEditable(false);
}
readData();
conn.closeConnection();
}
else{
JOptionPane.showMessageDialog(null,"数据填写不完整");
}
}
else{
MakeDatebase conn = new MakeDatebase();
conn.connectionSql();
String sql="update VIPID set vip_name=" + "'" + vtname.getText() + "',vip_age=" + vtage.getText() + ",vip_date='" + jcyear.getSelectedItem() + "-" + jcmonth.getSelectedItem() + "-" + jcday.getSelectedItem() + "',vip_type='" + vttype.getText() + "' where vip_no=" + vtid.getText();
conn.updateDate(sql);
JOptionPane.showMessageDialog(null,"修改成功");
vtid.setEditable(false);
conn.closeConnection();
}
}
if(e.getActionCommand()=="删除"){
MakeDatebase conn = new MakeDatebase();
conn.connectionSql();
String sql = "delete from VIPID where vip_no=" + vtid.getText();
int flag = JOptionPane.showConfirmDialog(null,"确定要删除吗?","删除提示",JOptionPane.YES_NO_OPTION);
if(flag == JOptionPane.YES_OPTION){
vtid.setEditable(true);
conn.updateDate(sql);
clear();
readData();
}
conn.closeConnection();
}
}
public void valueChanged(ListSelectionEvent e){
vtid.setEditable(false);
flag=2;
if(!e.getValueIsAdjusting()){
MakeDatebase conn = new MakeDatebase();
conn.connectionSql();
String sql = "select vip_no,vip_name,vip_age,vip_date,vip_type from VIPID where vip_no=" + Integer.parseInt(((String)jls.getSelectedValue()).substring(6));
conn.selectDate(sql);
try {
while(conn.rct.next()){
vtid.setText(conn.rct.getString(1));
vtname.setText(conn.rct.getString(2));
vtage.setText(conn.rct.getString(3));
String crg = conn.rct.getString(4);
String year = crg.substring(0,4);
String month = crg.substring(5,7);
String day = crg.substring(8,10);
jcyear.setSelectedItem(year);
jcmonth.setSelectedItem(month);
jcday.setSelectedItem(day);
vttype.setText(conn.rct.getString(5));
}
}
catch (Exception ex) {
}
conn.connectionSql();
}
}
public void ifLoad(String no,String name,String age,String date,String type){
try{
flag = 2;
new VIPInfo().readData();
js = new JScrollPane(jls);
JDialog jframe = new JDialog(this,"VIP基本信息",true);
JPanel jpanel = new JPanel();
vtid.setText(no);
vtname.setText(name);
vtage.setText(age);
jcyear.setSelectedItem(date.substring(0,4));
jcmonth.setSelectedItem(date.substring(5,7));
jcday.setSelectedItem(date.substring(8,10));
vttype.setText(type);
js = new JScrollPane(jls);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jls.addListSelectionListener(this);
jp1.add(js);
jp2.add(vid);jp2.add(vtid);jp2.add(new JLabel("(不大于4位的数字)"));
jp2.add(vname);jp2.add(vtname);
jp2.add(vage);jp2.add(vtage);
jp2.add(vdate);jp2.add(jcyear);jp2.add(jlyear);jp2.add(jcmonth);jp2.add(jlmonth);jp2.add(jcday);jp2.add(jlday);//jp2.add(vtdate);
jp2.add(vtype);jp2.add(vttype);
jp2.add(jb1);jp2.add(jb2);jp2.add(jb3);
vtid.setEditable(false);
jpanel.setLayout(new BorderLayout());
jpanel.add(jp1,BorderLayout.WEST);
jpanel.add(jp2,BorderLayout.CENTER);
jframe.add(jpanel);
jframe.setSize(390,220);
Commonable.screenCenter(jframe);
Commonable.screenCenter(jframe);
jframe.setVisible(true);
}
catch(Exception e){
System.out.println ("加载失败");
}
}
private void readData(){
MakeDatebase conn = new MakeDatebase();
conn.connectionSql();
String sql = "select vip_no from VIPID";
conn.selectDate(sql);
try {
vtid.setEditable(true);
Vector v = new Vector();
v.removeAllElements();
while(conn.rct.next()){
v.add("VIP编号:" + conn.rct.getString(1));
}
try{
jls.setListData(v);
}catch(Exception ee){
clear();
}
}
catch (Exception ex) {
System.out.println ("数据加载出错");
}
finally{
conn.closeConnection();
}
}
private void clear(){
vtid.setText("");
vtname.setText("");
vtage.setText("");
vtdate.setText("");
vttype.setText("");
vtid.setEditable(true);
flag=1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -