java smart_java如何操作smartart

展开全部

楼主,我写的完全符合要求62616964757a686964616fe78988e69d8331333335333162:package HomeWork;import javax.swing.*;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;public class Search extends JFrame implements ActionListener,Runnable { private ArrayList num,name,grade,sex; private BufferedReader br; private File current; private JTextField text1; private JButton search,load; private JTextArea text; JLabel status; boolean isload=false; Thread back; public Search() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } JPanel p=new JPanel(new FlowLayout(FlowLayout.CENTER)); text1=new JTextField(8); search=new JButton("查找"); search.addActionListener(this); load=new JButton("加载文件"); load.addActionListener(this); p.add(load); p.add(text1); p.add(search); getContentPane().add(p,"North"); text=new JTextArea(); text.setEditable(false); text.setBorder(BorderFactory.createTitledBorder("查询结果")); getContentPane().add(text); status=new JLabel(""); getContentPane().add(status,"South"); setTitle("Demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,300); setVisible(true); } public void loadFile() { JFileChooser chooser=new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("加载文件"); chooser.setApproveButtonText("加载"); chooser.setApproveButtonToolTipText("加载当前选中文件"); if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) { current=chooser.getSelectedFile(); status.setText("当前加载文件:"+current.getAbsolutePath()); } else return; } public void analyse() { String s=null; String [] temp=null; name=new ArrayList(); num=new ArrayList(); grade=new ArrayList(); sex=new ArrayList(); if(current==null) return; try { br=new BufferedReader(new FileReader(current)); br.readLine(); while((s=br.readLine())!=null) { temp=s.split("\t"); num.add(temp[0]); name.add(temp[1]); grade.add(temp[2]); sex.add(temp[3]); } } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this,"文件未找到"); return; } catch (IOException e) { JOptionPane.showMessageDialog(this, "读取文件发生异常!"); return; } } public void actionPerformed(ActionEvent e) { JButton btn=(JButton)e.getSource(); if (btn==load) { loadFile(); if(current==null) return; (back = new Thread(this)).start(); isload=true; } if (btn==search) { if (isload==false) { JOptionPane.showMessageDialog(this, "你尚未加载任何文件"); return; } if (text1.getText()==null||text1.getText()=="") { JOptionPane.showMessageDialog(this, "请输入要查询的内容"); } String s=text1.getText(); if(num.contains(s)) { int index=num.indexOf(s); text.setText(""); text.append("找到记录:\n"); text.append(num.get(index)+"\t"); text.append(name.get(index)+"\t"); text.append(grade.get(index)+"\t"); text.append(sex.get(index)); } else if(grade.contains(s)) { int index=num.indexOf(s); text.setText(""); text.append("找到记录:\n"); text.append(num.get(index)+"\t"); text.append(name.get(index)+"\t"); text.append(grade.get(index)+"\t"); text.append(sex.get(index)); } else if(name.contains(s)) { int index=num.indexOf(s); text.setText(""); text.append("找到记录:\n"); text.append(num.get(index)+"\t"); text.append(name.get(index)+"\t"); text.append(grade.get(index)+"\t"); text.append(sex.get(index)); } else if(sex.contains(s)) { int index=num.indexOf(s); text.setText(""); text.append("找到记录:\n"); text.append(num.get(index)+"\t"); text.append(name.get(index)+"\t"); text.append(grade.get(index)+"\t"); text.append(sex.get(index)); } else { text.setText(""); text.append("未找到记录!!"); } } } public void run() { if(name!=null) name.clear(); if(num!=null) num.clear(); if(grade!=null) grade.clear(); if(sex!=null) sex.clear(); analyse(); } public static void main(String[] args) { new Search(); }}我使用的查找文本内容为:学号 姓名 班级 性别1 张三 5 男2 李四 6 女3 王五 7 男(上面分隔符是"\t",最左边没有分隔符)%D%A

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值