— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet370/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   366   367   368   369   370   371   372   373   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

396
 
chapter 12


getting 
gui
you are here
4
397
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class InnerButton {
JFrame frame;
JButton b;
public static void main(String [] args) {
InnerButton gui = new InnerButton();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
b = new JButton(“A”);
b.addActionListener( 
new BListener( ) 
);
frame.getContentPane().add(
BorderLayout.SOUTH, b);
frame.setSize(200,100);
frame.setVisible(true);
}
class BListener 
implements
ActionListener {
public void actionPerformed(ActionEvent e) {
if (b.getText().equals(“A”)) {
b.setText(“B”);
} else {
b.setText(“A”);
}
}
}
}
The addActionListener( ) 
method takes a class that 
implements the ActionLis-
tener interface
ActionListener is an 
interface, interfaces 
are implemented, not 
extended
BE the compiler
Once this code 
is fixed, it will 
create a GUI with 
a button that 
toggles between 
A and B when you 
click it.
I got the whole GUI, in my hands. 
JFrame
Every event type has one of these. 
listener interface
The listener’s key method.
actionPerformed( )
This method gives JFrame its size. 
setSize( )
You add code to this method but 
never call it. 
paintComponent( )
When the user actually does 
something, it’s an ____ 
event
Most of these are event sources. 
swing components
I carry data back to the listener. 
event object
An addXxxListener( ) method 
says an object is an ___ 
event source
How a listener signs up. 
addActionListener( )
The method where all the 
graphics code goes. 
paintComponent( )
I’m typically bound to an instance. 
inner class
The ‘g’ in (Graphics g), is
really of this class. 
Graphics2d
The method that gets
paintComponent( ) rolling. 
repaint( )
The package where most of the 
Swingers reside.
javax.swing

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   366   367   368   369   370   371   372   373   ...   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