Fatihul Ulum Community of Knowledge
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Penambahan dengan swing

Go down

Penambahan dengan swing Empty Penambahan dengan swing

Post  cpp Wed Jul 22, 2009 6:39 am

Code dibawah ini adalah GUI dasar untuk java
Code:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class oke extends JFrame
{

   public JTextArea a,b,c;
   int aa,bb,cc;
   public JLabel satu,dua,tiga ;
   String Hasil;
    public oke()
    {

        setTitle("Simle Event");
        satu = new JLabel ("Pertama :");
           satu.setBounds (10,20,80,25);
      a = new JTextArea();
         a.setBounds(100, 20, 80, 25);
      dua = new JLabel ("Kedua :");
           dua.setBounds (10,50,80,25);
      b = new JTextArea();
          b.setBounds(100, 50, 80, 25);
      tiga = new JLabel ("Tiga :");
           tiga.setBounds (10,80,80,25);         
      c = new JTextArea();
         c.setBounds(100, 80, 80, 25);
        JButton ppfu = new JButton("Ok");
           ppfu.setBounds(100, 110, 80, 25);

        ppfu.addActionListener
        (
           new ActionListener()
           {
               public void actionPerformed(ActionEvent event)
               {
               aa = Integer.parseInt(a.getText());
               bb = Integer.parseInt(b.getText());
               cc = aa+bb;
               Hasil = Integer.toString(cc);
               c.setText(Hasil);
               }
           }               
        );

        JPanel paimo = new JPanel();
           paimo.setLayout(null);
           paimo.add(satu);
           paimo.add(ppfu);
           paimo.add(dua);
           paimo.add(tiga);
           paimo.add(a);
           paimo.add(b);
           paimo.add(c);
        add(paimo);
            setSize(300, 200);
           setLocationRelativeTo(null);
           setDefaultCloseOperation(EXIT_ON_CLOSE);
         setVisible(true);
    }

    public static void main(String[] args)
    {
        new oke();
    }
}
Baris yang perlu diperhatikan adalah baris ke tigapuluh satu yakni ppfu.addActionListener -
sampai baris ke 44 yakni tanda );
GoodLuck......

cpp
Pejuang
Pejuang

Jumlah posting : 35
Registration date : 15.03.09

Kembali Ke Atas Go down

Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik