![](/img/trans.png)
[英]How to make workbook(outputstream) write all rows to an xlsx file instead of only one row?
[英]How to write in one textField instead of all fields
我正在開發一個復數計算器。 我創建了5個文本字段,當我單擊按鈕以輸入數字時,它將在所有字段上顯示文本,因此在所有字段上都將是相同的數字。
這是一個按鈕的代碼:
JButton btn0 = new JButton("0");
btn0.setFont(new Font("Tahoma",Font.BOLD,15));
btn0.setBounds(199, 228, 80, 30);
frame.getContentPane().add(btn0);
btn0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String num = textField.getText() + btn0.getText();
textField.setText(num);
String num1 = field.getText() + btn0.getText();
field.setText(num1);
String num2 = field2.getText() + btn0.getText();
field2.setText(num2);
String num3 = field3.getText() + btn0.getText();
field3.setText(num3);
String num4 = field4.getText() + btn0.getText();
field2.setText(num4);
}
});
當用戶單擊btn0
,將執行您在此處提到的actionPerformed()
方法。 在這個actionPerformed()
方法中,您正在設置所有文本字段( textField
, field
, field2
等)的值。 因此,在所有文本字段中設置文本也就不足為奇了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.