SWING

Jumat, 21 Oktober 2011

public class SwingApp2 extends JFrame {

    private int bilangan = 0;
    JButton buttonSwing;
    JLabel labelClick;

    public SwingApp2() {
        setSize(300, 200);
        this.setTitle("swing Application");
        this.setLocation(300, 300);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new FlowLayout());

        buttonSwing = new JButton("I'm swing button");
        this.add(buttonSwing);

        labelClick = new JLabel("Number of button Click = " + bilangan);
        this.add(labelClick);

        buttonSwing.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                bilangan = bilangan + 1;
                tambah();
            }

            public void tambah() {
                labelClick.setText("Number of button Click = " + bilangan);
            }
        });

        buttonSwing = new JButton("I'm not swing button");
        this.add(buttonSwing);

        buttonSwing.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                bilangan = bilangan - 1;
                kurang();
            }
        });
    }

    public void kurang() {
        labelClick.setText("Number of button Click = " + bilangan);
    }

    public static void main(String[] args) {
        SwingApp2 sw = new SwingApp2();
        sw.setVisible(true);
    }
}

OUTPUT:

 Jika di klik I'm swing button, number of button click akan bertambah 1.


Jika di klik I'm not swing button, number of button click akan berkurang 1.
 

Get This Comment Form

0 comment(s):

 
Copyright© 2010 Felisitas Brillianti | Semelekete Weleh Weleh | http://dr214ac.blogspot.com