I'm making a simple kg to pounds converter and I have a textfield which says "kgs here" and when the user types the input, it's getting appended, but not overwritten. Please help.
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class UnitConvertKg {
JFrame f;
JPanel p;
JButton b1;
JTextField tf1,tf2;
UnitConvertKg(){
f=new JFrame("UnitConvertKg");
p=new JPanel();
tf1=new JTextField("Kg here");
//this is predefined text and I want that this gets overwritten when t //user types in kgs.
tf2=new JTextField(" ");
b1=new JButton("CONVERT");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
double d = Double.parseDouble(tf1.getText())*2.204;
tf2.setText(String.valueOf(d));
}
});
p.add(tf1);
p.add(tf2);
p.add(b1);
p.setForeground(Color.blue);
f.add(p);
f.setSize(400,400);
}