我要如何單獨的一個字符串使用, 提取碼如何將字符串轉換成大量的單子,
JTextField stockNo = new JTextField(7);
JTextField quantity = new JTextField(7);
TextArea information = new TextArea(5, 50);
JButton purchaseBtn = new JButton("Purchase");
purchaseBtn.addActionListener(this);
//set up gui ect
String key = stockNo.getText();
String quantityTxt = quantity.getText();
String info = "\n\nName: " + StockData.getName(key) +
"\nPrice: £" + (StockData.getPrice(key)) +
"\nNumber in stock: " + StockData.getQuantity(key) +
"\nNumber to buy: " + quantityTxt;
information.append(info);
當用戶點擊purchaseBtn,信息應保持爲此在.append
之前,我需要的是以某種方式從信息文本區域提取信息,並用它來計算,有人告訴我數組列表,但不知道。
如
//in text area
Name: shirt //user inputed 1 for key
Price: £5.00
Number in stock: 15
Number to buy 7 // user inputed 7 for quantity
Name: socks //user inputed 2 for key
Price: £2.50
Number in stock: 4
Number to buy 1 // user inputed 7 for quantity
Name: trouser //user inputed 3 for key
Price: £24.00
Number in stock: 19
Number to buy 4 // user inputed 7 for quantity
我需要把它保存每一行的關鍵和數量,這樣我就可以用它以後做的事情,並且能夠說int totalcost = //the price of all of them added together in our example £31.50
,
有什麼問題請參見How to use Lists?我們不會爲你寫代碼。你遇到什麼具體的部分? – tjameson 2013-03-19 23:50:06
你的問題沒有一個可以理解。 – 2013-03-19 23:50:08