我想要的是,當用戶單擊按鈕時,在Textbox
或JList
中輸入的數據或從任何地方移除的數據都會進入數組列表。用JButton JAVA將數據寫入ArrayList
我不想建立數據庫!我只想在用戶使用應用程序時存儲數據。我嘗試過所有的事情,但事件按鈕似乎需要一定的難度,代碼不應該被認真對待,它只是用於分析。
重要的是按下按鈕將數據寫入數組。 例如:
btnSaveToArray.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
ArrayList recordArray=new ArrayList();
// This variable receiveList, receives value a given selected from a JList, is far from good.
String receiveList = userList.getSelectedValue().toString();
// The variable recordArray capture this value, the goal is that this variable store it.
recordArray.add(receiveList);
// these two lines to see if I recorded the same roof but're angry, it just returns me one record element.
System.out.println(recordArray.toString());
// these two lines to see if I recorded the same roof but're angry, it just returns me one record element.
System.out.println(recordArray.size());
}
我試圖打印出數組的內容,看是否用戶的輸入被記錄,但它並沒有打印出任何東西。
感謝兄弟! :) –
歡迎您:) –