我期待從JTextField
的所有數據,並將它們添加在一起,然後將答案輸出到文本文件。基於JTextFields的計算
static class Session implements ActionListener {
public void actionPerformed (ActionEvent e){
JButton submitInvoice = new JButton ("Submit");
sPanel.add(submitInvoice);
submitInvoice.addActionListener(e8->{
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("RegInvoice.txt"));
bw.write("---------------Booking Invoice---------------");
bw.write("\r\n");
bw.write("All Day: "); bw.write(tSesh1.getText());
bw.write("\r\n");
bw.write("Morning: "); bw.write(tSesh2.getText());
bw.write("\r\n");
bw.write("Lunch: "); bw.write(tSesh3.getText());
bw.write("\r\n");
bw.write("Afternoon: "); bw.write(tSesh4.getText());
bw.write("\r\n");
bw.write("Pre School: "); bw.write(tSesh5.getText());
bw.write("\r\n");
bw.write("Full Holiday Care: "); bw.write(tSesh6.getText());
bw.close();
}catch(Exception ex){
ex.printStackTrace();
}
});
}
}
上面的代碼取tSesh1,tSesh2,tSesh3,tSesh4,tSesh5並將其打印到文件中。但我需要將每個JTextField
加在一起。
你是什麼意思 「添加的每個JTextField的一起」 是什麼意思?舉例說明每個框的內容以及您試圖獲得的結果。 – FredK
JTextField包含一個數字。這些號碼由用戶輸入。因此,在JTextField 1中,數字是5,在JTextField中數字是1.我希望這兩個數字加在一起總共爲6 – DeeMoMo
'Integer.parseInt(tSesh1.getText())+ Integer.parseInt(tSesh2。 getText())' – rdonuk