While building a simple currency converter app setText is not setting the value in JLabel.(I am using eclipse ide in windows).I have called Action Listener for setting button and also had converted the getText to int with the help of parseInt.
My code is given below.
import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class CurrencyConverter implements ActionListener { JButton button1,button2; JLabel display2,display3; JTextField display; public CurrencyConverter() { var frame=new JFrame(); frame.setLayout(null); frame.setBounds(300, 300, 400, 300); frame.getContentPane().setBackground(Color.BLACK); display=new JTextField(); display.setBounds(50, 30, 300, 50); display.setBackground(Color.yellow); display.setForeground(Color.black); frame.add(display); button1=new JButton("TO INR"); button1.setBounds(50, 100, 135, 50); frame.add(button1); button2=new JButton("TO USD"); button2.setBounds(215, 100, 135, 50); frame.add(button2); display2=new JLabel(); display2.setBounds(50, 170, 300, 50); display2.setBackground(Color.GREEN); display2.setForeground(Color.BLACK); display2.setOpaque(true); frame.add(display2); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new CurrencyConverter(); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { int noInDisplay=Integer.parseInt(display.getText())*70; display2.setText(""+noInDisplay); } else if(e.getSource()==button2) { int noInDisplay=Integer.parseInt(display.getText())/70; display2.setText(""+noInDisplay); } } }