Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.1 kB
0
Indexable
Never
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.EventListener;
import java.awt.event.ActionListener;

public class gridbaglayoutko {
    JFrame frame;
    JButton b1;
    JLabel p, t, r, o;
    JTextField t1, t2, t3;

    public gridbaglayoutko() {
        frame = new JFrame("Simple Interest");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500, 500);
        frame.setVisible(true);
        frame.setLayout(new GridBagLayout());
        GridBagConstraints g1 = new GridBagConstraints();

        p = new JLabel("Principle");
        t = new JLabel("Time");
        r = new JLabel("Rate");
        o = new JLabel("SI:");

        t1 = new JTextField(6);
        t2 = new JTextField(6);
        t3 = new JTextField(6);

        b1 = new JButton("Find SI");

        g1.gridx = 0;
        g1.gridy = 0;
        g1.insets = new Insets(20, 20, 20, 20);
        frame.add(p, g1);
        g1.gridx = 1;
        g1.gridy = 0;
        frame.add(t, g1);
        g1.gridx = 2;
        g1.gridy = 0;
        frame.add(r, g1);
        g1.gridx = 0;
        g1.gridy = 1;
        frame.add(t1, g1);
        g1.gridx = 1;
        g1.gridy = 1;
        frame.add(t2, g1);
        g1.gridx = 2;
        g1.gridy = 1;
        frame.add(t3, g1);
        g1.gridx = 0;
        g1.gridy = 3;
        frame.add(o, g1);
        g1.gridx = 1;
        g1.gridy = 3;
        frame.add(b1, g1);
        frame.setVisible(true);

        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                float pr = Float.parseFloat(t1.getText());
                float ti = Float.parseFloat(t2.getText());
                float ra = Float.parseFloat(t3.getText());

                o.setText("SI :"+String.valueOf((pr*ti*ra)/100));

            }
        });

    }

    public static void main(String[] args) {
        gridbaglayoutko g = new gridbaglayoutko();
    }
}
Leave a Comment