You are on page 1of 44

CHNG I - BT U VI JAVA

Bi 1 Hello world
Bn hy xem bi ca anh CEO trong JVN
Xin hi, ti bt !" #$i m%t #i #& '(, m ti ch)ng hi*" c+i g, c-.
Xin tr- /0i, bn 12 h3c Ja#a 4"a c+c #& '(, r5t nhi6" #& '(, /& th"y7t th, bn ch8 h3c t9 t9
thi.
:;& th"y7t< c5" tr=c m%t ch>?ng tr,nh Ja#a
public class Core {
public static void main(String[] args) {
System.out.println("Hello,Everybody in te !orld"")#
$
$
@"b/ic c/a11 Core bn bt !" m%t /$@ Ja#a
@"b/ic 1tatic #oi' mainABtringCD arg1E Fy / m%t @h>?ng thGc main trong Ja#a, * cho
ch>?ng tr,nh chy >Hc. Im th0i bn @h-i gJ y nh> th7 ny
By1tem.o"t.@rint/nAKLe//o,E#erybo'y in the Mor/'NKE Fy / m%t cF" /Onh trong Ja#a, ?n
gi-n nP ch8 in ra ch"Qi nRm trong S '5" TU ra mn h,nh.
V3i /$@ # @h>?ng thGc trong Ja#a mW ra bRng X # Png /i bRng Y
V3i cF" /Onh trong Za#a [7t th=c bRng .
Bi 2 In r !"#$i n"%& 'o
Bi !" ti\n ca bn, bn h3c c+ch * Ja#a in c+i g, P ra mn h,nh, trong bi ny, bn
12 h3c c+ch nh]@ #o c+i g, P # Ja#a in c+i P ra mn h,nh. ^J c+i ny i bn A/>" _, bn
@h-i gJ, [hng >Hc co@y # @a1teE
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print(".our name is/ ")#
String str#
str , in.read0ine()#
System.out.println("!elcome " 1 str 1 " to 2ava")#
$
$
:;& th"y7t<
Im th0i, trong ch>?ng tr,nh ny, bn ch8 n\n 4"an tFm 7n '`ng
Btring 1tr [hai b+o bi7n 1tr [i*" ch"Qi, #
By1tem.o"t.@rint/nAKMe/come K a 1tr a K to Ja#aKE
bFy ccng / '`ng By1tem.o"t.@rint/n nh> ch>?ng tr,nh !", cP [h+c / a 1tr a tGc / >a
m%t bi7n #o ch"Qi in ra. Ch8 7n P thi nhd, 1a" P, hy 4"an tFm 7n bi hm nay
Bi ( Bi)n *ron+ J'
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap a/ ")#
int a , -nteger.parse-nt(in.read0ine())#
System.out.print("3ap b/ ")#
int b , -nteger.parse-nt(in.read0ine())#
int 4et5ua#
4et5ua , a1b#
System.out.println("6et 5ua bai toan a1b la/ 7 1 4et5ua)#
$
$
Nh]@ the S 1f a # b #o i bn, [7t 4"- bi to+n aab 12 >Hc in ra.
:;_ th"y7t<
im@ort bn nh]@ c/a11 hay th> #iOn ch"gn, tm th0i 9ng 4"an tFm nP / g,, ch8 c!n nh$ /
cP nP * ch>?ng tr,nh chy
By1tem.o"t.@rint in ra m%t ch"Qi, nh>ng [hng x"fng '`ng
By1tem.o"t.@rint/n in ra m%t ch"Qi, nh>ng x"fng '`ng
int [et4"a tGc / [hai b+o bi7n [et4"a [i*" int
[et4"a h aab tGc / g+n [7t 4"- m%t bi*" thGc t&nh to+n AW Fy / bi7n a a bi7n bE cho bi7n
[et4"a
By1tem.o"t.@rint/nAKiet 4"a bai toan aab /a< T a [et4"aE th, ?n gi-n rji, in c+i '`ng P ra,
ch8 [h+c / nP >a bi7n [et4"a ca bn #o ch"Qi P
Bi , C"i ")*- !"i l./ d0
:;& th"y7t< m%t 1f [i*" bi7n trong Ja#a
Bn bi7t S [i*" Btring Ach"QiE # int Ang"y\nE bFy gi0 bn bi7t th\m [i*" k/oat AthlcE
Bf ng"y\n # 1f thlc bn bi7t 1l [h+c nha" rji chG. BFy gi0 ta bt !" bi to+n #& '(
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap a/ ")#
*loat a , 8loat.parse8loat(in.read0ine())#
System.out.print("3ap b/ ")#
*loat b , 8loat.parse8loat(in.read0ine())#
*loat 4et5ua , a9b#
System.out.println("6et 5ua bai toan a1b la/ " 1 4et5ua)#
$
$
Bn the bi to+n xem, nh$ 9ng nh]@ 1f bhm nhd, ch"yOn 5y 12 xe /& 1a".
V& '( nh]@ ahn, bhS, [7t 4"- in ra 12 / S.n, th= #o @h-i [hng p
BFy gi0 ccng bi to+n 5y, bn thay qi nh> 1a"
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap a/ ")#
int a , -nteger.parse-nt(in.read0ine())#
System.out.print("3ap b/ ")#
int b , -nteger.parse-nt(in.read0ine())#
*loat 4et5ua , a9b#
System.out.println("6et 5ua bai toan a9b la/ " 1 4et5ua)#
$
$
Ccng nh]@ ahn, bhS, /!n ny [7t 4"- in ra / r S
shd@ chia 12 / @hd@ chia h7t n7" c- S to+n hng 6" [i*" ng"y\n, g3i / chia /5y ng"y\n
AtE hay 'i#
BFy gi0 ccng ch>?ng tr,nh 5y m ta thay qi /i ch=t x&" xem 1ao
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap a/ ")#
int a , -nteger.parse-nt(in.read0ine())#
System.out.print("3ap b/ ")#
int b , -nteger.parse-nt(in.read0ine())#
*loat 4et5ua , a:b#
System.out.println("6et 5ua bai toan a1b la/ " 1 4et5ua)#
$
$
Ccng nh]@ ahn, bhS, /!n ny [7t 4"- in ra / r u
bFy / [7t 4"- @hd@ chia /5y '> n chia cho S, g3i / chia /5y '> AvE hay mo'
:Ih7 n7" ti m"fn S 1f ng"y\n chia nha" m ra [i*" thlc chG [hng @h-i @hd@ chia /5y
ng"y\n th, 1ao p Irong tr>0ng hH@ P, bn 'wng Td@ [i*"U
int ahn,bhSxk/oat [et 4"ax
[et4"ahAk/oatEatbx
Bi 1 2%& *r3n" 445
Bn xem bi ca anh CEO trong JVN
!l66
bFy / m%t c/a11, c/a11 ny cP hai @ro@erty Ath"%c t&nhE / name # age
public class ;erson
{
String name#
int age#
$
bFy / m%t c/a11, c/a11 ny ngoi @ro@erty c`n cP con1tr"ctor A[hWi toE ca c/a11 P
public class ;erson
{
String name#
int age#
public ;erson(String name)
{
tis.name , name#
$
$
Irong c+i con1tr"ctor ny hy />" _ m%t i6", P / bi7n thi1. Bi7n thi1 cP nghya / b-n
thFn c+i c/a11 P AW Fy / c/a11 ser1onE.
Irong c/a11 ser1on cP m%t @ro@erty / age, cF" thi1.age h age cP nghya / c+i th"%c t&nh age
ca c/a11 ser1on 12 nh]n gi+ tro W c+i fi 1f age 'o con1tr"ctor ser1onAint ageE >a #o.
;>" _ / m3i c/a11 6" cP 1zn &t nh5t m%t con1tr"ctor [hng cP fi 1f.
bFy / m%t c/a11, c/a11 ny ngoi @ro@erty, con1tr"ctor c`n cP m%t beha#ior Ahnh #iE
public class ;erson
{
String name#
int age#
public ;erson(int age)
{
tis.age , age#
$
public void 3ap()
{
nameonsole.read0ine("3ap o ten/")#
$
$
ihi ta #i7t cF" /Onh 1a"
ser1on @er1onOne h ne{ ser1onAuSEx
Ih, ta to ra m%t in1tance Ath* hiOnE / @er1onOne ca c/a11 ser1on
Bi 1 2%& *r3n" 445 Ati7@E
7"i 89o :;* !l66
@"b/ic ab1tract c/a11 VyC/a11 XY
I9 thG u / [hai b+o 4"y6n tr"y x"5t # [7 th9a,cP | /oi<
}@"b/ic<>Hc @hd@ tr"y x"5t t9 b5t cG n?i no # b5t cG /$@ no ccng >Hc 4"y6n [7 th9a
}@rotecte'<ch8 cP @h>?ng thGc cwng gPi >Hc @hd@ tr"y x"5t # [7 th9a
}@ri#ate<ch8 cP @h>?ng thGc cwng gPi >Hc @hd@ tr"y x"5t nh>ng [hng /$@ no >Hc @hd@
[7 th9a
}n7" [hng [hai b+o,m~c onh / @rotecte'
I9 thG S / [hai b+o m%t /$@ tr9" t>Hng hay / [hng tr9" t>Hng.
Nhiem #"< tao u /o@ ser1on, tao tie@ S /o@ Bt"'ent1 #a Ieacher1 [e th"a /o@ ser1on, tao /o@
Exec"te ch"a ham chinh 'e chay ch"ong trinh.
}}/o@ ser1on}
import core%ava.&#
abstract class ;erson
{
99cai nay goi la cac property ay state<tuoc tin cua doi tuong
String oten#
int age#
String diaci#
int luong#
99cac constructor
public ;erson(int age)
{
tis.age , age#
$
99cac metod ay beavior<an vi cua doi tuong
public void 3ap()
{
oten , Console.read0ine("3ap o ten/")#
diaci , Console.read0ine("3ap dia ci/")#
$
9&vi la = class tuoc loai abstract nen ;erson duoc pep 4ai bao
cac metod 4ong co noi dung, noi dung cua class -n se duoc cac lop 4e
tua no tem vao noi dung cua rieng no&9
public abstract void -n()#
public abstract int >inluong()#
$
}}/o@ Bt"'ent1}
import core%ava.&#
class Students e(tends ;erson
{
int ?aS@,?alop#
public void 3ap()
{
super.3ap()#
?aS@ , Console.read-nt("3ap ma S@/")#
?alop , Console.read-nt("3ap ma lop/")#
$
public void -n()
{
System.out.println(oten)#
System.out.println(diaci)#
System.out.println(?aS@)#
System.out.println(?alop)#
$
public int >inluong()
{
return =ABBBB#
$
$
t" [hoa 1"@er 1e goi ham Nha@AE t" /o@ ser1on /a cha c"a /o@ Bt"'ent1
}}/o@ Ieacher1}
import core%ava.&#
class >eacers e(tends ;erson
{
int ?a4oa#
public void 3ap()
{
super.3ap()#
?a4oa , Console.read-nt("3ap ma 4oa//")#
$
public void -n()
{
System.out.println(oten)#
System.out.println(diaci)#
System.out.println(?a4oa)#
$
public int >inluong()
{
return ABBBBB#
$
$
}}/o@ Exec"te}
import core%ava.&#
class E(ecute
{
public static void main(String args[])
{
Students st , ne' Students()#
st.3ap()#
st.-n()#
st.luong,st.>inluong()#
>eacers tc , ne' >eacers()#
tc.3ap()#
tc.-n()#
tc.luong,tc.>inluong()#
$
$
7"i 89o :;* *"#;! *<n"=
ihai b+o u th"%c t&nh
@"b/ic 1tatic #oi' tem@x
a. I9 thG u / [hai b+o 4"y6n tr"y x"5t,cP | /oi
}@"b/ic<>Hc @hd@ tr"y x"5t t9 b5t cG n?i no
}@rotecte'<ch8 cP /$@ con m$i >Hc @hd@ tr"y x"5t
}@ri#ate<ch8 cP /$@ P xiAth"%c t&nh ri\ng ca nPE
}n7" [hng [hai b+o,m~c onh / acce11 @ac[age
b.I9 thG S / [hai b+o c+ch tr"y x"5tA1taticE
}n7" [hng [hai b+o,m~c onh / [hng tynh
I5t c- c+c fi t>Hng th* hiOn t9 /$@ cha 6" >Hc @hd@ thay qi gi+ tro ca c+c th"%c t&nh
[hng tynh,c`n gi+ tro ca th"%c t&nh tynh th, [hng >Hc @hd@ thay qi
public class Car
{
public string branc#
public int cost#
public static int tire,C#
$
Nh> #& '( tr\n,t5t c- c+c /$@ con ca /$@ Car Anh> IoyotaCar,se"geot,Va'arE 6" >Hc
@hd@ thay qi c+c th"%c t&nh branch hay co1t * @hw hH@ cho ri\ng m,nh,nh>ng th"%c t&nh
tire A1f b+nh xeE [hng >Hc @hd@ thay qi #, / th"%c t&nh tynh
NPi c+ch [h+c, ch8 cP m%t # ch8 m%t th"%c t&nh cP t\n / tire trong c/a11 Car # t5t c- c+c
c/a11 con ca nP, #, #]y g3i / tynh
7"i 89o :;* "n" 'i
V%t @h>?ng thGc >Hc [hai b+o nh> 1a"
@"b/ic 1tatic 'o"b/e [et4"aAE
CP | ch8 onh tr"y x"5t / @"b/ic, @rotecte' # @ri#ate
}@"b/ic<>Hc @hd@ tr"y x"5t t9 b5t cG n?i no
}@rotecte'<ch8 cP /$@ [7 th9a /$@ chGa nP >Hc tr"y x"5t
}@ri#ate<ch8 /$@ chGa nP >Hc tr"y x"5tA'wng n%i b%E
}n7" [hng [hai b+o,m~c onh / @ac[age acce11
CP ch8 onh th"%c t&nh / 1tatic AtynhE, ab1tract Atr9" t>HngE, kina/, nati#e, 1ynchronie'
Ajng b%E # #o/ati/e A/inh hotE
}n7" [hng [hai b+o,m~c onh / [hng tynh
class >estDb%ect
{
static void Static?etod() {E$
void 3onStatic?etod() {E$
$
N7" / m%t @h>?ng thGc [hng tynh, !" ti\n bn @h-i [hWi to m%t fi t>Hng,1a" P m$i
>Hc @hd@ g3i @h>?ng thGc
Ie1tObZect te1thne{ Ie1tObZectAEx
te1t.NonBtaticVetho'AEx
N7" / m%t @h>?ng thGc tynh,bn >Hc @hd@ g3i trlc ti7@ t9 /$@
Ie1tObZect.BtaticVetho'AEx
V%t @h>?ng thGc tr9" t>Hng [hng cP n%i '"ng.N%i '"ng ca nP 12 >Hc c+c /$@ con twy
bi7n # @h+t tri*n theo h>$ng ca ri\ng nP.
} kina/< [hng th* >Hc exten'1 hay o#erri'e Aghi E
} nati#e< thFn @h>?ng thGc #i7t bRng C hay Caa
} 1ynchronie'< ch8 cho @hd@ u threa' tr"y c]@ #o [hfi m W cwng m%t th0i i*m
} #o/ati/e< 1e '(ng #$i bi7n * thng b+o rRng gi+ tro ca bi7n cP th* >Hc thay qi #i /!n
#, #]y [hng ghi #o thanh ghi
.I9 thG | / gi+ tro tr- #6.N7" [hng cP gi+ tro tr- #6 th, / #oi'
in*er>!e-*e:&l*e
BFy gi0 ta cP u [h+i niOm m$i, / giao 'iOn. ^iao 'iOn ra 0i ch&nh / * gi-i 4"y7t a [7
th9a. VQi /$@ trong Ja#a ch8 cP u /$@ cha, nh>ng cP th* im@/ement1 nhi6" giao 'iOn.
^iao 'iOn >Hc [hai b+o gifng nh> u /$@, ccng cP 1tate # beha#ior. Nh>ng 1tate ca giao
'iOn / kina/ c`n beha#ior / ab1tract
^i- 1e, ta 12 [hai b+o m%t giao 'iOn
public inter*ace ;roduct
{
99ai state duoi day la *inal, tuc la lop implements 4ong duoc
pep doi gia tri
static string ma4er , 7?y CorpF#
static string pone , 7AAA<GGHGF#
99beavior duoi day la abstract, tuc la 4ong co noi dung
public int get;rice(int id)#
$
BFy gi0, ta 12 #i7t m%t c/a11 cP ci ~t Aim@/ement1E giao 'iOn ny
public class Soe implements ;roduct
{
public int get;rince(int id)
{
return (id, ,=)IA/=B#
$
public String get?a4er()
{
return ma4er#
$
$
V"fn im@/ement1 nhi6" giao 'iOn, /m nh> 1a", #& '( c/a11 Ioyota exten'1 Car
im@/ement1 ctionCar, ctionVobi/ation
&!?+e-#ni*
Ly to u th> m(c cP t\n / Iran1@ort
B\n trong th> m(c ny hy to S ki/e / Car.Za#a # Bicyc/e.Za#a nh> 1a"
}}Car.Za#a}
pac4age >ransport#
public class Car
{
public String manu*acturer#
public int year#
$
}}Bicyc/e.Za#a}
pac4age >ransport#
public class )icycle
{
public int cost#
public )icycle(int cost)
{
tis.cost , cost#
$
$
Nh> #]y / ta to ra u gPi chGa S /$@ / Car # Bicyc/e. BFy gi0 ta cP u ch>?ng tr,nh
m"fn 1e '(ng gPi ny / Ie1tsrogram.Za#a. Ia #i7t<
}}Vi"Iran1@ort.Za#a}
import >ransport.&#
class >est;rogram
{
public static void main(String args[])
{
Car myCar , ne' Car()#
myCar.manu*acturer , 7>oyotaF#
)icycle my)icycle , ne' )icycle(=ABB)#
$
$
;>" _ n7" trong ki/e Vi"Iran1@ort bn [hng [hai b+o im@ort Iran1@ort.: th, bn #n cP
th* [hai b+o t>0ng minh nh> 1a"
Iran1@ort.Car myCar h ne{ Iran1@ort.CarAEx
n@& !"An+ Bo'erlodC 1 &"0Dn+ *"E!
class @idu
{
public satic void main(String a[])
{
private *loat cost#
public *loat CalculateSale;rice()
{
return cost&=.A#
$
public *loat CalculateSale;rice(double eso)
{
return cost&(=1eso)#
$
$
$
Fy cP S @h>?ng thGc trwng t\n Ca/c"/ateBa/esrice nh>ng @h>?ng thGc thG S [h+c tham
1f, g3i / n@ chjng
: n@ chjng Ao#er/oa'E # ghi Ao#erri'eE
Nhng @h>?ng thGc >Hc n@ chjng / nhng @h>?ng thGc trong cwng m%t /$@, cP cwng
m%t t\n nh>ng 'anh 1+ch fi 1f [h+c nha"
sh>?ng thGc >Hc ghi / @h>?ng thGc cP m~t W /$@ cha, >Hc x+c onh / @h>?ng thGc
ch"ng cho c+c /$@ con, rji x"5t hiOn W c+c /$@ con
N@ chjng / m%t h,nh thGc a h,nh A@o/ymor@hi1mE trong 4"+ tr,nh bi\n 'och Acom@i/eE
c`n ghi / trong 4"+ tr,nh thlc thi Ar"ntimeE
Bi 6 Cc kiu d liu nguyn thy v php ton
- Kiu nguyn: gm s nguyn(int,long)
- Kiu du phy ng (hay kiu th): gm s th(!loat,dou"l#)
- Kiu k$ t (ha%)
- Kiu hu&i ('t%ing)
()ng k$ t khai "*o nh+ sau, ,$ d- .(. (kh* ,/i 0(0 l1 mt hu&i k$
t)
2t s h)ng k$ t 3 "i4t, ,$ d- .55. "iu di6n h$nh k$ t 5, ,1 5u
"iu di6n 7niod#, ,$ d-:
.5u889:. "iu di6n ; ("<nh ph+=ng)
.5u889>. "iu di6n ? (mt ph@n t+)
.5u8AB8. "iu di6n C (mD a)
- Kiu "ool#an
>E : gi* t%F l1 : tG khEa t%u# ,1 !als#, ,1 khHng th huyn kiu
sang int
IKhai "*o "iJn
int i,KL MM: "iJn i ,1 K E kiu dN li4u l1 int
ha% hO.P.L MM"iJn h kiu ha% khQi tRo gi* t%F @u .P.
IKhai "*o h)ng
()ng +S khai "*o ,/i tG khEa !inalT U$ d-:
!inal !loat VW O XTAYAZ[L
IVh\p to*n
Vh\p to*n ]a ^a,a ging >T _%ong lass Ka,aTlangT2ath E mt s
m#thod d`ng t%ong to*n ha nh+ sau
dou"l# y O 2athTpob(c,a) O cC
,1 %andom, sin, os, tan, #cp (mD), log(loga%it) TTT
I >* ph\p to*n s ha
- U/i d kiu nguyn ,1 kiu th: e - I M (ph\p hia sf ho %a kJt
gud kiu th nJu mt t%ong : to*n th l1 kiu th)
- >hia hJt (M) hi *p d-ng khi d : to*n th l1 kiu nguyn, ,$ d-
A8MXOX
- >hia ly d+ (j) hi *p d-ng khi d : to*n th l1 kiu nguyn, ,$ d-
A8jXOA
I >* ph\p to*n guan h4 (so s*nh)
- 9ao gm OO,k,l,kO,lO t%d ,m kiu "ool#an
I >* ph\p to*n ,/i kiu logi
- 9ao gm and(k$ hi4u nn) o%(k$ hi4u oo) not(k$ hi4u p)
I Vh\p ee ,1 --
- Vh\p n1y E : dRng, mt l1 ee"iJn hay --"iJn, hai l1 "iJnee hay
"iJn-- ' kh* nhau hi l1 khi ph\p n1y th hi4n hung ,/i mt
ph\p to*n kh* th<
- U/i ee"iJn ,1 --"iJn th< nE sf th hi4n ph\p to*n n1y t%+/ %i
m/i th hi4n ph\p to*n kh*
- U/i "iJnee ,1 "iJn-- th< nE sf th hi4n ph\p to*n kh* t%+/ %i
m/i th hi4n ph\p to*n n1y
I Vh\p g*n
- Vh\p n1y E dRng aOZ
- Vh\p g*n phq, ,$ d- aeOZ nghra l1 aOaeZ, hay aIO: nghra l1
aOaI:
I _%<nh t kJt hSp
(@u hJt * ph\p to*n imu E t%<nh t kJt hSp tG t%*i sang phdi,
hi E * ph\p sau l1 tG phdi sang t%*i
- Vh\p ee ,1 --
- >* ph\p g*n nh+ O,eO,-O,kkO,llO
Bi F GHn" IJ i>
n7" em @ th, ti 12 c>a em [hng th, ti c>a Ga [h+c
em @ ILEN ti 12 c>a em E;BE ti c>a Ga [h+c
Aem @E ti 12 c>a emx
E;BE ti c>a Ga [h+cx
C= @h+@ A1yntaxE ca mOnh 6 /
ikAmOnh 6E /Onh ux
e/1e /Onh Sx
N7" mOnh 6 =ng th, thlc hiOn /Onh ux
ihng th, thlc hiOn /Onh Sx
V& '(
ikAabE By1tem.o"t.@rint/nATBo /on nhat /a TaaEx
e/1e By1tem.o"t.@rint/nATBo /on nhat /a TabEx
:Ia xFy 'lng m%t bi to+n /m tr`n 1f
Nh]@ #o m%t 1f b5t [,. N7" @h!n th]@ @hFn 1f ny hm.n, /m tr`n tng /\n m%t ?n #o,
ng>Hc /i gi-m i m%t ?n #o.
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap a/ ")#
*loat a , 8loat.parse8loat(in.read0ine())#
*loat 4et5ua,a:=#
i*(4et5uaJ,B.A) a,a<4et5ua1=#
else a,a<4et5ua#
System.out.println("6et 5ua bai toan la/ " 1 a)#
$
$
: shd@ i6" [iOn p # @hd@ ch3n <
} ^i- 1e cP mOnh 6 ik
ikAabE ahSx
e/1e ahmx
shd@ i6" [iOn bi*" 'in nh> 1a" ahabpS<m nghya / n7" chFn tro ca ab / =ng th, ahS
n7" / 1ai th, ahm
: Ba" [hi h3c xong ik, bn cP r5t nhi6" bi t]@ * m r /m, cq i*n nh5t #n / gi-i
@h>?ng tr,nh b]c m%t # hai, ngoi ra c`n nhi6" bi t]@ [h+c na. Fy ch8 cP gi-i
@h>?ng tr,nh b]c m%t. Bn n\n t,m nhi6" bi t]@ * tl /m tr>$c [hi ti7@ t(c @h!n [7.
V& '(< @h>?ng tr,nh b]c u
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.println("Kiai puong trin bac nat dang
a(1b,B")#
System.out.print("3ap e so a/ ")#
*loat a , 8loat.parse8loat(in.read0ine())#
System.out.print("3ap e so b/ ")#
*loat b , 8loat.parse8loat(in.read0ine())#
i*(a,,B) {
i*(b,,B) System.out.println(";uong trin vo so
ngiem")#
i*(b",B) System.out.println(";uong trin vo
din")#
$
else System.out.println(";uong trin mot ngiem (," 1
<b9a)#
$
$
Bi K 6wi*!"
Bn h3c xong ik. Bn m"fn 'wng #`ng /~@ ik * +nh gi+ i*m 1f nh]@ #o. Bn 12 #i7t
ch>?ng tr,nh 1a" Fy
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap diem so/ ")#
int diem , -nteger.parse-nt(in.read0ine())#
i*(diemL,M) System.out.println(".eu")#
i*((diemJM) NN (diemL,O)) System.out.println(">rung
bin")#
i*((diemJO) NN (diemL,C)) System.out.println("6a")#
i*((diemJC) NN (diemLA)) System.out.println("Kioi")#
i*(diem,,A) System.out.println("Puat sac")#
$
$
Ihay #, /~@ /i nhng cF" ik 5y, bn n\n 'wng 1{itch
import %ava.io.&#
public class Hello {
public static void main(String[] args) tro's E(ception {
)u**ered+eader in , ne' )u**ered+eader(ne'
-nputStream+eader(System.in))#
System.out.print("3ap diem so/ ")#
int diem , -nteger.parse-nt(in.read0ine())#
s'itc(diem)
{
case B/
case =/
case M/System.out.println(".eu")#brea4#
case O/System.out.println(">rung bin")#brea4#
case C/
case A/System.out.println("Kioi")#brea4#
de*ault/System.out.println("@ao sai")#
$
$
$
:brea[ #$i 1{itch< brea[ 12 tho+t ngay ra [hi [hfi /Onh trong thFn ca 1{itch
Bi 9 String
Kh* ,/i >, 't%ing l1 mt l/p ]a ^a,aT 't%ing +S khai "*o nh+
sau
't%ing a O 0(#llo0L
>ng : 't%ing ")ng du e
'yst#mToutTp%intln(0sia t%i la 0 e n)L
^a,a E khd ntng t huyn kiu "t q dN li4u kiu s n1o khi
ng ,1o 't%ingT u` n l1 int, !loat, dou"l# mu E th huyn th1nh
't%ing nhv mwo ,3t (00 e n)
>* m#thod t%ong lass 't%ing
I su"st%ing
't%ing sA O 0(#llo0L
't%ing s: O sATsu"st%ing(8,Y)L MM"xt @u tG k$ t thq 8 (tq l1 .(.) ly
i Y k$ t (tq l1 0(#ll0)
I l#ngth
int n O sATl#ngth()L MMtq l1 ")ng Z
I ha%Pt
ha% h O sATha%Pt(Y)L MMtq l1 ")ng .o.
yzy l1 m#thod t<m k$ t thq i t%ong 't%ing, * k$ t t%ong 't%ing
+S *nh s tG 8
I #guals
Kiu t%a c#m hu&i ngun s E ging hu&i $h d hay khHng, ta
d`ng m#thod #guals t%d ,m "ool#an
"ool#an " O sT#guals(t)L
't%ing khHng ging dN li4u kiu s, tuy4t i khHng d`ng ging
nh+ i!(sOOt)
I ompa%#_o
int a O s:Tompa%#_o(sA)L
al8 s:lsA
ak8 s:ksA
aO8 s:OsA
'o s*nh giNa s: ,1 sA l1 so s*nh thq t giNa k$ t @u ]a hai
hu&i so i, ,$ d- 0k0 l 0ka{"#0
I to>ha%P%%ay (|i hu&i %a mdng k$ t)
ha%}~ huoi O sATto>ha%P%%ay()L
I ind#c!
't%ing sA O 0(#llo ,#%y"ody0L
't%ing s: O 0lo0L
int n O sATind#c!(s:)L MMn sf ")ng Y
yzy l1 m#thod t%d ,m ,F t%$ ]a hu&i s: t%ong hu&i sA, nJu khHng
t<m thy sf t%d ,m -A
I >huyn kiu tG 't%ing %a dN li4u kiu s
>huyn tG dN li4u kiu s %a 't%ing kh* d6 d1ng, d`ng 00 e n,
nh+ng ng+S lRi th< phdi d`ng * m#thod t+=ng qngT
>* m#thod n1y n)m t%ong gEi Ka,aTlang, t%ong * lass 9yt#,
'ho%t, Wnt#g#%, ong, loat, uou"l#
't%ing input O 0:X80L
int n O Wnt#g#%Tpa%s#Wnt(input)L MMn sf ")ng :X8
_+=ng t ,/i * m#thod sau 9yt#Tpa%s#9yt#, 'ho%tTpa%s#'ho%t,
loatTpa%s#loat, TTT
Bi 1L 'Mn+ lN& >or
*or(int i,B#iLn#i11)
s1,i#
| thnh @h!n trong cF" kor ta cP th* b h7t nh>ng @h-i gi /i c+c '5" x [hi P n7n m"fn ta
cP th* ~t @hd@ to+n i6" [hi*n #`ng /~@ trong thFn /Onh nh> 1a"
*or(int i,B#iLn#)
{
s1,i#
i11#
$
:brea[ #$i kor< brea[ 12 tho+t ngay ra [hi #`ng kor
*or(int i,B#iLn#i11)
{
System.out.println(i)#brea4#
System.out.println(">iep tuc")#
$
i7t 4"- in ra [hng cP cF" KIie@ t"cK #, brea[ nh-y ngay ra [hi #`ng kor 1a" [hi in u
:contin"e #$i kor< contin"e 12 [hi7n #`ng kor bt F" u ch" tr,nh m$i # b 4"a t5t c- c+c
/Onh b\n '>$i nP
V< in t5t c- c+c 1f t9 m 7n um, b 4"a |,,n
*or(int i,B#iL=B#i11)
{
i*((i, ,O)QQ(i, ,C)QQ(i, ,A)) continue#
System.out.println(i)#
$
Bi 11 w"ile
'ile(biRu tSc)
lTn#
N7" bi*" thGc =ng th, thlc hiOn /Onh
:brea[ #$i {hi/e< brea[ 12 tho+t ngay ra [hi #`ng {hi/e
int i,B#
'ile(iL=B)
{
System.out.println(i)#brea4#
i11#
$
B2 ch8 in ra m
: contin"e #$i {hi/e< nP 12 x+c onh gi+ tro bi*" thGc #i7t ngay 1a" {hi/e
int i,B#
'ile(iL=B)
{
System.out.println(i)#continue#
i11#
$
Ia 12 >Hc m%t /ot in m # t]n
Bi 12 'Mn+ lN& doOOw"ile
do
lTn#
'ile(biRu tSc)#
N7" bi*" thGc =ng th, ti7@ t(c thlc hiOn /Onh
:brea[ #$i 'o..{hi/e< brea[ 12 tho+t ngay ra [hi #`ng {hi/e
int i,B#
do
{
System.out.println(i)#brea4#
i11#
$
{hi/eAiumEx
B2 ch8 in ra m
: contin"e #$i {hi/e< nP 12 x+c onh gi+ tro bi*" thGc #i7t ngay 1a"
'ile
int i,B#
do
{
System.out.println(i)#continue#
i11#
$
'ile(iL=B)#
Ia 12 >Hc m%t /ot in m # t]n
Bi 1 !rr!y
_a khai "*o A mdng ,/i zu l4nh sau, ,1 khHng ung p s ph@n
th
int}~ aL
_uy ,y, ,/i ^a,a, d`ng +S mt a%%ay, ta @n phdi khQi tRo
a%%ay E, ,1 l n1y phdi ung p s ph@n th
int}~ aL
a O n#b int}A88~L
(ai zu E th ,iJt lRi th1nh mt zu
int}~ a O n#b int}A88~L
^a,a sf khQi tRo mt mdng A88 ph@n th mu l1 int E *nh thq t
tG 8 Jn [[
2dng E gi* t%F @u: 2dng loRi n1y khHng @n n#b m1 Dng hng
@n s ph@n th
int}~ a O A,YZ,,,:AL
Cc "#thod v$i "%ng
I l#ngth
m#thod n1y sf ung p s ph@n th ]a mdng, ,$ d- ta mun g*n
gi* t%F s ho * ph@n th ]a mdng a
!o%(int iO8LikaTl#ngthLiee) aoioOiL l+u l1 l#ngth, khHng phdi
l#ngth()
I'yst#mTa%%ayopy
sid sh, "an @u ta E : mdng
int}~ s O A,X,Z,B,[,AA,AX,AZL
int}~ d O :,Y,,,A8,A:,AYL
m#thod a%%ayopy t%ong gEi 'yst#m
'yst#mTm#thodopy(s,X,d,:,Y)L
sf ho %a mt mdng d m/i l1 :,Y,B,[,AA,AX,AY
m#thod n1y sf thay thJ Y ph@n th, t$nh tG ph@n th thq : t%ong
mdng d, ")ng ng@n y ph@n th t$nh tG ph@n th thq X t%ong mdng s
Cc "#thod n&" trong cl!'' (!v!)util)*rr!y'
I ,oid so%t
E sf sxp cJp mt mdng s ttng d@n
int}~ s O :,B,AY,AAL
P%%aysTso%t(s)L
I int "ina%y'#a%h
E sf t<m ,F t%$ ]a mt ph@n th t%ong mt mdng, t%d ,m -A nJu
khHng t<m thy
int}~ s O :,B,AY,AAL
int n O P%%aysT"ina%y'#a%h(s,AY)L n sf ")ng :
+%ng nhi,u chi,u
int}~}~ O n#b int}A88~}Z8~L
(o3 khai "*o A mdng E gi* t%F @uT yzy l1 mdng : himu gm Y
ph@n th l1 Y mdng A himu, m&i mdng A himu hqa X ph@n th
int}~}~ a O

A, X, :,
Z, A8, AA,
[, , B,
Y, AZ, AY
L
Bi 1, - n+o@i lH
int x,yx
xhumxyhx}umx
xhxtyx
ihi chy on m ny bn 12 th5y x"5t hiOn thng b+o
Za#a./ang.rithmeticExce@tion< 'i#i'e by ero
V ch>?ng tr,nh 12 tho+t ra ngay /=c P. V"fn ch>?ng tr,nh chy ti7@ # [hng tho+t ra, ta
Pn KbtK ngoi /O ny, >a ra bi7n e, c"fi cwng in e A* xem / ngoi /O g,E
int (,y#
try
{
(,=B#y,(<=B#
(,(9y#
$
catc(E(ception e)
{
System.out.println(e.get?essage())#
$
PQ l< n+o@i lH BRS!e&*ionC
b* KndmK ngoi /O 'o b5t cG '`ng m no trong m%t @h>?ng thGc 1inh ra, bn cP th* [hai
b+o * ndm b ngoi /O P
public void divide() tro's E(ception
{
int a,A9B#
$
ho~c n7" m"fn KbtK ngoi /O P /i * xem P / ngoi /O g, * xe /&, bn KbtK nP rji in ra
try
{
int a,A9B#
$
catc(E(ception e)
{
System.out.println(e.get?essage())#
$
N7" m"fn ch>?ng tr,nh thnh cng th, 1inh thng b+o thnh cng, th5t bi th, 1inh thng
b+o ngoi /O, bn cP th* 'wng
boolean done,*alse#
try
{
int a,A9b#
done,true#
$
catc(E(ception e)
{
System.out.println(e.get?essage())#
$
i*(done,,true) System.out.println("Success*ul")#
Bi 1- . /#ctor 0"%ng kh1ng gi$i h2n '3 ph4n t56
>* m#thod t%ong "1i n1y n)m Q : lass Ka,aTutilTU#to% ,1
Ka,aTutilTnum#%ation
Khai "*o
U#to% ,t O n#b U#to%()L
hp dN li4u ho mt U#to% (lass >onsol# n)m t%ong gEi
o%#Ka,a)
+u l1 m&i ph@n th ]a U#to% mu phdi l1 mt i t+Sng, nn ta
phdi E n#b Wnt#g#%(n) khi mun +a ,1o mt "iJn kiu intT _+=ng
t ,/i 9yt#, ong, loat, TTT
do

int n O >onsol#T%#adWnt(00)L
i!(npO8) ,tTaddl#m#nt(n#b Wnt#g#%(n))L

bhil#(npO8)L
Wn %a * ph@n th ]a mt U#to%
!o%(int iO8Lik,tTsi{#()Liee)
'yst#mToutTp%intln(,tT#l#m#ntPt(i))L
y +a U#to% ,m kiu mdng ho d6 thao t*, ta +a ,m kiu
num#%ation (mt kiu mdng)
num#%ation # O ,tT#l#m#nts()L
h+ ,y ta E mdng # kiu num#%ation sao h\p y khuHn U#to%
,t d6 ch l$, khHng -ng Jn U#to% ,t
Wn %a * ph@n th ]a mt num#%ation
bhil#(#Thas2o%#l#m#nts())
'yst#mToutTp%intln(#Tn#ctl#m#nt())L
Bi 1T - 2U& n;i BlU& nV: *ron+ lU& ?"9!C
public class >est;rogram
{
static int currentCount#
static class Upple
{
int 'eigt#
public Upple(int 'eigt)
{
tis.'eigt,'eigt#
currentCount11#
$
public int !eigt()
{
return 'eigt#
$
$
public static void main(String args[])
{
Upple a,ne' Upple(=M)#994oi tao = 5uV tao nang =M4g
System.out.print(a.!eigt())#
$
$
Fy ta th5y /$@ n%i @@/e trong /$@ Ie1tsrogram, [hi bi\n 'och Ja#a 12 /m x"5t hiOn S
ki/e / Ie1tsrogram.c/a11 # Ie1tsrogram@@/e.c/a11. " i*m [hi 1e '(ng /$@ n%i /<
} th* hiOn t&nh Png gPi cao
} c+c /$@ n%i cP th* tr"y x"5t trlc ti7@ c+c bi7n ca /$@ cha
;>" _ / /$@ n%i [h+c #$i c+c /$@ m nRm ch"ng m%t ki/e, #& '( nh> t]@ tin VainC/a11.Za#a
'>$i Fy
public class ?ainClass
{
$
class Subclass
{
$
ihi bi\n 'och nP 12 to ra S ki/e / VainC/a11.c/a11 # B"bc/a11.c/a11
Bi 17 . 82o t9p tin (!r t: ch2y
sid sh h+=ng t%<nh ]a "Rn E ,1i !il# Tlass t%ong E !il# h+=ng
t%<nh h$nh l1 2ainV%oTlass hng hRnT
9Rn hy tRo mt !il# ly tn l1 mym!Tm! E ni dung nh+ sau
2ain->lass: 2ainV%o
9xt "u phdi h$nh c* nh+ thJ (tq l1 phdi E d cung dng),
khHng th< t%<nh hRy Ka% khHng hiu +ST
'au E "Rn ,1o j^PUP(2j5"in5 h\p tt d * tp tin Tlass
]a qng d-ng ,1 d mym!Tm! ,1o E, %i hRy Ka%T#c# ,/i tham s
dng l4nh nh+ sau
Ka% m!, mym!Tm! 2yV%og%amTKa% ITlass
_+=ng t nJu "Rn mun +a thm : th+ m- di%A ,1 di%: ,H !il#
^P th< "Rn Dng g
Ka% m!, mym!Tm! 2yV%og%amTKa% ITlass di%A di%:
_%<nh Ka% sf tRo !il# 2yV%og%amTKa% (tn kh* t`y "Rn) E th hRy
+S, khHng phdi d`ng l4nh Ka,a hay gid sh khHng E Wu gu#n
thu ]a "Rn
CHNG 2 - JAVA VW 2X5 TYZNH GIA4 [I\N B]NG ^_ING
b 7n /=c bn n\n 1e '(ng m%t E * cng #iOc ca m,nh nhanh chPng # ' 'ng h?n.
@@/et trW thnh j cq, ch=ng ta nh-y /"n 1ang MI B{ing
Bi 1 - G` Ia# 'J ^win+
Ch>?ng tr,nh ny 12 to m%t Jrame ?n gi-n nh5t
import %ava(.s'ing.28rame#
class Hello!orldS'ing
{
public static void main(String[] a)
{
28rame *rame,ne' 28rame("?ain 8rame")#99?ain 8rame la ten
cai cua so
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#99am dong
cua so lai
20abel label,ne' 20abel("Hello Everybody, label contain
conte(t")#99mot doi tuong do oa
*rame.getContent;ane().add(label)#99dua doi tuong do oa
vao trong *rame
*rame.pac4()#99"dong goi" lai toan bo trin do oa
*rame.set@isible(true)#99ien ti trin do oa ra man
in
$
$
bFy / m%t rame ?n gi-n [h+c, nh>ng cP th* 'wng ' 'ng cho #iOc mW r%ng ch>?ng
tr,nh
import %ava(.s'ing.28rame#
import %ava.a't.&#
class E(ecute e(tends 28rame
{
Container container , getContent;ane()#
public E(ecute(String title)
{
super(title)# 99tuong duong 28rame(title)
0abel label,ne' 0abel("Hello Everybody, label contain
conte(t")#
container.add(label)#
$
public static void main(String a[])
{
E(ecute e(e , ne' E(ecute("8rame")#IIIIIIII
e(e.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
e(e.pac4()#
e(e.set@isible(true)#
$
$
H$ *rb *i)n+ ViH*
^i- 1e bn m"fn n=t b5m ca bn cP '`ng KViOt NamK # bn [hng bi7t in nh> th7 no,
ch>?ng tr,nh 1a" 12 gi=@ bn
JB"tton bhne{ JB"ttonAKVi"uECt NamKEx
"uEC / m nico'e ca [& tl O m Ja#a hQ trH. I5t c- [& tl ViOt 6" >Hc hQ trH trong
;atin # ;atin Exten'
;>" _ / ch8 cP Za#ax.1{ing m$i hQ trH, Za#a.a{t [hng hQ trH
Bi 2 - Ci IN* 8; n+"e ' 6c ?iHn !"o !9! Idi *0bn+ IA "e
C+c fi t>Hng j h3a 1W 'y cP th* hot %ng >Hc / nh0 cP c+c b% nghe KngheK c+c hnh
%ng m ng>0i 'wng t>?ng t+c #$i ch"%t hay bn @h&m, # t9 P cho ra c+c 1l [iOn t>?ng
Gng.
Irong #& '( '>$i Fy ta cP c/a11 E#ent"it / m%t b% nghe, b% nghe ny thlc hiOn @h>?ng
thGc actionserkorme' ch&nh / chGa nhng 1l [iOn ca b% nghe P. bfi t>Hng e#ent"it /
m%t in1tance ca c/a11 E#ent"it. b* ci ~t b% nghe ny cho fi t>Hng j h3a b"tton ta
'wng @h>?ng thGc a''ction;i1tener.
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core e(tends 28rame
{
Container container , getContent;ane()#
public Core(String title)
{
super(title)#
)utton button , ne' )utton("?y button")#
EventYuit eventYuit,ne' EventYuit()#
button.addUction0istener(eventYuit)#
container.add(button)#
$
public static void main(String a[])
{
Core e(e , ne' Core("8rame")#
e(e.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
e(e.pac4()#
e(e.set@isible(true)#
$
class EventYuit implements Uction0istener
{
public void action;er*ormed(UctionEvent e)
{
System.e(it(B)#
$
$
$
BFy gi0, n7" ta m"fn r=t g3n, ci ~t b% nghe # hnh %ng trlc ti7@, ta /m nh> 1a"
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
*inal 2)utton button , ne' 2)utton("?y button")#
button.addUction0istener(ne' Uction0istener()
{
public void action;er*ormed(UctionEvent e)
{
i*(e.getSource(),,button) System.e(it(B)#
99nZu event n[y c\ source do button sin ra
$
$)#
*rame.add(button)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.pac4()#
*rame.set@isible(true)#
$
$
Bi ( - 6e*2/o#*Bn#llC Ii Ifi 'Ui 6e*Bo#nd6
1et;ayo"t mnh nh5t trong B{ing / 1et;ayo"tAn"//E cho fi t>Hng a'', c`n fi #$i fi
t>Hng bo a'' th, 1etBo"n'1, c= @h+@ 1etBo"n'1Ax,y,{i'th,heightE
Ir\n monitor, Ja#a t&nh i*m cP t3a % Am,mE / i*m tr+i tr\n cwng. Ba" P tr(c honh AxE
/ chi6" ngang monitor t9 tr+i 1ang @h-i # tr(c t"ng AyE / chi6" '3c monitor t9 tr\n x"fng
'>$i.
sh>?ng thGc ny 12 to ra m%t h,nh ch nh]t -o bao 4"anh fi t>Hng bo a'', h,nh ch nh]t
ny cP t3a % gPc !" ti\n / Ax,yE # 'i {i'th cao height. V& '( nh> bi 1a"<
import %ava(.s'ing.28rame#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
*rame.set0ayout(null)#
2)utton b= , ne' 2)utton(")utton =")#
b=.set)ounds(B,B,=BB,MA)#
*rame.add(b=)#
2)utton bM , ne' 2)utton(")utton M")#
bM.set)ounds(=BB,B,=BB,MA)#
*rame.add(bM)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.set@isible(true)#
$
$
Nh> #]y / ch=ng ta 1et;ayo"tAn"//E cho krame # /!n />Ht 1etBo"n'1 A[&ch th>$c ccng
nh> #o tr&E cho S b"tton. V]y * 1et [&ch th>$c ccng nh> #o tr& cho ch&nh krame th, 'wng S
@h>?ng thGc 1a"<
import %ava(.s'ing.28rame#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
*rame.set0ayout(null)#
2)utton b= , ne' 2)utton(")utton =")#
b=.set)ounds(B,B,=BB,MA)#
*rame.add(b=)#
2)utton bM , ne' 2)utton(")utton M")#
bM.set)ounds(=BB,B,=BB,MA)#
*rame.add(bM)#
*rame.set0ocation(MBB,=BB)#III4o c]y
*rame.setSi^e(MBB,HB)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.set@isible(true)#
$
$
Bi ny y chang bi tr\n, cP [h+c / gi0 Fy #o tr& i*m !" ca krame >Hc x+c onh
bRng 1et;ocation, N7" [hng 1et;ocation, m~c onh / Am,mE c`n [&ch th>$c >Hc x+c onh
bRng 1etBie. ;>" _ / Smmhchi6" 'i S c+i b"tton c%ng /i c`n mhchi6" r%ng b"tton a
chi6" r%ng thanh ban !" Ah|nE.
Bi , - 6e*2/o#* ?"fn+ &"g *"#;! &"hn +iii :n "3n"
V$i c+c Gng '(ng nh th, ch>a c!n 4"an tFm /m. V$i c+c Gng '(ng tr"ng b,nh # /$n th,
Gng '(ng Kco ginK twy theo % @hFn gi-i 12 / /Hi th7 /$n. Ia cP th* /5y % @hFn gi-i hiOn
hnh # twy bi7n Gng '(ng nh> 1a"<
import %ava(.s'ing.28rame#
import %ava.a't.&#
public class Core
{
public static void main(String[] args)
{
>ool4it 4it , >ool4it.getWe*ault>ool4it()#
Wimension screenSi^e , 4it.getScreenSi^e()#
int screen!idt , screenSi^e.'idt#
int screenHeigt , screenSi^e.eigt#
28rame *rame , ne' 28rame("?y *rame")#
*rame.setSi^e(screen!idt,screenHeigt)#
*rame.set+esi^able(*alse)#993guoi dung 4ong te tay doi
duoc si^e cua min
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.set@isible(true)#
$
$
Bi - . Cc ;3i t<=ng ;> h?! c@ A%n c! B!v!
I 9utton
9utton "uttonOn#b 9utton(0K0)L
add("utton)L
ho3 add(n#b 9utton(0K0))L
9utton sh d-ng Ptionist#n#% ngh# s ki4n ,1 t%uymn h1nh
ng
I a"#l
a"#l la"#lOn#b a"#l(0_h# sum o! ,alu#s h#%#:0)L
a"#l l1 nhn
I Van#l
Van#l pan#lOn#b Van#l()L
Van#l l1 khung hqaT
Bi T - C"e!?8oS
Chec[box 'wng * ch"y*n qi trng th+i A1tateE gia ye1tno hay tr"etka/1e. ihi 1tate / tr"e
th, >Hc +nh '5". CP | in1tr"ctor th>0ng 'wng /<
Chec[boxAE Chec[boxABtring /abe/E Chec[boxABtring /abe/,boo/ean 1tateE #$i /abe/ hi*n tho
nhn c`n 1tate / tr"etka/1e
b* x+c /]@ 1tate cho m%t Chec[box ta 'wng @h>?ng thGc 1etBtateAtr"eE
b* /5y 1tate hiOn hnh ca m%t Chec[box ta 'wng @h>?ng thGc getBtateAE
b* xe /& t,nh h"fng ca Chec[box [hi nP thay qi trng th+i, ta @h-i cho nP im@/ement1
giao 'iOn tem;i1tener, # b\n trong nP cP @h>?ng thGc itemBtateChange'AtemE#ent eE.
C`n * Chec[box thlc hiOn nhng hnh %ng ca /$@ 5y th, ta @h-i 'wng @h>?ng thGc
a''tem;i1tener.
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
Cec4bo( cec4bo(,ne' Cec4bo(("Wocuments",*alse)#
cec4bo(.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
System.out.println("Canged")#
$
$)#
*rame.add(cec4bo()#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.pac4()#
*rame.set@isible(true)#
$
$
#& '( ny th, mQi /!n bn thay qi trng th+i Chec[box, mn h,nh Con1o/e 12 in ra cF"
KChange'K BFy gi0 n7" bn m"fn mn h,nh in ra ch8 [hi no nP >Hc ch3n m thi, th,
1ea /i @h>?ng thGc itemBtateChange' nh> 1a"
ikAe.getBtateChangeAEhhtemE#ent.BE;ECIEE By1tem.o"t.@rint/nAKChange'KEx
BE;ECIE # EBE;ECIE / S hRng 1f bi*n 'in trng th+i tr"e hay ka/1e ca
Chec[box
Bi F - C"e!?8oS n"iJ# *j/ !"en BC"e!?8oSGro#&C
b!" ti\n, hy to m%t nhPm Chec[box nh> 1a" Chec[box^ro"@ ghne{ Chec[box^ro"@AEx
Ba" P >a c+c Chec[box m"fn >a #o nhPm Chec[box P nh> 1a"
Chec[box cuhne{ Chec[boxAKO@tion uK,g,tr"eEx
Chec[box cShne{ Chec[boxAKO@tion SK,g,ka/1eEx
Chec[box cShne{ Chec[boxAKO@tion SK,g,ka/1eEx
C- | c+i cwng mang gi+ tro ka/1e ccng >Hc, nh>ng n7" / tr"e th, ch8 >Hc m%t c+i tr"e
Bi t]@ 1a" 12 to m%t Chec[box^ro"@ cP | Chec[box. b* /i1tener bi7t / Chec[box no
>Hc ch3n, ta 'wng @h>?ng thGc gettem Atr- #6 ObZectE ;>" _ / * c- | Chec[box cwng
hi*n tho tr\n krame, ta 'wng sane/
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
Cec4bo(Kroup g,ne' Cec4bo(Kroup()#
Cec4bo( c=,ne' Cec4bo(("Dption =",g,true)#
Cec4bo( cM,ne' Cec4bo(("Dption M",g,*alse)#
Cec4bo( cO,ne' Cec4bo(("Dption O",g,*alse)#
?y-tem0istener listener , ne' ?y-tem0istener()#
c=.add-tem0istener(listener)#
cM.add-tem0istener(listener)#
cO.add-tem0istener(listener)#
;anel panel,ne' ;anel()#
*rame.add(panel)#
panel.add(c=)#
panel.add(cM)#
panel.add(cO)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.pac4()#
*rame.set@isible(true)#
$
$
class ?y-tem0istener implements -tem0istener
{
public void itemStateCanged(-temEvent e)
{
i*(e.getStateCange(),,-temEvent.SE0EC>EW)
{
Db%ect temp,e.get-tem()#
String s,(String)temp#
System.out.println(s)#
$
$
$
;>" _ ABtringEtem@ thlc ra / /5y c+i /abe/ ca ObZect tem@. S /Onh cP th* thay th7 bRng u
/Onh Btring 1hABtringEe.gettemAEx
Bi K - C"oi!e
Choice myChoice h ne{ ChoiceAEx
1a" P >a m(c ch3n #o Choice nh> 1a"
myChoice.a''temAKe'KEx
myChoice.a''temAK^reenKEx
myChoice.a''temAKB/"eKEx
ihi P | m(c ch3n >Hc +nh 1f /!n />Ht / m,u,S A~t / i< thG tl m(c ch3nE
b* b m(c ch3n no ra [hi Choice, ta 'wng myChoice.remo#eAiE #$i i / thG tl m(c ch3n
b* b t5t c- m(c ch3n [hi Choice, ta 'wng myChoice.remo#e//AE
b* ch3n m(c ch3n no trong Choice, ta 'wng m"Choice.1e/ectAiE
;>" _ / ta cP th* 'wng 1f thG tl ho~c nhn 6" >Hc, #& '( myChoice.remo#eAKB/"eKE hay
myChoice.remo#eASE 6" >Hc. V n7" cP um m(c ch3n cP nhn / KB/"eK th,
myChoice.remo#eAKB/"eKE ch8 xPa m(c ch3n !" ti\n nP t,m th5y
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
Coice myCoice , ne' Coice()#
myCoice.add-tem("+ed")#
myCoice.add-tem("Kreen")#
myCoice.add-tem(")lue")#
myCoice.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
i*(e.getStateCange(),,-temEvent.SE0EC>EW)
{
String s,(String)e.get-tem()#
System.out.println(s)#
$
$
$)#
*rame.add(myCoice)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.pac4()#
*rame.set@isible(true)#
$
$
Bi 9 . Ci't
U/i >h#k"oc, ta hi E th han giNa : t%Rng th*i t%u#M!als# ]a
mt i t+SngT U/i >h#k"ocs%oup ,1 >hoi#, ta hi E th mt
t%ong * i t+SngT U/i ist, ta E th han mt ,1i i t+Sng,
thm h$ han hJtT
23 Fnh ]a mt ist l1 hi hin thF ti a Y ph@n thT >* ph+=ng
thq khQi tRo:
ist() sf tRo mt ist m&i l@n han hi han +S mt h1ng (=n
han)
ist(int num) sf tRo mt danh s*h m&i l@n han m&i l@n han hi
han +S mt h1ng, nh+ng sf hin thF num h1ng hq khHng phdi
l1 Y nh+ m3 Fnh
ist(int num,"ool#an multi2od#) y hang *i t%n, nh+ng thm l1
m&i l@n han +S han nhimu ph@n th mt l (nJu multi2od# l1
t%u#) (a han)
h+ ,y ist(B) ,1 ist(B,!als#) l1 nh+ nhau, hin thF B h1ng mt
l ,1 m&i l@n han hi han +S mt h1ng
y add ph@n th ,1o ist:
ist myistOn#b ist(X,t%u#)L
myistTadd(0Vasal0)L
myistTadd(0>55>ee0)L
myistTadd(0U90)L
myistTadd(0^a,a0)L
>* ph@n th Dng +S *nh thq t tG 8T y thm ph@n th ,1o ,F
t%$ n1o ta +a ,1o hi s ta th$h, ,$ d-
myistTadd(0Pss#m"l#%0,8)L
y thay thJ mt ph@n th tRi ,F t%$ n1o ta d`ng ph+=ng thq
myistT%#pla#Wt#m(0U9T_0,:)L MMU9 "F thay ")ng U9T_
y cEa mt ph@n th n1o ta d`ng ph+=ng thq %#mo,#(i)
myistT%#mo,#(X)L hay myistT%#mo,#(0^a,a0)L mu +ST U1 nJu
E A8 m- han E nhn l1 0^a,a0 th< myistT%#mo,#(0^a,a0) hi
cEa ph@n th @u tin nE t<m thy
y cEa tt d ta d`ng myistT%#mo,#Pll()L
y han ph@n th ,1 " han ph@n th ta d`ng s#l#t(i) ,1
d#s#l#t(i)
Bi 1L - 2: 'iH! 'Ui 2i6*
: V$i ;i1t ?n ch3n
b* bi7t >Hc @h!n te no >Hc ch3n, ta 'wng S @h>?ng thGc int getBe/ecte'n'exAE #
Btring getBe/ecte'temAE
int getBe/ecte'n'exAE 12 tr- #6 1f thG tl ca @h!n te >Hc ch3n, n7" [hng cP @h!n te
no th, tr- #6 }u
Btring getBe/ecte'temAE 12 tr- #6 /abe/ ca @h!n te >Hc ch3n, n7" [hng cP @h!n te
no th, tr- #6 KK
*inal 0ist l,ne' 0ist()#
l.add(";ascal")#
l.add("C__C11")#
l.add("@)")#
l.add("2ava")#
*rame.add(l)#
l.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
System.out.println(l.getSelected-nde(()1"
"1l.getSelected-tem())#
$
$)#
: V$i ;i1t a ch3n
b* bi7t >Hc nhng @h!n te no >Hc ch3n, ta 'wng S @h>?ng thGc intCD
getBe/ecte'n'ex1AE # BtringCD getBe/ecte'tem1AE
intCD getBe/ecte'n'ex1AE / m%t m-ng 12 tr- #6 nhng 1f thG tl ca c+c @h!n te >Hc
ch3n, n7" [hng cP @h!n te no th, tr- #6 }u
BtringCD getBe/ecte'tem1AE / m%t m-ng 12 tr- #6 nhng /abe/ ca c+c @h!n te >Hc
ch3n, n7" [hng cP @h!n te no th, tr- #6 KK
*inal 0ist l,ne' 0ist(O,true)#
l.add(";ascal")#
l.add("C__C11")#
l.add("@)")#
l.add("2ava")#
*rame.add(l)#
l.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
int[] a,l.getSelected-nde(s()#
String[] b,l.getSelected-tems()#
*or(int i,B#iLa.lengt#i11)
System.out.println(aQiQ)#
*or(int %,B#%Lb.lengt#%11)
System.out.println(b[%])#
$
$)#
Bi 11 . 8#DtEi#ld v 8#Dt*r#!
I _#cti#ld
>E Y ph+=ng thq khQi tRo
_#cti#ld() khHng thm g< d
_#cti#ld('t%ing s) ,/i s l1 hu&i "an @u cut hi4n t%n _#cti#ld
(,$ d- 0Wnput you% nam# h#%#0)
_#cti#ld(int num) ,/i num l1 d1i _#cti#ld
_#cti#ld('t%ing s,int num) ,/i s l1 hu&i "an @u cut hi4n t%n
_#cti#ld ,1 num l1 d1i _#cti#ld
I _#ctP%#a
>E Y ph+=ng thq khQi tRo
_#ctP%#a() khHng thm g< d
_#ctP%#a('t%ing s) ,/i s l1 hu&i "an @u cut hi4n t%n _#ctP%#a
_#ctP%#a(int %ob,int olumn) ,/i %ob ,1 olumn l1 s h1ng ,1 t
t%n _#cti#ld
_#cti#ld('t%ing s,int %ob,int olumn) l1 @y ] nht kJt hSp :
ph+=ng thq khQi tRo t%n
I >* ph+=ng thq ]a _#cti#ld ,1 _#ctP%#a
y+a ni dung ,tn "dn ,1o ")ng ,oid s#t_#ct('t%ing tct)
y ni dung ,tn "dn %a ")ng 't%ing g#t_#ct()
y ni dung ,tn "dn ang +S *nh du ("Hi #n) %a ")ng 't%ing
g#t'#l#t#d_#ct()
y ng+vi d`ng khHng th thay |i ni dung ")ng ,oid
s#tdita"l#(!als#) (m3 Fnh l1 t%u#)
y3 "i4t l1 _#cti#ld E mt ph+=ng thq m1 _#ctP%#a khHng E,
E l1 ,oid s#tho>ha%(ha% )T U$ d- s#tho>ha%(.I.) th< ph+=ng
thq n1y sf khiJn ho tt d k$ t nhp ,1o _#cti#ld mu hi hin
thF l1 k$ t .I. (%t hNu d-ng khi nhp passbo%d)
I Vh+=ng thq d`ng hung ,/i _#cti#ld
sid sh nJu "Rn mun l1m %a mt h+=ng t%<nh "dng t$nh, dN li4u
nhp ,1o _#cti#ld, "zy giv mun huyn dN li4u y %a s th
t$nh to*n
sOt#cti#ldTg#t_#ct()L
,alu#AOloatTpa%s#loat(s)L
_+=ng t ,/i
9yt#Tpa%s#9yt#,Wnt#g#%Tpa%s#Wnt,uou"l#Tpa%s#uou"l#,TTT
Bi 12 - ^!roll8r B*"n" *r0b*C
Bcro//bar >Hc c]@ nh]t theo | t,nh h"fng "nit,b/oc[ # ab1o/"te
} ihi ng>0i 'wng c/ic[ ch"%t #o mci t\n W S !" Bcro//bar th, "nit n-y 1inh, thanh tr>Ht 12
tl %ng tr9 i hay c%ng th\m #o tr& ca con tr>Ht u ?n #o Ata cP th* thay qi gi+ tro ny,
m~c onh / uE
} ihi ng>0i 'wng c/ic[ ch"%t #o [ho-ng gia thanh tr>Ht # #o tr& hiOn hnh th, b/oc[ n-y
1inh, con tr>Ht 12 'och ch"y*n m%t [ho-ng / b/oc[
} ihi ng>0i 'wng nm #o #o tr& hiOn ti ca con tr>Ht # /i A'ragE nP t9 #o tr& ny 1ang #o
tr& [h+c, ab1o/"te n-y 1inh
: ihWi to thanh tr>Ht
Bcro//barAE / ?n gi-n nh5t, m~c onh / thanh tr>Ht Gng
Bcro//barAint orientationE #$i orientation / Bcro//bar.LOONI; AngangE hay
Bcro//bar.VEIC; AGngE
Bcro//barAint orientation,int @o1ition,int b/oc[,int min,int maxE / !y nh5t, #& '(
Bcro//barABcro//bar.LOONI;,nm,un,m,ummE tGc / thanh tr>Ht ngang, @hm #i t9 m
7n umm, #o tr& ban !" ca con tr>Ht / nm Agia thanhE [hi t,nh th"fng b/oc[ x-y ra th, con
tr>Ht 'i ch"y*n un
: C+c @h>?ng thGc ca thanh tr>Ht
b* thay qi gi+ tro "nit Am~c onh / uE ta 'wng 1etnitncrementAint "nitE #$i "nit m$i
b* thay qi gi+ tro b/oc[ ta 'wng 1etB/oc[ncrementAint b/oc[E #$i b/oc[ m$i
b* bi7t #o tr& hiOn hnh ca con tr>Ht ta 'wng int getVa/"eAE
: Vi7t b% nghe # hnh %ng cho thanh tr>Ht
b* xe /& t,nh h"fng ca Bcro//bar [hi nP thay qi trng th+i, ta @h-i cho nP im@/ement1
giao 'iOn 'Z"1tment;i1tener, # b\n trong nP cP @h>?ng thGc
a'Z"1tmentVa/"eChange'A'Z"1tmentE#ent eE. C`n * Bcro//bar thlc hiOn nhng hnh
%ng ca /$@ 5y th, ta @h-i 'wng @h>?ng thGc a'''Z"1tment;i1tener.
I"y #]y, m%t thanh tr>Ht th, mQi [hi t+c %ng 7n nP, nP @h-i Kc"%nK m%t c+i g, 5y.
V"fn 'Z"1tment;i1tener +@ Gng mQi [hi ta Kc"%nK th, c!n 'Z"1tmentE#ent e bi7t >Hc
#o tr& con tr>Ht ang W F", ta 'wng e.getVa/"eAE. V& '( 1a" / thanh tr>Ht # Iextie/'
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
;anel p,ne' ;anel()#
*rame.add(p)#
Scrollbar s,ne'
Scrollbar(Scrollbar.HD+-`D3>U0,B,=B,B,=BB)#
p.add(s)#
*inal >e(t8ield t,ne' >e(t8ield(=BB)#
t.setEditable(*alse)#
p.add(t)#
s.addUd%ustment0istener(ne' Ud%ustment0istener()
{
public void ad%ustment@alueCanged(Ud%ustmentEvent
e)
{
int current;os,e.get@alue()#
String te(t,""#
*or(int i,B#iLcurrent;os#i11) te(t1,a&a#
t.set>e(t(te(t)#
$
$)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.pac4()#
*rame.set@isible(true)#
$
$
BFy gi0 th, mQi /!n bn [do con tr>Ht th, [& tl : /y thay qi trong Iextie/' t.
Bi 1 . Cc ;3i t<=ng khung chF! 0cont!in#r6 v AG Hu%n lI
trJnh Ay 0l!yout "!n!g#r6
Khung hqa nEi nHm na l1 nhNng *i khung t%anh "Rn @n d*n
nhNng n\t ,f (i t+Sng haa) ]a "Rn ln ET U1 sxp cJp *
i t+Sng n1y t%n khung hqa th< a @n t/i " gudn l$ t%<nh "1yT
- Khung hqa m1 "Rn gu#n thu l1 %am#T E ging nh+ ha
s| ]a indobs ,1 hqa to1n " qng d-ng ]a "Rn
- 2t khung hqa kh* m1 "Rn "iJt gua l1 Van#lT E ging nh+
mt *i "dng hin thi @y ] * th1nh ph@n s7W m1 "Rn mun
tng ln %am#
- hNng *i n lRi sf ha sauT _t d * l/p %am#,Van#l,TTT mu
l1 on ]a l/p >ontain#%
I >* ph+=ng thq ]a >ontain#% (* ph+=ng thq hung ]a *
i t+Sng khung hqa)
>ompon#nt add(>ompon#nt ) +a mt i t+Sng ,1o khung
hqaT U$ d- !%am#Tadd(pan#l)L
,oid %#mo,#(>ompon#nt ) +a mt i t+Sng %a khi khung
hqaT U$ d- !%am#T%#mo,#(pan#l)L
Bi 1, - N"k! l@i 'J Jlr:e
sh!n u nPi #6 Jrame, bFy gi0 ch8 nhc /i
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
99*rame 4ong pu tuoc do pan giai man in
>ool4it 4it , >ool4it.getWe*ault>ool4it()#
Wimension screenSi^e , 4it.getScreenSi^e()#
int screen!idt , screenSi^e.'idt#
int screenHeigt , screenSi^e.eigt#
int *rame!idt , MBB#
int *rameHeigt , HB#
28rame *rame , ne' 28rame("?y *rame")#
*rame.set0ayout(null)#
*rame.set0ocation((screen!idt<*rame!idt)9M,
(screenHeigt<*rameHeigt)9M)#
*rame.setSi^e(*rame!idt,*rameHeigt)#
*rame.set+esi^able(*alse)#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
99tao )utton E(it cai dat puong tuc an dong 5ua class
rieng
)utton b= , ne' )utton("E(it")#
b=.set)ounds(B,B,=BB,MA)#
*rame.add(b=)#
EventYuit eventYuit,ne' EventYuit()#
b=.addUction0istener(eventYuit)#
99tao )utton Ubout cai dat puong tuc an dong truc
tiep
*inal )utton bM , ne' )utton("Ubout")#
bM.set)ounds(=BB,B,=BB,MA)#
*rame.add(bM)#
bM.addUction0istener(ne' Uction0istener()
{
public void action;er*ormed(UctionEvent e)
{
i*(e.getSource(),,bM)
System.out.println("?ade in @ietnam")#
$
$)#
*rame.set@isible(true)#
$
$
class EventYuit implements Uction0istener
{
public void action;er*ormed(UctionEvent e)
{
System.e(it(B)#
$
$
Bi tr\n 'wng /i c+c [i7n thGc h3c tr>$c Fy< 1et;ayo"tAn"//E # 1etBo"n'1, ~t Gng
'(ng gia mn h,nh # [hng @h( th"%c @hFn gi-i mn h,nh nh0 'wng Ioo/[it, S c+ch ci
~t @h>?ng thGc hnh %ng 4"a c/a11 ri\ng # ci ~t trlc ti7@.
Bi 11 - T@o ' dd "n+ lo@* 8#**on
Bn hy cG t>Wng t>Hng n7" bn @h-i a'' [ho-ng |m b"tton #o rame ca m,nh, bn @h-i
#i7t [ho-ng |m cF" /Onh [hWi to, a'' r5t / mOt. Ly * m+y tl %ng /m cho bn, ch8 #$i
#i #`ng /~@. Bn c!n 'wng m%t b-ng Btring * />" nhng /abe/ ca b"tton # m%t m-ng
B"tton * />" ch&nh nhng b"tton. bjng th0i ccng 'la #o m-ng B"tton 5y * ci ~t
@h>?ng thGc hnh %ng
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core e(tends 28rame implements Uction0istener
{
;anel p,ne' ;anel()#
*inal String[]
a,{"8ile","Edit","@ie'","-nsert","8ormat",">able","!indo's","Help"$#
*inal )utton[] b,ne' )utton[a.lengt]#
public Core(String title)
{
set>itle(title)#
setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
add(p)#
setSi^e(ABB,HB)#
*or(int i,B#iLa.lengt#i11)
{
bQiQ,ne' )utton(aQiQ)#
p.add(bQiQ)#
bQiQ.addUction0istener(tis)#
$
set@isible(true)#
$
public void action;er*ormed(UctionEvent e)
{
*or(int i,B#iLa.lengt#i11)
i*(e.getSource(),,bQiQ) System.out.println(".ou
ave clic4ed button "1aQiQ)#
$
public static void main(String args[])
{
Core c,ne' Core("?y *rame")#
$
$
BW 'y trong bi ny ta 'wng [hWi to ca Core / * 1e '(ng a''ction;i1tenerAthi1Ex
Bi 1T - Gen#Br-Gen# ' Gen#I*e:
: Ven"Bar # Ven"
b* th5y >Hc c+c Ven" nh> i/e, E'it, Le/@ nh> tr\n m%t cea 1q Min'o{1 thng th>0ng
th, t5t c- c+c fi t>Hng Ven" 5y @h-i >Hc a'' #o m%t Ven"Bar. b* Ven"bar cP th* x=Ft
hiOn trong Jrame th, ta 'wng @h>?ng thGc 1etVen"BarAmen"BarE. Ch>?ng tr,nh 1a" minh
h3a m%t Gng '(ng nh> #]y
import %ava(.s'ing.28rame#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
?enu)ar menu)ar,ne' ?enu)ar()#
*.set?enu)ar(menu)ar)#
?enu *ile,ne' ?enu("8ile")#
menu)ar.add(*ile)#
?enu edit,ne' ?enu("Edit")#
menu)ar.add(edit)#
?enu elp,ne' ?enu("Help")#
menu)ar.setHelp?enu(elp)#
99pan code duoi tem vao day
*.setSi^e(MBB,HB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Ven" # Ven"tem
C`n * Ne{, O@en, Ba#e hiOn ra trong men" i/e th, c+c Ven"tem 5y @h-i >Hc
a'' #o men" i/e. Ia th\m #o nh> 1a"
Ven"tem ne{temhne{ Ven"temAKNe{KEx
ki/e.a''Ane{temEx
Ven"tem o@entemhne{ Ven"temAKO@enKEx
ki/e.a''Ao@entemEx
Ven"tem 1a#etemhne{ Ven"temAKBa#eKEx
ki/e.a''A1a#etemEx
1a#etem.1etEnab/eAka/1eEx
tt@han co'e '"oi them #ao 'ay
ki/e.a''Be@aratorAEx tt@h"ong th"c nay '"a mot hang @han cach #ao men" i/e
Ven"tem exittemhne{ Ven"temAKExitKEx
ki/e.a''AexittemEx
b* cho m%t Ven"tem [hng th* ch3n >Hc, ta 'wng @h>?ng thGc 1etEnab/eAka/1eE
Am~c onh / tr"eE #& '( nh> tr\n 1a#etem.1etEnab/eAka/1eEx bi6" ny ~c biOt h"
&ch #$i Gng '(ng #n b-n ch>a cP ch no th, [hng n\n cho ng>0i 'wng ch3n
Ven"tem 1a#etem
: Ven" # 1"bmen"
b* to m%t Ven"tem chGa m%t Ven" [h+c A1"bmen"E, ta ch8 #iOc to Ven" P rji
a'' #o men" item [ia / xong. Ia th\m #o nh> 1a"
Ven" @rinthne{ Ven"AKBet"@ srintKEx
ki/e.a''A@rintEx
Ven"tem @re#ie{temhne{ Ven"temAKsre#ie{KEx
@rint.a''A@re#ie{temEx
Ven"tem @rinttemhne{ Ven"temAKsrintKEx
@rint.a''A@rinttemEx
tt@han co'e '"oi them #ao 'ay
: Chec[boxVen"tem
Bn ccng cP th* to m%t m(c ch3n cP [h- nng +nh '5" bRng c+ch 1e '(ng /$@
Chec[boxVen"tem
Chec[boxVen"tem a"to1a#ehne{ Chec[boxVen"temAK"to Ba#eKEx
ki/e.a''Aa"to1a#eEx
Ngoi ra c`n m%t @h>?ng thGc [hWi to [h+c / Chec[boxVen"tem a"to1a#ehne{
Chec[boxVen"temAK"to Ba#eK,tr"eEx V~c onh / ka/1e Ach>a ch3nE
Bi 1F - 7"`i *@o ' !i IN* &"0Dn+ *"E! "n" I;n+ "n+ lo@*
Bn hy cG t>Wng t>Hng n7" bn @h-i /m m%t Gng '(ng gifng nh> Vicro1okt Mor' Ach8
m$i nPi Mor' thi chG ch>a '+m (ng t$i shoto1ho@, Core/ g, c-E #$i m%t / Ven" # mQi
Ven" cP h?n ch(c c+i Ven"tem. V]y th, bn @h-i [hWi to, @h-i a'' r5t / mOt. Ly *
m+y tl %ng /m cho bn, ch8 #$i #i #`ng /~@. Bn c!n 'wng m%t b-ng Btring * />"
nhng /abe/ ca men" # m%t m-ng Ven" * />" ch&nh nhng men".
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
?enu)ar menu)ar,ne' ?enu)ar()#
*.set?enu)ar(menu)ar)#
*inal String[]
menu0abel,{"8ile","Edit","@ie'","-nsert","8ormat",">able","!indo's","Help
"$#
*inal ?enu[] menu,ne' ?enu[menu0abel.lengt]#
*or(int i,B#iLmenu0abel.lengt#i11)
{
menuQiQ,ne' ?enu(menu0abelQiQ)#
menu)ar.add(menuQiQ)#
$
*inal String[]
*ile?enu-tem0abel,{"3e'","Dpen","Save","E(it"$#
*inal ?enu-tem[] *ile?enu-tem,ne'
?enu-tem[*ile?enu-tem0abel.lengt]#
*or(int i,B#iL*ile?enu-tem0abel.lengt#i11)
{
*ile?enu-temQiQ,ne' ?enu-tem(*ile?enu-tem0abelQiQ)#
menu[B].add(*ile?enu-temQiQ)#
i*(i,,M) menu[B].addSeparator()#
$
*ile?enu-tem[O].addUction0istener(ne' Uction0istener()
{
public void action;er*ormed(UctionEvent e)
{
System.e(it(B)#
$
$)#
*.setSi^e(CBB,HB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 1K - ^!roll5ne
import %ava(.s'ing.28rame#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
Scroll;ane s,ne' Scroll;ane()#
>e(tUrea t,ne' >e(tUrea()#
s.add(t)#
*.add(s)#
*.setSi^e(MBB,=MB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 1m - 2oo?Andleel B!i: n#n +io diHnC
;oo[n'ee/ A#i7t tt / ;a g3i / c-m 4"an giao 'iOn cho Gng '(ng. Be '(ng r5t ?n
gi-n
Vanager.1et;oo[n'ee/ABtring c/a11NameE #$i Vanager / m%t c/a11 c`n
c/a11Name / t\n c/a11 chGa c+i ;a P. Ja#a hQ trH 1zn | c+i /<
Za#ax.1{ing.@/ak.meta/.Veta/;oo[n'ee/ Agiao 'iOn Ja#aE
com.1"n.Za#a.1{ing.@/ak.{in'o{1.Min'o{1;oo[n'ee/ Agiao 'iOn Min'o{1E
com.1"n.Za#a.1{ing.@/ak.motik.Votik;oo[n'ee/ Agiao 'iOn NXE
Ba" [hi 1et, * giao 'iOn hi*n tho tr\n Jrame no, c!n c]@ nh]t tr\n Jrame P bRng
@h>?ng thGc 1a"
B{ingti/itie1."@'ateCom@onentIreeAmyrameE Amyrame / t\n Jrame c!n c]@ nh]tE
V& '( 1a" 12 minh h3a c+ch thay qi ;a 'la #o Chec[box^ro"@. C!n nPi th\m /
@h>?ng thGc Vanager.1et;oo[n'ee/ABtring c/a11NameE bt b"%c @h-i xe /& ngoi /O
import %ava(.s'ing.28rame#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
*inal 28rame * , ne' 28rame("?y 28rame")#
*inal String[] a,{"?etal","!indo's","?oti*"$#
*inal Cec4bo([] b,ne' Cec4bo([a.lengt]#
*inal String[] c,ne' String[a.lengt]#
Cec4bo(Kroup g,ne' Cec4bo(Kroup()#
c[B],"%ava(.s'ing.pla*.metal.?etal0oo4Und8eel"#
c[=],"com.sun.%ava.s'ing.pla*.'indo's.!indo's0oo4Und8eel"#
c[M],"com.sun.%ava.s'ing.pla*.moti*.?oti*0oo4Und8eel"#
;anel p,ne' ;anel()#
*.add(p)#
*or(int i,B#iLa.lengt#i11)
{
bQiQ,ne' Cec4bo((aQiQ,g,*alse)#
p.add(bQiQ)#
bQiQ.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
*or(int %,B#%La.lengt#%11)
{
i*(e.getSource(),,b[%])
{
try
{
b-?anager.set0oo4Und8eel(c[%])#
$
catc(E(ception
e(ception)
{
System.out.println("0a8 not *ound")#
$
S'ingbtilities.updateComponent>reeb-(*)#
$
$
$
$)#
$
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 2L - C9!" 6Q dgn+ 2l !o "pn+ *"E (=
C+ch u< coi nP nh> / u a''}in @/"gin, tGc / >a c+i ki/e .Zar chGa c/a11 m,nh c!n #o th>
m(c Z'[u.n.mZre/ibext rji cG th7 i6" ch8nh c/a11Name cho @hw hH@
C+ch S< gi-i ndn ki/e .Zar ra # tfng th)ng nP #o gPi Z'[u.n.mZre/ibrt.Zar
V& '(< bn OMN >Hc gPi x@/oo[an'kee/.Zar # chd@ nP theo c+ch u
Bn hy mW ki/e rea'me ca gPi ny ra # t,m th5y c/a11Name ca nP /
Kcom.1tekan[ra"1e.x@/oo[an'kee/.Xs;oo[n'ee/K th, >a th\m nP #o
: ;a cP b-n 4"y6n AW Fy /5y #& '( / //oy}cP c- mE
b* 1e '(ng ;a cP b-n 4"y6n bn 1etsro@erty cho nP, #& '( / 'wng //oy;a Ac/a11Name
/ Kcom.incor1.@/ak.a//oy.//oy;oo[n'ee/KE
import %ava(.s'ing.&#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
com.incors.pla*.alloy.Ulloy0oo4Und8eel.set;roperty("alloy.licenseCode","v
ce%Xtecnologiescu'b%^(ceHpc4d")#
*inal 28rame * , ne' 28rame("?y *")#
*inal String[]
a,{"?etal","!indo's","?oti*","P;","Ulloy"$#
*inal Cec4bo([] b,ne' Cec4bo([a.lengt]#
*inal String[] c,ne' String[a.lengt]#
Cec4bo(Kroup g,ne' Cec4bo(Kroup()#
c[B],"%ava(.s'ing.pla*.metal.?etal0oo4Und8eel"#
c[=],"com.sun.%ava.s'ing.pla*.'indo's.!indo's0oo4Und8eel"#
c[M],"com.sun.%ava.s'ing.pla*.moti*.?oti*0oo4Und8eel"#
c[O],"com.ste*an4rause.(ploo4and*eel.P;0oo4Und8eel"#
c[C],"com.incors.pla*.alloy.Ulloy0oo4Und8eel"#
;anel p,ne' ;anel()#
*.add(p)#
*or(int i,B#iLa.lengt#i11)
{
bQiQ,ne' Cec4bo((aQiQ,g,*alse)#
p.add(bQiQ)#
bQiQ.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
*or(int %,B#%La.lengt#%11)
{
i*(e.getSource(),,b[%])
{
try
{
b-?anager.set0oo4Und8eel(c[%])#
$
catc(E(ception
e(ception)
{
System.out.println("0a8 not *ound")#
$
S'ingbtilities.updateComponent>reeb-(*)#
$
$
$
$)#
$
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 21 - JC"e!?8oS
: JChec[Box t>?ng tl Chec[box
import %ava(.s'ing.&#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
28rame *rame , ne' 28rame("?y *rame")#
2Cec4bo( cec4bo(,ne' 2Cec4bo(("Wocuments",*alse)#
cec4bo(.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
System.out.println("Canged")#
$
$)#
*rame.add(cec4bo()#
*rame.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*rame.set@isible(true)#
$
$
Bi 22 - JYdioB#**on ' B#**onGro#&
: Ja'ioB"tton # B"tton^ro"@ t>?ng tl Chec[box # Chec[box^ro"@
import %ava(.s'ing.&#
import %ava.a't.&#
import %ava.a't.event.&#
class Core
{
public static void main(String args[])
{
com.incors.pla*.alloy.Ulloy0oo4Und8eel.set;roperty("alloy.licenseCode","v
ce%Xtecnologiescu'b%^(ceHpc4d")#
*inal 28rame * , ne' 28rame("?y *")#
*inal String[]
a,{"?etal","!indo's","?oti*","P;","Ulloy"$#
*inal 2+adio)utton[] b,ne' 2+adio)utton[a.lengt]#
*inal String[] c,ne' String[a.lengt]#
c[B],"%ava(.s'ing.pla*.metal.?etal0oo4Und8eel"#
c[=],"com.sun.%ava.s'ing.pla*.'indo's.!indo's0oo4Und8eel"#
c[M],"com.sun.%ava.s'ing.pla*.moti*.?oti*0oo4Und8eel"#
c[O],"com.ste*an4rause.(ploo4and*eel.P;0oo4Und8eel"#
c[C],"com.incors.pla*.alloy.Ulloy0oo4Und8eel"#
)uttonKroup g,ne' )uttonKroup()#
2;anel p,ne' 2;anel()#
*.add(p)#
*or(int i,B#iLa.lengt#i11)
{
bQiQ,ne' 2+adio)utton(aQiQ)#
g.add(bQiQ)#
p.add(bQiQ)#
bQiQ.add-tem0istener(ne' -tem0istener()
{
public void itemStateCanged(-temEvent e)
{
*or(int %,B#%La.lengt#%11)
{
i*(e.getSource(),,b[%])
{
try
{
b-?anager.set0oo4Und8eel(c[%])#
$
catc(E(ception
e(ception)
{
System.out.println("0a8 not *ound")#
$
S'ingbtilities.updateComponent>reeb-(*)#
$
$
$
$)#
$
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 2( - JCo:8oBoS ' J2i6*
: JComboBox t>?ng tl nh> Choice
import %ava(.s'ing.&#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
String[] label,{"US?","C__C11","@)","2ava"$#
2Combo)o( bo(,ne' 2Combo)o((label)#
*.add(bo()#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.setSi^e(=BB,AA)#
*.set@isible(true)#
$
$
: J;i1t t>?ng tl ;i1t nh>ng nP /i [hng tl [do th- >Hc nh> ;i1t, c!n cP 1l hQ trH ca
JBcro//sane
import %ava(.s'ing.&#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
String[] label,{"US?",";ascal","C__C11","@)","2ava"$#
20ist l,ne' 20ist(label)#
Scroll;ane s,ne' Scroll;ane()#
s.add(l)#
*.add(s)#
*.setSi^e(=BB,=BB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
: C`n /i th, JVen"Bar,JVen",JVen"tem t>?ng tl Ven"Bar,Ven",Ven"tem
Bi 2, - JT88ed5ne
bFy g3i / fi t>Hng @hFn trang. V& '( '>$i Fy minh h3a u trong c+c @h>?ng thGc
a''Iab / JIabbe'sane.a''IabABtring tit/e,Com@onent com@onentE C+c com@onent trong
#& '( 6" / c+c JB"tton
import %ava(.s'ing.&#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
String[] label,{"US?",";ascal","C__C11","@)","2ava"$#
2)utton[] b,ne' 2)utton[label.lengt]#
2>abbed;ane p,ne' 2>abbed;ane()#
*or(int i,B#iLlabel.lengt#i11)
{
bQiQ,ne' 2)utton(labelQiQ)#
p.add>ab(labelQiQ,bQiQ)#
$
*.add(p)#
*.setSi^e(OBB,=BB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Ihng th>0ng th, c+c com@onenet 6" / c+c [h"ng chGa A#& '( nh> Jsane/E chGa nhi6"
fi t>Hng ri\ng biOt
Bi 21 - JToolBr
JIoo/Bar Athanh cng c(E gifng y nh> bn th>0ng th5y trong c+c Gng '(ng Min'o{1. NP
bao gjm nhi6" JB"tton, mQi JB"tton cP m%t con ri\ng. Ir>$c h7t hy ch"gn bo #i h,nh
.gik SxS cho #& '( ny. N7" [hng t,m th5y th, chd@ t9
Z'[u.n.m'emo@/"ginZkcBty/e@a're1o"rce1. Chd@ #o th> m(c chGa m ng"jn
import %ava(.s'ing.&#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
2>ool)ar t,ne' 2>ool)ar()#
String[]
label,{"3e'","Dpen","Save","Cut","Copy",";aste",")old","-talic","bnderlin
e","0e*t","+igt","Center"$#
String[]
*ile,{"ne'.gi*","open.gi*","save.gi*","cut.gi*","copy.gi*","paste.gi*","b
old.gi*","italic.gi*","underline.gi*","le*t.gi*","rigt.gi*","center.gi*"
$#
-mage-con[] icon,ne' -mage-con[label.lengt]#
2)utton[] b,ne' 2)utton[label.lengt]#
*or(int i,B#iLlabel.lengt#i11)
{
iconQiQ,ne' -mage-con(*ileQiQ)#
bQiQ,ne' 2)utton(iconQiQ)#
bQiQ.set>ool>ip>e(t(labelQiQ)#
t.add(bQiQ)#
i*((i,,M)QQ(i,,A)QQ(i,,d)) t.addSeparator()#
$
*.add(t)#
*.setSi^e(HBB,GB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
Bi 2T - JT8le
: JIab/e hi*n tho ' /iO" cP 1zn
import %ava(.s'ing.&#
import %ava.a't.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
String[][] dat,{{"=","2Creator","Pino(",")eginer"$,
{"M","%K+US;","Uuburn","?edium"$,
{"O","3et)eans","Sun
?icrosystems","E(pert"$,
{"C","Kel","KE(perts",")eginer"$,
{"A","Eclipse","Eclipse","E(pert"$,
{"H","2)uilder",")orland","E(pert"$$#
String[] column3ame,{"-W","3ame","Company","+an4"$#
2>able t,ne' 2>able(dat,column3ame)#
2Scroll;ane s,ne' 2Scroll;ane(t)#
*.add(s)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.setSi^e(CBB,=BB)#
*.set@isible(true)#
$
$
: Ihao t+c trlc ti7@ ' /iO" trong t9ng ca b-ng
Irong #& '( '>$i ch=ng ta 12 thay qi ' /iO" ca c%t Kan[K bRng m%t JComboBox, 1e
'(ng c/a11 Iab/eCo/"mn
import %ava(.s'ing.&#
import %ava.a't.&#
import %ava(.s'ing.table.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
String[][] dat,{{"=","2Creator","Pino(",")eginer"$,
{"M","%K+US;","Uuburn","?edium"$,
{"O","3et)eans","Sun
?icrosystems","E(pert"$,
{"C","Kel","KE(perts",")eginer"$,
{"A","Eclipse","Eclipse","E(pert"$,
{"H","2)uilder",")orland","E(pert"$$#
String[] column3ame,{"-W","3ame","Company","+an4"$#
2>able t,ne' 2>able(dat,column3ame)#
2Scroll;ane s,ne' 2Scroll;ane(t)#
*.add(s)#
2Combo)o( c,ne' 2Combo)o((ne' String[]
{"0o'","Hig","E(tremely"$)#
>ableColumn ran4Column,t.getColumn("+an4")#
ran4Column.setCellEditor(ne' We*aultCellEditor(c))#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.setSi^e(CBB,=BB)#
*.set@isible(true)#
$
$
Bi 2F - J4&*ion5ne !D 8in
bFy cP th* nPi / cng c( ia/og mnh nh5t
Ir>$c ti\n hy xem 4"a #& '( 1a"
import %ava(.s'ing.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
2Dption;ane.so'?essageWialog(*,"Hien ti cau tong
bao","Hien ti tieu de",2Dption;ane.E++D+X?ESSUKE)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
JO@tionsane bao gjm c+c thnh @h!n ch&nh 1a" Fy< Iit/e, con, Ve11age, n@"tVa/"e #
O@tionB"tton1. ihng c!n bao gjm t5t c-
: ihWi to ca JO@tionsane
JO@tionsaneAObZect me11age, int me11ageIy@e, int o@tionIy@e, con icon, ObZectCD
o@tion1E
Bn cP th* th&\" b5t cG thnh @h!n no th]m ch& cP th* thi7" h7t
ObZect me11age< cF" thng b+o hi*n tho tr\n JO@tion@ane
int me11ageIy@e< bao gjm EOVEBB^E, NOVIONVEBB^E,
MNN^VEBB^E, EBIONVEBB^E, # s;NVEBB^E
int o@tionIy@e< bao gjm E;IOsION, EBNOOsION,
EBNOCNCE;OsION, OiCNCE;OsION
con icon< h,nh icon ca JO@tionsane
V& '(<
import %ava(.s'ing.&#
class Core
{
public static void main(String args[])
{
28rame * , ne' 28rame("?y *rame")#
*.add(ne' 2Dption;ane("Hien ti cau tong bao",
2Dption;ane.YbES>-D3X?ESSUKE, 2Dption;ane..ESX3DXCU3CE0XD;>-D3))#
*.setSi^e(MAB,=AB)#
*.setWe*aultCloseDperation(28rame.EP->XD3XC0DSE)#
*.set@isible(true)#
$
$
: C+c @h>?ng thGc Ahay 1e '(ng h?nE
#oi' 1ho{Ve11ageia/ogACom@onent @arentCom@onent, ObZect me11age, Btring tit/e, int
me11ageIy@eE
Btring 1ho{n@"tia/ogACom@onent @arentCom@onent, ObZect me11age, Btring tit/e, int
me11ageIy@eE
int 1ho{Conkirmia/ogACom@onent @arentCom@onent, ObZect me11age, Btring tit/e, int
o@tionIy@e, int me11ageIy@eE e1 tr- #6 m # No tr- #6 u

You might also like