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

📄 delmessage.java

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

import javax.swing.*;
import javax.swing.event.*;

import contenct.TXLBasInfor;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class DelMessage extends JDialog implements ActionListener
{
	Hashtable messagetable=null;                           
	  JTextField txlnumber,tname,tphnumber,temail,tdanwei,tzhiwu;               
	  JButton delate;
	  ButtonGroup group=null;
	  FileInputStream inOne=null;
	  ObjectInputStream inTwo=null;
	  FileOutputStream outOne=null;
	  ObjectOutputStream outTwo=null;
	  File file=null;                                           
	  public DelMessage(File file)
	  {
	   this.file=file;
	   txlnumber=new JTextField(10);
	   delate=new JButton("删除");
	   txlnumber.addActionListener(this);
	   delate.addActionListener(this);
	   tname=new JTextField(10);
	   tname.setEditable(false);
	   tphnumber=new JTextField(10);
	   tphnumber.setEditable(false);
	   temail=new JTextField(10);
	   temail.setEditable(false);
	   tdanwei=new JTextField(10);
	   tdanwei.setEditable(false);
	   tzhiwu=new JTextField(10);
	   tzhiwu.setEditable(false);

	   Box box1=Box.createHorizontalBox();              
	   box1.add(new JLabel("输入要删除的编号:",JLabel.CENTER));
	   box1.add(txlnumber);
	   box1.add(delate);
	   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);
	   validate();
	  }
	 public void actionPerformed(ActionEvent e)
	  {
	    if(e.getSource()==delate||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))          
	                 {
	            	  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());
	           

	                  String m="确定要删除该编号及全部信息吗?";
	                  int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
	                                                 JOptionPane.QUESTION_MESSAGE);
	                  if(ok==JOptionPane.YES_OPTION)
	                     {
	                	  messagetable.remove(number);
	                       try
	                        {
	                          outOne=new FileOutputStream(file);
	                          outTwo=new ObjectOutputStream(outOne);
	                          outTwo.writeObject(messagetable);
	                          outTwo.close();
	                          outOne.close();
	                          txlnumber.setText(null);
	                          tname.setText(null);                                
	                          tphnumber.setText(null);
	                          temail.setText(null);
	                          tdanwei.setText(null);
	    	       		      tzhiwu.setText(null);
	                        }
	                       catch(Exception ee)
	                        { 
	                         System.out.println(ee);
	                        }
	                     }
	                   else if(ok==JOptionPane.NO_OPTION)
	                     {
	                	   txlnumber.setText(null);
	                	   tname.setText(null);
	                	   tphnumber.setText(null);
	                	   temail.setText(null);
	                	   tdanwei.setText(null);
	 	       		       tzhiwu.setText(null);
	                     }
	                 }
	              else
	                 { 
	                  String warning="该编号不存在!";
	                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	                 }
	            }
	        else
	            { 
	              String warning="必须要输入编号!";
	              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
	            }
	      } 
	  }
	}

⌨️ 快捷键说明

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