几天前我开始学习编程。我试着制作一个计算器,但我有一个问题: 我不知道如何制作退格JButton。
buusun.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
tf.setText(text.getText().length()-1);
}
});
有什么想法吗?
答案 0 :(得分:3)
试试这个:
buusun.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
tf.setText(text.getText().substring(0, text.getText().length() - 1));
}
});
它使用string.substring(start, end)
方法
请注意,您可能需要调整所使用的确切变量,因为我不确定您是否需要从tf
或text
获取值,但这应该提供您想要的内容的要点。