且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 Jtextfield 向数组列表添加数字

更新时间:2023-12-04 09:48:04

  • 列个清单
  • 列表项
  • 制作一个文本框
  • 为按钮添加监听器
  • 从文本字段或文本区域获取文本添加到数组列表对象
  • 这是您需要做的所有工作:

    Here is all the work you need to do:

ArrayList<String> arrayObject= new ArrayList<String>();
JButton button = new JButton();
JtextField textBox = new JtextField ();

  button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
          //inside your action listener:
             String add_item_to_array = textBox.getText().trim();
             arrayObject.add(add_item_to_array);


        }
    });