ButtonActionTest.java
Dosyayı İndir
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ButtonActionTest extends JFrame implements ActionListener {
Button b, b2;
ButtonActionTest() {
b = new Button("Button1");
b2 = new Button("Button2");
// düğmelere tıklandığını dinlemek için kayıt oluyoruz.
b.addActionListener(this);
b2.addActionListener(this);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(b);
getContentPane().add(b2);
}
public static void main(String[] args) {
ButtonActionTest test = new ButtonActionTest();
test.setBounds(0, 0, 200, 100);
test.setVisible(true);
}
// düğmelere tıklandığında actionPerformed method’u çağrılacak.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Button1")) {
System.out.println("1. button tıklandı");
} else if (e.getActionCommand().equals("Button2")) {
System.out.println("2. button tıklandı");
}
}
}
Dosyayı İndir