JTextField 输出
JTextField Outputting
如何在 JTextField 中输出数字?我需要在输入时添加年龄并将其显示给他。
age = new JTextField();
age.setBounds(10, 133, 108, 20);
contentPane.add(age);
age.setColumns(10);
textArea = new JTextField();
textArea.setBounds(10, 198, 298, 20);
contentPane.add(textArea);
JButton btnDisplayWelcome = new JButton("Submit");
btnDisplayWelcome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String first = firstname.getText();
String last = lastname.getText();
textArea.setText("Welcome " + first + ", " + last + " of ");
}
});
How do you output a number in the JTextField?
有一个setText
方法可以让你修改它的内容。
age.setText(String.valueOf(950));
如何在 JTextField 中输出数字?我需要在输入时添加年龄并将其显示给他。
age = new JTextField();
age.setBounds(10, 133, 108, 20);
contentPane.add(age);
age.setColumns(10);
textArea = new JTextField();
textArea.setBounds(10, 198, 298, 20);
contentPane.add(textArea);
JButton btnDisplayWelcome = new JButton("Submit");
btnDisplayWelcome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String first = firstname.getText();
String last = lastname.getText();
textArea.setText("Welcome " + first + ", " + last + " of ");
}
});
How do you output a number in the JTextField?
有一个setText
方法可以让你修改它的内容。
age.setText(String.valueOf(950));