问题描述
importjava.awt.*;importjava.awt.event.*;importjava.io.File;importjava.io.IOException;importjava.io.*;//importjava.util.*;importjavax.swing.*;importjavax.swing.text.*;importjavax.imageio.ImageIO;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JLabel;importjavax.swing.JScrollPane;classcard{staticStringname0;staticStringphone0;//privatestaticStringqqcom0;staticStringnote0;staticStringcompany0;publiccard(Stringname0,Stringphone0,Stringqqcom0,Stringnote0,Stringcompany0){super();this.name0=name0;this.phone0=phone0;this.qqcom0=qqcom0;this.note0=note0;this.company0=company0;}staticStringgetName(){returnname0;}publicvoidsetName(Stringname0){this.name0=name0;}staticStringgetPhone(){//publicreturnphone0;}publicvoidsetPhone(Stringphone0){this.phone0=phone0;}staticStringgetQqcom(){returnqqcom0;}publicvoidsetQqcom(Stringqqcom0){this.qqcom0=qqcom0;}staticStringgetNote(){returnnote0;}publicvoidsetNote(Stringnote0){this.note0=note0;}staticStringgetCompany(){returncompany0;}publicvoidsetCompany(Stringcompany0){this.company0=company0;}}publicclassmycard{publicstaticvoidmain(Stringargs[]){JFrameframe=newJFrame("名片管理系统");ContainercontentPane=frame.getContentPane();contentPane.setBackground(Color.WHITE);JPanelpanel=newJPanel();panel.setLayout(newBorderLayout());JLabellabel0=newJLabel("名片管理簿",JLabel.CENTER);Fontfont=newFont("楷体",1,40);label0.setFont(font);panel.add(label0,BorderLayout.NORTH);JLabellabel1=newJLabel();ImageIconimg1=newImageIcon("card.jpg");label1.setIcon(img1);finalJTextFieldname=newJTextField();finalJTextFieldphone=newJTextField();finalJTextFieldqqcom=newJTextField();finalJTextFieldnote=newJTextField();finalJTextFieldcompany=newJTextField();name.setOpaque(false);phone.setOpaque(false);qqcom.setOpaque(false);note.setOpaque(false);company.setOpaque(false);name.setBounds(238,50,117,25);phone.setBounds(230,98,147,25);qqcom.setBounds(222,130,168,25);note.setBounds(225,162,125,25);company.setBounds(250,223,185,25);label1.add(name);label1.add(phone);label1.add(qqcom);label1.add(note);label1.add(company);panel.add(label1,BorderLayout.CENTER);JPanelpanel4=newJPanel();panel4.setLayout(newBorderLayout());JLabellabel2=newJLabel("名片列表:");Fontfont1=newFont("楷体",1,20);label2.setFont(font1);panel4.add(label2,BorderLayout.NORTH);//finalDefaultListModellistmodel=newDefaultListModel();finalListlist=newList();//list.setBounds(0,500,500,45);JScrollPanejsp=newJScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);panel4.add(jsp,BorderLayout.CENTER);JPanelpanel2=newJPanel();JPanelpanel3=newJPanel();panel2.setLayout(newBorderLayout());JButtonbutton1=newJButton("添加");JButtonbutton2=newJButton("清空");panel3.add(button1);panel3.add(button2);panel2.add(panel3,BorderLayout.NORTH);JTextAreaarea0=newJTextArea("说明:在上述名片中输入相关信息后,点击添加按钮,职务与姓名即可录入名片列表。点击清空n按钮可以将刚录入名片的信息清除。当要查看某人的相关信息时,只要在名片列表中找到其姓n名,然后双击,其具体信息就会显示在名片中。");area0.setEditable(false);panel2.add(area0,BorderLayout.CENTER);button1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){if(name.getText().equalsIgnoreCase("")){JOptionPane.showMessageDialog(null,"无法添加名字为空的记录","Message",JOptionPane.INFORMATION_MESSAGE);name.setText("");phone.setText("");qqcom.setText("");note.setText("");company.setText("");return;}else{list=name.getText();}}});button2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){name.setText("");phone.setText("");qqcom.setText("");note.setText("");company.setText("");}});//ArrayList<card>alt;list.addActionListener(newActionListener()//list.addListSelectionListener(newListSelectionListener(){@OverridepublicvoidactionPerformed(ActionEvente){Stringstring=list.toString();//for(cardc:alt){if(c.getName().equals(string)){name.setText(c.getName());phone.setText(c.getPhone());//getInstance().qqcom.setText(c.getQqcom());note.setText(c.getNote());company.setText(c.getCompany());}}}});frame.getContentPane().add(panel,BorderLayout.NORTH);frame.getContentPane().add(panel4);frame.getContentPane().add(panel2,BorderLayout.SOUTH);frame.setSize(506,600);frame.setVisible(true);frame.setResizable(false);//frame.setResizable(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}说明:就是编译、运行程序后,出来一个界面,在界面里输入姓名,手机号信息,然后点击添加按钮,刚才输入的信息中的姓名就会出现在列表中,当清空文本域后,在列表中双击一个姓名,其详细信息就会出现在文本域中我使用的软件是JDK