Social Icons

Cara mendapatkan bitcoin gratis

Sunday, 7 September 2014

program penjumlahan dengan GUI

Sourc Code :

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;

public class Gui2 extends JFrame implements ActionListener{

private JButton btnHitung, btnClose;
private JLabel lblHasil, lblOpr;
private JTextField txt1, txt2;

    public Gui2() {
    setTitle("PENJUMLAHAN");
    setSize(300, 70);
    setLayout(new GridLayout(2, 3));
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setUndecorated(true);
    setLocationRelativeTo(null);

    btnHitung = new JButton("HITUNG");
    btnClose = new JButton("KELUAR");

    lblHasil = new JLabel();
    lblOpr = new JLabel("               +");

    txt1 = new JTextField();
    txt2 = new JTextField();

    add(txt1);
    add(lblOpr);
    add(txt2);
    add(lblHasil);
    add(btnHitung);
    add(btnClose);

    btnHitung.addActionListener(this);
    btnClose.addActionListener(this);
    }
    
    public void actionPerformed(ActionEvent e){
    int a, b;
    if(e.getSource() == btnHitung){
    a = Integer.parseInt(txt1.getText());
    b = Integer.parseInt(txt2.getText());

    lblHasil.setText("" + (a + b));
    }

    if(e.getSource() == btnClose){
    dispose();
    }
    }
    
    public static void main(String [] args){
    new Gui2().setVisible(true);
    }
}

Outputnya :


No comments:

Post a Comment

jago Photoshop