1
我有一個按鈕上的if
聲明,點擊按鈕會將JTextField
更改爲£35.00。我也希望能夠使用JRadioButton
,點擊後將JTextField
更改爲70.00英鎊。更新按鈕上的JTextField按
代碼:
sesh1.addActionListener(e2->{
if (sesh1.isSelected())
tSesh1.setText("35.00");
});
tSesh1是文本字段。
另外:
//ActionListener for saving session info to text file
JButton submitInvoice = new JButton ("Submit");
sPanel.add(submitInvoice);
submitInvoice.addActionListener(e9->{
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("RegInvoice_0to2.txt",true));
bw.write("---------------Booking Invoice---------------");
bw.write("\r\n");
bw.write("---------------0 To 2 Year Olds--------------");
bw.write("\r\n");
bw.write("[Sessions Selected]");
bw.write("\r\n");
bw.write("All Day: £"); bw.write(tSesh1.getText());
bw.write(" On");
//
//Displays the days selected for All Day Sessions
if(mon1.isSelected()){
bw.write(" Monday"); bw.write(" ");
tSesh1.setText("70.00"); // This wont change the text field
}