類搜索擴展了 JFrame{private Container container;private Font font,font2;private JLabel label;private JTextField textField;private JButton search;private JTextArea textarea;search(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100,40,600,380); this.setTitle("SEARCH"); container = this.getContentPane(); container.setLayout(null); font = new Font("Courier New",Font.BOLD,14); font2 = new Font("Courier New",Font.BOLD,18); label = new JLabel("SEARCH : "); label.setBounds(40,20,150,50); label.setFont(font); container.add(label); textField = new JTextField(); textField.setBounds(140,25,200,40); textField.setFont(font2); container.add(textField); search = new JButton("SEARCH"); search.setBounds(370,25,110,37); search.setFont(font); container.add(search); textarea = new JTextArea(); textarea.setBounds(40,85,500,200); textarea.setFont(font2); container.add(textarea); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String x = textField.getText(); try{ File file = new File("allinfo.txt"); BufferedReader reader = new BufferedReader(new FileReader(file)); String s = reader.readLine(); while(s!=null){ String string[] = s.split(" "); String a = string[0]; String b = string[1]; String c = string[2]; String d = string[3];這是一個搜索選項,我可以在其中搜索一個人的名字。如果有兩個人同名,則兩個選項都應顯示在文本區域中,但文本區域僅顯示一個人的詳細信息。但控制臺正在打印所有個人詳細信息。我需要有關如何在文本區域中顯示所有詳細信息的幫助。
添加回答
舉報
0/150
提交
取消