Stack Exchange
Java Programming Using NetBeans: adding ActionListener to JButton
I have a specific problem I'm stuck on. My job is to have this pop up:

Here's the program I have so far:
import javax.swing.*;
import java.awt.event.*;

public class Assignment5 implements ActionListener
{
JFrame frame;
JPanel panel;
JLabel label1, label2, label3, label4;
JButton button;
JTextField text1, text2, text3;

public Assignment5()
    {
        frame = new JFrame();
        frame.setVisible(true);
        frame.setSize(400,500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        label1 = new JLabel("No. of Years: ");
        text1 = new JTextField(20);

        label2 = new JLabel("Rate of Interest: ");
        text2 = new JTextField(20);

        label3 = new JLabel("Principal Amount: ");
        text3 = new JTextField(20);

        button = new JButton("Calculate Simple Interest");

        panel = new JPanel();
        panel.add(label1);
        panel.add(label2);
        panel.add(label3);

        panel.add(text1);
        panel.add(text2);
        panel.add(text3);
        panel.add(button);

        frame.add(panel);

        button.addActionListener(this);



    }


    public void actionPerformed(ActionEvent e)
    {
       int years = Integer.parseInt(text1.getText());
       double rate = Double.parseDouble(text2.getText());
       double amount = Double.parseDouble(text3.getText());

       double simple = years*rate*amount;

       label4 = new JLabel("Your Payable Amount Is: "+simple);

       panel.add(label4);

       }

     public static void main(String[] args) 
    {
    Assignment5 obj = new Assignment5();
    }


    }

Everything works so far, but my final label containing the actual result won't show up. I've tried a couple different things, each of which doesn't work, so I'm hoping you guys will be able to tell me a better way of doing this. Thanks.

Have you confirmed it actually getting into actionPerformed()?

Do you have any red errors showing up in any line of your code? I am not sure if it is the output code that is wrong. Try this:     
label4.setText("Your payable amount is "+simple);


Try this:
JOptionPane.showMessageDialog(null,"Your payable amount is “+simple);

That will pop your message.
