java yardım!!!!!

emrah555

New member
Katılım
6 Ocak 2008
Mesajlar
39
Reaction score
0
Puanları
0
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;
import javax.swing.*;
import java.awt.GridLayout;
/**
*
* @author dell
*/
public class JavaApplication2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

JPanel wC =new JPanel();
GridLayout gl= new GridLayout (4,2);
wC.setLayout(gl);
JLabel label1=new JLabel("1. sayı:");
JTextField yazi1=new JTextField(10);
JLabel label2=new JLabel("2. sayı:");
JTextField yazi2=new JTextField(10);
JLabel label3=new JLabel("Toplam");
JTextField toplam=new JTextField(10);
JButton OK=new JButton("Topla");
wC.add(label1);
wC.add(yazi1);
wC.add(label2);
wC.add(yazi2);
wC.add(label3);
wC.add(toplam);
wC.add(OK);
JFrame sayfa=new JFrame("Haydi Topla!!");
sayfa.setContentPane(wC);
sayfa.setSize(375,150);
sayfa.setVisible(true);
}
}

arkadaşlar butona bastığımızda toplama işlemini yapabilecek kodu yazabilir misiniz? Şimdiden teşekkürler
 
actionListener ve actionPerformed yazman lazım birer tane butona dinleyici buton hareketlerini dinliyecek bastığında ise actionPerformed içindeki kodları çalıştıracak.

int sayi1=Integer.parseInt(yazi1.getText());

int sayi2=Integer.parseInt(yazi2.getText());

int toplam=sayi1+sayi2;

yazi3.setText(Integer.toString(toplam));
 
Geri
Üst