— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet334/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   330   331   332   333   334   335   336   337   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

360
 
chapter 12
import javax.swing.*;
import java.awt.event.*;
public class SimpleGui1B
 implements ActionListener {

JButton button;

 public static void main (String[] args) {
SimpleGui1B gui = new SimpleGui1B();
gui.go();
}

 public void go() {

JFrame frame = new JFrame();
button = new JButton(“click me”);
button.addActionListener(this);

frame.getContentPane().add(button);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);

}
public void actionPerformed(ActionEvent event) {
button.setText(“I’ve been clicked!”);
}
}
Implement the interface. This says, 
“an instance of SimpleGui1B IS-A 
ActionListener”.
(The button 
will give events 
only to 
ActionListener implementers)
register your interest with the button. This says 
to the button, “Add me to your list of listeners”. 
The argument you pass MUST be an object from a 
class that implements ActionListener
!!
a new import statement 
for the package that 
ActionListener and ActionEvent are in.
Implement the ActionListener 
interface’s 
actionPerformed() method.. This is the 
actual event-handling method!
The button calls this method to let you know an event 
happened. It sends you an ActionEvent object as the 
argument, but we don’t need it. Knowing the event
happened is enough info for us.
2
3
1
Implement the ActionListener interface
1
Register with the button (tell it you 
want to listen for events)

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   330   331   332   333   334   335   336   337   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish