为了账号安全,请及时绑定邮箱和手机立即绑定

在控制台中显示多个详细信息,但不在文本区域中显示。

在控制台中显示多个详细信息,但不在文本区域中显示。

万千封印 2023-10-18 20:53:05
类搜索扩展了 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];这是一个搜索选项,我可以在其中搜索一个人的名字。如果有两个人同名,则两个选项都应显示在文本区域中,但文本区域仅显示一个人的详细信息。但控制台正在打印所有个人详细信息。我需要有关如何在文本区域中显示所有详细信息的帮助。
查看完整描述

1 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

代替

textarea.setText(f);

使用

textarea.append(f + "\n");


查看完整回答
反对 回复 2023-10-18
  • 1 回答
  • 0 关注
  • 63 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信