⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifymessage.java

📁 该系统主要处理班级通讯信息。 学生信息主要包括:姓名、班级、电子邮件、通讯录地址、邮编等内容。 完成以下的操作:实现通讯录的添加、修改、删除和查询
💻 JAVA
字号:
package contenct;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Hashtable;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import Person.Client;
public class ModifyMessage extends JDialog implements ActionListener
{
	  Hashtable messagetable=null;                           
	  JTextField txlnumber,tname,tphnumber,temail,tdanwei,tzhiwu;                 
	  ButtonGroup group=null;
	  JButton BegainModify,LModify,reset;
	  TXLBasInfor txlbasinfor=null;
	  FileInputStream inOne=null;
	  ObjectInputStream inTwo=null;
	  FileOutputStream outOne=null;
	  ObjectOutputStream outTwo=null;
	  File file=null;                                           
	  public ModifyMessage(File file)
	  {
	   this.file=file;
	   txlnumber=new JTextField(10);
	   tname=new JTextField(10);                                
	   tphnumber=new JTextField(10);
	   temail=new JTextField(10);
	   
	   tdanwei=new JTextField(10);
	   tzhiwu=new JTextField(10);

	   BegainModify=new JButton("开始修改");
	   LModify=new JButton("录入修改");
	   LModify.setEnabled(false);
	   reset=new JButton("重置");
	   txlnumber.addActionListener(this);
	   BegainModify.addActionListener(this);
	   LModify.addActionListener(this);
	   reset.addActionListener(this);
	   Box box1=Box.createHorizontalBox();              
	   box1.add(new JLabel("输入要修改信息的编号:",JLabel.CENTER));
	   box1.add(txlnumber);
	   box1.add(BegainModify);
	   Box box2=Box.createHorizontalBox();              
	   box2.add(new JLabel("(新)姓        名:",JLabel.CENTER));
	   box2.add(tname);
	   Box box3=Box.createHorizontalBox();              
	   box3.add(new JLabel("(新)电话号码:",JLabel.CENTER));
	   box3.add(tphnumber);
	   Box box4=Box.createHorizontalBox();              
	   box4.add(new JLabel("(新)电子邮箱:",JLabel.CENTER));
	   box4.add(temail);
	   Box box5=Box.createHorizontalBox();              
	   box5.add(new JLabel("(新)邮       编:",JLabel.CENTER));
	   box5.add(tdanwei);
	   Box box6=Box.createHorizontalBox();              
	   box6.add(new JLabel("(新)班        级:",JLabel.CENTER));
	   box6.add(tzhiwu);

	   Box boxH=Box.createVerticalBox();              
	   boxH.add(box1);
	   boxH.add(box2);
	   boxH.add(box3);
	   boxH.add(box4);
	   boxH.add(box5);
	   boxH.add(box6);

	   boxH.add(Box.createVerticalGlue());   
	   this.setBounds(100,200,660,270);
	   JPanel pCenter=new JPanel();
	   pCenter.add(boxH);
	   setLayout(new BorderLayout());
	   add(pCenter,BorderLayout.CENTER);
	   JPanel pSouth=new JPanel();
	   pSouth.add(LModify);
	   pSouth.add(reset);
	   add(pSouth,BorderLayout.SOUTH);
	   validate();
	  }
	 public void actionPerformed(ActionEvent e)
	 { 
	   if(e.getSource()==BegainModify||e.getSource()==txlnumber)
	      {
	         String number="";
	         number=txlnumber.getText();
	        
	         if(number.length()>0)
	            {
	              try {
	                    inOne=new FileInputStream(file);
	                    inTwo=new ObjectInputStream(inOne);
	                    messagetable=(Hashtable)inTwo.readObject();
	                    inOne.close();
	                    inTwo.close();
	                  }
	               catch(Exception ee)
	                   {
	                   }
	              if(messagetable.containsKey(number))          
	                 {
	            	   LModify.setEnabled(true);
	            	   TXLBasInfor cli=(TXLBasInfor)messagetable.get(number);
	                   tname.setText(cli.getName());
	                   tphnumber.setText(cli.getPhnumber());
	                   temail.setText(cli.getEmail());
	                   tdanwei.setText(cli.getDanwei());
		       		   tzhiwu.setText(cli.getZhiwu());
	                 } 
	              else
	                 { 
	            	  LModify.setEnabled(false);
	                  
	                  String warning="该编号不存在!";
	                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	                  txlnumber.setText(null);
	                  tname.setText(null);                                
	                  tphnumber.setText(null);
	                  temail.setText(null);
	                  tdanwei.setText(null);
	       		      tzhiwu.setText(null);
	                }
	            }
	        else
	            { 
	        	LModify.setEnabled(false); 
	              
	              String warning="必须要输入编号!";
	              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	              txlnumber.setText(null);
	              tname.setText(null);                                
	              tphnumber.setText(null);
	              temail.setText(null);
	              tdanwei.setText(null);
	   		      tzhiwu.setText(null);

	            }
	      } 
	  else if(e.getSource()==LModify)
	      { 
	        String number="";
	        number=txlnumber.getText();
	        if(number.length()>0)
	           {
	            try {
	                 inOne=new FileInputStream(file);
	                 inTwo=new ObjectInputStream(inOne);
	                 messagetable=(Hashtable)inTwo.readObject();
	                 inOne.close();
	                 inTwo.close(); 
	                }
	            catch(Exception ee)
	                {
	                }
	            if(messagetable.containsKey(number))          
	                {
	                  String question="该用户基本信息已存在,您想修改他(她)的基本信息吗?";
	                  
	                  JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE);
	                   
	                  String m="基本信息将被修改!";
	                  int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
	                                                 JOptionPane.INFORMATION_MESSAGE);
	                  if(ok==JOptionPane.YES_OPTION)
	                    {
	                      String name=tname.getText();
	                      String phnumber=tphnumber.getText();
	              		  String email=temail.getText();
	              		  String danwei=tdanwei.getText();
	              		  String zhiwu=tzhiwu.getText();

	                      txlbasinfor=new TXLBasInfor();
	                      txlbasinfor.setXlnumber(number);
	                      txlbasinfor.setName(name);
	                      txlbasinfor.setPhnumber(phnumber);
	                      txlbasinfor.setDanwei(danwei);
	                      txlbasinfor.setEmail(email);
	                      txlbasinfor.setZhiwu(zhiwu);
	                     try
	                      {
	                       outOne=new FileOutputStream(file);
	                       outTwo=new ObjectOutputStream(outOne);
	                       messagetable.put(number,txlbasinfor);
	                       outTwo.writeObject(messagetable);
	                       outTwo.close();
	                       outOne.close();
	                       txlnumber.setText(null);
	                       tname.setText(null);                                
	                       tphnumber.setText(null);
	                       temail.setText(null);
	                   
	                      }
	                     catch(Exception ee)
	                      { 
	                       System.out.println(ee);
	                      }
	                     LModify.setEnabled(false); 
	                   }
	                 else if(ok==JOptionPane.NO_OPTION)
	                   {
	                	 LModify.setEnabled(true);
	                   }
	               }
	             else
	               {
	                
	                 String warning="该编号没有基本信息,不能修改!";
	                 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	                 LModify.setEnabled(false); 
	               }
	           }
	        else
	           {
	              String warning="必须要输入编号!";
	              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	              LModify.setEnabled(false);
	           }
	       }
	   if(e.getSource()==reset)
	      { 
		   txlnumber.setText(null);
		   tname.setText(null);
		   tphnumber.setText(null);
		   temail.setText(null);
		   tdanwei.setText(null);
		   tzhiwu.setText(null);
	      }
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -