Chap 5

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Chap 5 as PDF for free.

More details

  • Words: 5,340
  • Pages: 50


 '1 01'g D)"'22o'   "78/4'9"+ "%8 :;"1'(<""='1'(C%$"!:(<1(0.'@':($31DE %B0&% H@"DA5DH/1,+WM92 I2 <++1('JJƒ1 !5$.:;"1'(<""='#'&<#/A"D/(EJ& %B&'= ,n9"<-1K. java.awt /LA+'$#'&:(>  Container <##'& %B :;"&H@":(1/+1('JJƒ1/7B"F  <""='1'( .,5@'6&H@":(1/+1('JJƒ1!5$9I2//:.K:(>  LayoutManager  /LA+'$1'(&(2'6 0"M!5$9I2#'&9"<-1K. java.awt  <#9"D/" 2'$C/6+ :;"1'(<""='<-1K. javax.swing<##'&DH'6F %B0%/$MH9"<-1K. 

- 89:9SXPUY9dVXUp`9^^  "78/4' %BWH'"0'"2"1'(-,f"'!:(<1(0 0%B &% H@"DA5DH/1,+WM92 I2<++C2/@'0 bq V'?'/0-A@D/(E &H@"94nH.9I2I35='&,B6|-'9"'?'.'@'.&",+&"3"1'(-,f"'!:(<1(0~YO %B&'0'(*9I26'" G524#'$<-#DJ/(E0!5$.9I2I35='&,6B 5%$@1,"/' A IH"('&'0'(* .%B "='!:(<1(0~YO %B -,f"'+"(++:ZA+D, A1'( \  0'9I2+"(++:ZA+D, A1'(/7B"F %B0&% H@"DA5DH/1,+WM92 I2:;" <++1('JJƒ1G52 I35='&,6B C/6!:(<1(0>'?'.'@' %B9I29"1'(-,f"'!:(<1(0 ~YO ./$M9H "I35C/6 <-1K.  g V  g  5,6<&569"(M: %B tQP RSB6:(1/+52@$<-1K. DH'6F5,6"%8 

    

    





  -! &H@":(1/+ &%B =',nC/6g  x Nd X ^V  wN^:;"<-1K. 9%B I29"1'(-,f"'!:(<1(0~YO C,8"-78"l'"RSB6.942!:(<1(0~YO %B :;"wV %BCS8"/$MH1,+<-#DJ/(E0 >'?'.'@'G521='4"5<-1K. N^ CS8"0'D,86@/(EI,B"<(1  PQm  !5$ 1='4"5G@29"<-1K.java.awt x \  :;"<-1K. 0%B %&@H ":(1/+1('JJƒ1 %B0%3#,1?<#(M:<++ %B5%1@H' &H@":(1/+1('JJƒ1C/6<-1K. N^ RSB6.40'1,+1'(-,f"'!:(<1(0 ~YO %B"='G:9I26'".(A6>'?'.'@'G521='4"5<-1K.\ CS8"9".'@'@/(EI,B" !5$1='4"59"<-1K.I7B/ javax.swing!5$ @,B G:!:(<1(0 %B9I2 I35='&,6B 9"<-1K. \  . ='6'"I2'1@H'!:(<1(0 ~YO 9%B I2<-1K. N^ '- x NXXd :;"I35='&,B6 %B0%#'&9"1'(-,f"'!:(<1(0 %B0%/A"-3D4(7//' E-3D 9"#,1?-A)? /' A IH" X  V ` X    <#  V b V  x   V   :;"I35='&,B6C/6 !"!#$% %BIH@$9"1'(<#1:#%B$"C2/0M# (4@H'6!:(<1(0 %B-,f"'!5$>'?'.'@'1,+!:(<1(0>'?'/7B"F

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



- " '*;qr <-1K. N^ Nd X ^V  w :(1/+52@$#'&DH'6F %B :;":(> &H@":(1/+1('JJƒ1  X X -7B/"='G:9I29"1'(-,f"'!:(<1(0 ~YO <-1K.  N^ .IH@$9"1'(&(2'6!:(<1(0 ~YO :(>  w V  %BCS8"/$MH1,+ <-#DJ/(E0 %B9I26'" >'?'.'@'G521='4"5<-1K. N^ CS8"G@2D,86
  -!$#'&<#/A"D/(EJ&DH'6F9"<-1K.N^



- #"#2D" '*bsa #'&<#/A"D/(EJ&DH'6F &%B =',n9"<-1K.N^0%5,6"%8 x

Component

 :;"#'& %B :;"   X C/6#'&:(> &H@":(1/+ 1('JJƒ1 31#'&9"<-1K.N^

x

Container:;"#'&

x

LayoutManager

9%B I29"1'(9&H&H@":(1/+1('JJƒ1 :;"/A"D/(EJ& 9%B I29"1'(.,5D='<4"H6<#C"'5C/6

&H@":(1/+1('JJƒ1

    

    





x

Graphics  :;"#'&<++ abstract

B9% I29"1'(@'5(M:1('JJƒ1 /' AIH" @'5&2"@'5&%B 4#%$B 04(7/C%$"C2/@'0:;"D2"

x

Color:;"#'&

x

Font:;"#'&

9%B I29"1'(.,51'(&%C/6&H@":(1/+1('JJƒ1 9%B I29"1'(.,51'(J/"DEC/6&H@":(1/+1('JJƒ1

x AWTEvent :;"#'& %B 1%B$@C2/61,+4D31'(E} '61('JJƒ1 1'(C%$"!:(<1(0 ~YO ",8".:;"1'(&(2'6//:.KDH'6F %B :;"//:.KC/6#'& %B :;"&H@":(1/+1('JJƒ1 RSB6#'&4#H'"%8.&7+ /50'.'1#'& %BI7B/ Component 5,6 <&569"(M: %BtQcRSB6#'& %B :;" dXC/6#'&Component.<+H6:;"&/61#30H 7/ PQ #'& %B :;"#'&:(>  Container :;"#'& %B9I29"1'(9&H&H@":(1/+ 1('JJƒ1DH'6F Q #'& %B :;"&H@":(1/+1('JJƒ1/7B"F /' A IH" Button, Choice <# List:;"D2" 

  -!%#'&DH'6F &%B 7+ /50'.'1#'& %BI7B/Component

-" #

Container





//:.KC/6#'& Container  .9I29"1'(9&H//:.KC/6&H@":(1/+1('JJƒ1 4#'$F//:.KG@2-7B/<&56W# !:(<1(0 ~YO .D2/60%1'(&(2'6//:.KC/6#'&:(> 

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 Container

/$H'6"2/$4"S6B //:.KCS8"0'1H/" -7B/9I29"1'(9&H//:.KC/6#'& %B :;" &H@":(1/+1('JJƒ1/7B"F#'&:(> Container %B/$MH9"<-1K.N^0%5,6"%8

x Frame  x Panel x Dialog x Applet !5$.0%#='5,+I,8"C/61'(&7+ /55,6<&569"(M: %B tQc #'&:(>  Container :;"#'& &%B 7+ /50'.'1#'& %BI7B/ Component RSB6.,5:;"&H@":(1/+1('JJƒ1I"A54"SB6 5,6",8"('.S6&'0'(* .%B 9&H//:.K:(>  Container+'6I"A5#69"//:.KC/6#'&:(> ContainerD,@/7B"FG52/' AIH"9&H //:.KC/6#'&Panel#69"//:.KC/6#'&Frame #'& %BI7B/ Container  :;"#'&<++ abstract RSB6('G0H&'0'(* %B.&(2'6 //:.KC/6#'&5,61#H'@G52
%BD2/61'(9&H

x position7/D='<4"H6 D%B 2/61'(@'6&H@":(1/+1('JJƒ1 !5$:1DA#'&:(>  Container .0%1'(.,5@'6&H@":(1/+1('JJƒ1!5$ 1='4"5D='<4"H6<#C"'5D'0(M:<++1'(.,5@'6W,6 %B1='4"5!5$//:.K:(>  LayoutManager!5$/,D!"0,DARSB6.1#H'@*S69"4,@C2/DH/G: 

-" #Frame #'& Frame :;"#'& &%B 7+ /50'.'1#'& I%B 7B/ Window RSB6.,5@H':;"#'& :(>  Container <++4"SB6 !5$//:.KC/6#'& Frame .:(1/+52@$  d ` ŠdX  `X<# d 5,6<&569"(M: %B tQu!:(<1(0~YO &='4(,+!:(<1(0

    

    





.'@':($31DE.(AB0D2"52@$1'(&(2'6//:.KC/6#'& Frame /$H'6"2/$4"SB6//:.K RSB6 #'&Frame.0%(M:<++C/6X X  %B&=',n5,6"%8 x public Frame() x public Frame(String title)

!5$ %B title7/C2/@'0 D%B /2 61'(.<&56D(6d C/6Frame 



  -!,(M:<++C/6Frame   !5$ @,B G:#'&Frame.0%C"'5(AB0D2":;"m`m5,6",8".S6.=':;".D2/61='4"5 C"'5C/6//:.KC/6Frame!5$9I20L/5setSize()"/1.'1"%8#'&Frame. *M11='4"5942G0H&'0'(*0/64K"G529"D/"(AB0D2" 5,6",8".S6D2/60%1'((%$19I20L/5 show() 4(7/setVisible(true)-7B/1='4"5942//:.KC/6#'&Frame&'0'(*0/64K"G52  //:.KC/6#'& Frame  &'0'(* .%B :(,+C"'5G52!5$1'(#'10'&E:(,+C"'5 C/6J(0RSB6#'&Frame.0%0L/5 %B1%B$@C2/61,+1'(:(,+C"'5C/6J(05,6"%8 x boolean isResizable() :;"0L/5-7B/D(@.&/+@H'//:.KC/6#'& 4(7/G0H

Frame

"%8&'0'(*:(,+C"'5G52

x void setResizable(boolean canResize) :;"0L/5-7B/1='4"5942//:.KC/6#'&Frame"%8&'0'(*:(,+C"'5G524(7/G0H !:(<1(0 %B tQP <&56D,@/$H'61'(&(2'6//:.KC/6#'& Frame %BI7B/ fr <# 1='4"5942 fr 0%C"'5(AB0D2":;" mmbPtm -A1R# !5$1='4"5G@29"='&,B6

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 fr.setSize(200,150); &H@"='&,B6  fr.show(); :;"='&,B6-7B/

%B. ='942&'0'(*

0/64K"//:.KfrG52!:(<1(0"%8.942W##,-LE5,6<&569"(M: %BtQt ("'  -! #'&Frame        

import java.awt.*; public class FrameSample { private Frame fr; public void init() { fr = new Frame("Frame Sample"); fr.setSize(200,150); fr.show(); } public static void main(String args[]) {  FrameSample obj = new FrameSample();  obj.init(); }  } 







   -!-W##,-LE G%B 52.'11'((,"!:(<1(0 %BtQP 

-" #Panel #'& Panel .:;"#'&:(>  Container IH"5%$@1,+#'& Frame
    

    





#'& Panel.0% dX %BI7B/ Applet -7B/9I29"1'(C%$"!:(<1(0.'@'  Container /%1I,8"4"SB6 ,86"%8('&'0'(* .%B 1='4"5942 //:.KC/6#'& Panel
-"" #Dialog #'& Dialog:;"#'& &%B +7 /50'.'1#'& Window-7B/9I2:;"/A"-3D<# /' E-3D1,+WM92 I2  #'& Dialog . ='6'"/$M>H '$9D2//:.KC/6#'& Frame ,86"%81'( &(2'6//:.KC/6#'& Dialog .D2/6(+3//:.KC/6#'& Frame %BMH1,"RSB6(%$1@H' J(0<0H   //:.KC/6#'& Dialog/'.0%!4051'( ='6'"<++;=J,3RSB6 WM29I2D2/6:ƒ5//:.KC/6#'&Dialog1H/".S6.1#,+0' '= 6'"9"J(0<0H %BMH1,"G52 #'&Dialog0%(M:<++C/65=7K10251=0 %B&=',n5,6"%8 x x x x

public Dialog(Frame parent) public Dialog(Frame parent,String title) public Dialog(Frame parent, boolean isModal) public Dialog(Frame parent, String title, boolean isModal)

!5$ %B

 

x

parent7///:.KC/6#'&Frame

x

title7/C2/@'0

x

isModal

%B:;"J(0<0H

%BD2/61'(.<&56D(6d C/6Dialog

7/C2/0M#I"A5 boolean -7B/(+3@H'//:.KC/6 Dialog 0% !405:;"V4(7/G0H

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 "/1.'1"%8  NOG521='4"59420%#'& %B&7+ /50'.'1#'& Dialog/7B"F/%1 /' AIH"#'&FileDialogRSB6.9I29"1'((+3I7B/GJ#E %BD2/61'(9I26'"9"!:(<1(0 

-& '0 g1 ''22o' !:(<1(0 ~YO C/6>'?'.'@'..,5@'6&H@":(1/+1('JJƒ1DH'6F#69" //:.KC/6#'&:(>  Container!5$/,D!"0,DA ,86"%8.1='4"5C"'5<#D='<4"H6C/6 LayoutManager RSB6 &H@":(1/+1('JJƒ1G52!5$9I2//:.KC/6#'&:(>  LayoutManager :;"/A"D/(EJ& 9%B I,9"1'(1='4"5@AL%1'(.,5@'6W,6&H@":(1/+ 1('JJƒ1 >'?'.'@'G521='4"59420%#'& %B implements /A"D/(EJ& I%B 7B/ LayoutManager-7B/9I2:;"D,@.,5@'6W,6C/6&H@":(1/+1('JJƒ1 ,86405C/6#'&7/ PQ BorderLayout Q FlowLayout cQ GridLayout uQ CardLayout tQ GridBagLayout 1'(1='4"5@AL%1'(@'6W,6C/6//:.KC/6#'&:(>  Container . ='G52!5$ 1'(&(2'6//:.K:(>  LayoutManager C/6#'&95#'&4"SB69"42'#'&C2'6D2" .'1",8"('&'0'(* .%B 1='4"51'(@'6W,6!5$1'((%$19I20L/5 setLayout() C/6#'& :(>  Container!5$&H6WH'"   %B:;"//:.K:(>  LayoutManager %B &(2'6CS8"0'D,@/$H'6IH"='&,B6   Frame fr = new Frame(“Demo”); FlowLayout fl = new FlowLayout(); fr.setLayout(fl);

:;"1'(1='4"5942//:.KC/6#'& Frame %BI7B/ fr RSB60%@LA %1'(.,5@'6W,69" (M:<++C/6FlowLayout "7B/6.'1='&,B69"D,@/$H'6C2'6D2".G0H0%1'("='//:.K fl  RSB6:;"//:.KC/6 #'& FlowLayout G:/2'6/A69"='&,B6/7B"F 5,6",8"('.S6&'0'(* %B.C%$"='&,B69"1'(&(2'6 //:.K<#='&,B61='4"5(M:<++1'(@'6W,6>'$9"='&,B65%$@1,"G525,6"%8 fr.setLayout(new FlowLayout());   !5$ @,B G:#'&:(>  Container
    





x #'&Window,

Frame

<# Dialog.1='4"5942:;"BorderLayout

x #'&Panel<#Applet.1='4"5942:;"FlowLayout

-&

BorderLayout BorderLayout

:;"1'(.,5@'6W,6 %B1='4"5942&'0'(*@'6//:.KC/6#'& %B :;"&H@":(1/+1('JJƒ1G52 t //:.KD'0D='<4"H6 A)DH'6FC/6//:.K:(>  Container t D='<4"H67/ A)4"7/ i[hU A)9D2 \[YU  A)D@,"//1}N\ A)D@,"D1 ^}\ <#D(61#'6  }i}h  RSB6//:.K %B:;"&H@":(1/+1('JJƒ1. *M19&H9"D='<4"H6 A)DH'6F!5$.0%1'(1='4"5C"'5942!5$/,D!"0,DA !:(<1(0 %B tQ <&56D,@/$H'6!:(<1(0 ~YO %B:(1/+G:52@$:30™  t :30™  !5$G52 &(2'6//:.KC/6#'& Button CS8"0' t //:.KRSB60%I7B/:;" bn1 ."*S6 bn5 <#0% C2/@'0+":30™ :;"B1."*S6B5D'0#='5,+.'1",8"G529&H//:.KI"A5Button  Container0%1'(.,5@'6W,6<++ BorderLayout ",8" .D2/60%    -7B/(+3D='<4"H6 A) %BD2/61'(@'6//:.K %B :;" &H@":(1/+1('JJƒ1/' AIH"='&,B6    fr.add(bn1,BorberLayout.NORTH); :;"='&,B6 9%B I29"1'(9&H//:.Kbn1#69"//:.Kfr 9"D='<4"H6 A)4"7/ 1(% %B(%$19I20L/5 add() !5$G0H&6H WH'"    -7B/(+3D='<4"H6 )A %B D2/61'(@'6//:.K %B :;"&H@":(1/+1('JJƒ1",8" >'?'.'@'.*7/@H':;"1'(1='4"59429&H &H@":(1/+1('JJƒ1G@2D='<4"H6D(61#'6C/6//:.KC/6#'&:(>  Container /' A IH"='&,6B     fr.add(bn1); .*7/@H':;"='&,B6IH"5%$@1,+='&,B6    fr.add(bn1,BorderLayout.CENTER);

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -!$D,@/$H'61'(9I2D,@.,5@'6W,6<++BorderLayout               

import java.awt.*;

 public class BorderLayoutSample { private Frame fr; private Button bn1, bn2, bn3, bn4, bn5; public void init() { fr = new Frame("Button Sample"); bn1 = new Button("B1"); bn2 = new Button("B2"); bn3 = new Button("B3"); bn4 = new Button("B4"); bn5 = new Button("B5"); fr.add(bn1,BorderLayout.NORTH); fr.add(bn2,BorderLayout.SOUTH);  fr.add(bn3,BorderLayout.EAST); fr.add(bn4,BorderLayout.WEST); fr.add(bn5,BorderLayout.CENTER); fr.setSize(200,150); fr.show(); } public static void main(String args[]) { BorderLayoutSample obj  = new BorderLayoutSample(); obj.init();  }  }  

 

  -!.W##,-LE G%B 52.'11'((,"!:(<1(0 %BtQ

    

    





1'(:(,+C"'5C/6//:.KC/6#'&:(>  Container .0%W# ='942C"'5C/6 //:.KC/6&H@":(1/+1('JJƒ1 :#%B$"<:#6G:D'0C"'5C/6//:.KC/6#'&:(>  Container5,6"%8 x //:.KC/6&H@":(1/+1('JJƒ1 %B/$MHD='<4"H6 A)4"7/ 9D2 <#D(61#'6 . :(,+C"'5D'0C"'5C/6//:.KC/6#'&:(>  ContainerD'0<"@"/" 5,6<&569"(M: %BtQv1 x //:.KC/6&H@":(1/+1('JJƒ1 %B/$MHD='<4"H6 A)D@,"//1 D@,"D1 <# D(61#'6.:(,+C"'5D'0C"'5C/6//:.KC/6#'&:(>  Container D'0<"@D,68 5,6<&569"(M: %BtQvC 





 E'F<"@"/"









EF<"@D,86



  -!3C"'5C/6//:.K %B*1M :(,+ 

-&

FlowLayout FlowLayout

:;"1'(.,5@'6W,6&H@":(1/+1('JJƒ1G@2D='<4"H6+"&35C/6 //:.KC/6#'&:(>  Container !5$.(%$6//:.KC/6#'& %B :;"&H@":(1/+ 1('JJƒ1.'1R2'$G:C@' <#*2'@'01@2'6C/6//:.KC/6#'&:(>  Container 9"
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 B% 4#7/@'69"D='<4"H6*,5G:52'"#H'6 1'(.,5@'6W,6<++ FlowLayout .:(,+C"'5C/6 //:.KC/6#'& %B :;"&H@":(1/+1('JJƒ1DH'6FD'0@'040'&0 ,86"%8CS8"/$MH1,+ C2/1='4"5DH'6F/' A IH" C"'5C/6//:.KC/6#'& Button .0%C"'5D'0C"'5C/6 C2/@'0+":30™ :;"D2" !:(<1(0 %B tQc <&56D,@/$H'6!:(<1(0 ~YO %B&(2'6//:.KC/6#'& Frame CS8"0'<#2@1='4"59420%1'(.,5@'6W,6<++FlowLayout!5$9I2='&,B6 fr.setLayout(new FlowLayout());   !:(<1(0 ~YO "%8.0%//:.KC/6#'& Button /$MH c //:.K !5$1='4"59420% C2/@'0:;" \ d` X <# }b .'1",8"!:(<1(0G529&H//:.KC/6#'& Button
import java.awt.*; public class FlowLayoutSample { private Frame fr; private Button bn1, bn2, bn3; public void init() { fr = new Frame("Button Sample"); fr.setLayout(new FlowLayout()); bn1 = new Button("Submit"); bn2 = new Button("Cancel"); bn3 = new Button("Exit"); fr.add(bn1); fr.add(bn2); fr.add(bn3); fr.setSize(200,150); fr.show(); } public static void main(String args[]) { FlowLayoutSample obj = new FlowLayoutSample(); obj.init(); } }

    

    









E'F





 

EF

  -!4W##,-LE G%B 52.'11'((,"!:(<1(0 %BtQc

-&"

GridLayout GridLayout

:;"1'(.,5@'6W,6 <%B +H6//:.KC/6#'&:(>  Container :;"IH/6$H/$F4#'$IH/6 !5$ Container942:;"IH/6$H/$ 1'(9&H//:.KC/6#'& %B :;"&H@":(1/+1('JJƒ1#69"IH/6$H/$ . ='G52!5$1'( (%$19I20L/5 add() IH"5%$@1,"
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -!,D,@/$H'61'(9I2D,@.,5@'6W,6<++GridLayout  

            

import java.awt.*; public class GridLayoutSample { private Frame fr; private Button bn1, bn2, bn3, bn4, bn5; public void init() { fr = new Frame("Button Sample"); fr.setLayout(new GridLayout(3,2)); bn1 = new Button("B1"); bn2 = new Button("B2"); bn3 = new Button("B3"); bn4 = new Button("B4"); bn5 = new Button("B5"); fr.add(bn1); fr.add(bn2); fr.add(bn3); fr.add(bn4); fr.add(bn5); fr.pack(); fr.setVisible(true); }  public static void main(String args[]) {  GridLayoutSample obj = new GridLayoutSample();  obj.init(); }  }







   -!5W##,-LE G%B 52.'11'((,"!:(<1(0 B% tQu

    

    





-- 1 ''22o'D" '*;qr <-1K.java.awt0%#'& %B :;"&H@":(1/+1('JJƒ1 %B&=',n5,6"%8 x

Button:;"#'&

x

Label:;"#'&

x

TextField

9%B I29"1'(&(2'6//:.K %B :;":30™  9%B I29"1'(&(2'6//:.K 0%B %G@29"1'(<&56C2/@'0

:;"#'& 9%B I29"1'(&(2'6//:.K-7B/942WM29I2:„/"C2/@'0G52

&M6&354"SB6+(( ,5 x

TextArea:;"

%B ='4"2' %B#2'$1,+TextField
x

Checkbox:;"#'&

x

Choice:;"#'&

x

List:;"#'&

%B ='4"2' %B#2'$1,+:30™ !5$9I2&@A REˆ=7€=??‰

%BW9M2 I2&'0'(*#7/1('$1'(.'1 %B1='4"50'942G52

.%B  ='4"2' %B #2'$ Choice
-(2/0F1," x

Scollbar :;"#'&

%B ='4"2' %B:;"<*+@+30-7B/942WM29I2&'0'(*#7B/"G:$,6

D='<4"H6 D%B 2/61'(G52 x

Canvas

:;"#'& %B :;"-78" %B@H'6:#H'-7B/9I29"1'(@'5(M:1('JJƒ1#6G:



-- #Button Button:;"#'&

9%B I29"1'(&(2'6//:.K %B<&56:;":30™ !5$.0%C2/@'0d :('1ˆ/$MH+":30™  WM29I2&'0'(*9I2/3:1(E/A"-3DIH"0'&E4(7/%$+E /(E515#7/1:3™0G52 Button :;"#'& %B&+ 7 /50'.'1#'& Component ('&'0'(* .%B &(2'6//:.KC/6 #'&Button!5$(%$19I2X X C/6#'&Button %B0%(M:<++5,6"%8 x x

public Button() public Button(String label)

!5$ %B  x label7/C2/@'0 .%B :('1Z/$MH+":3™0 

#'&Button$,60%0L/5/7B"F %B&=',n9"1'(.,51'(1,+C2/@'05,6"%8 x

 

public void setLabel(String label)

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 :;"0L/5 9%B I29"1'(1='4"54(7/:#%B$"C2/@'0C/6:30™ x

public String getLabel()

:;"0L/5 9%B I29"1'((%$15MC2/@'0C/6:30™  

-- #Label :;"#'& %B9I2&(2'6//:.K %B :;"&H@":(1/+1('JJƒ1 %B9I29"1'(<&56 C2/@'0$'@4"SB6+(( ,5!5$ %B #'&Label0%X X  %B&=',n5,6"%8 Label

x x

public Label(String text) public Label(String text, int align)

!5$ %B x

text7/C2/@'0

%BD2/61'(<&56

x

align7/1'(1='4"51'(@'6<"@IA5R2'$C@'4(7/D(61#'6C/6C2/@'0



#'&Label0%0L/5 &%B =',n5,6"%8 x public void setText(String text) x public String getText() 0L/5 setText():;"0L/5 %B9I29"1'(1='4"54(7/:#%$B "C2/@'0C/6//:.K I"A5 Label &H@"0L/5 getText():;"0L/5 .%B &H6C2/@'0C/6//:.KI"A5 Label 7"0'

--" #TextField  TextField 7/#'& %B9I29"1'(&(2'6//:.K-7B/942WM29I2:„/"C2/@'04"SB6+(( ,5 !5$ %B#'&TextField0%X X  %B&=',n5,6"%8 x x x x

public TextField() public TextField(int col) public TextField(String text) public TextField(String text, int col)

    

    









!5$ %B x

text7/C2/@'0(AB0D2"

x

col7/.='"@"/#,0"E

%BD2/61'(<&56

%BD2/61'(<&56

#'&TextField0%0L/5 &%B =',n5,6"%8 x x x x

public int getColumns() public String getText() public boolean isEditable() public void select(int selectionStart,    int selectionEnd)

x public void selectAll() x public void setEditable(boolean b) x public void setText(String t) x public void setColumn(int column) 0L/5 setText() 9I29"1'(1='4"54(7/:#%B$"C2/@'0C/6//:.KI"A5 TextFiled 9"1(% %B ('D2/61'(1='4"5942 TextField &'0'(*/H'"C2/@'0G52/$H'6 5%$@ ('&'0'(* ='G52!5$(%$19I20L/5 setEditable(boolean b) !5$1='4"5942   0%H':;"false&H@"0L/5select()9I29"1'(#7/1C2/@'09"TextField !:(<1(0 %B tQt <&56D,@/$H'61'(&(2'6J(0 0%B %//:.KC/6#'& Label <# TextField <&56/$MH !:<1(0"%8.1='4"5942//:.K fr C/6#'& Frame0%1'(.,5@'6 W,6<++FlowLayoutW##,-LEC/6!:(<1(0"%8 :;"5,6<&569"(M: %BtQPm

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -!- D,@/$H'61'(&(2'6Label <# TextField import java.awt.*; public class TextFieldDemo { private Frame fr; private Label l; private TextField tf; public void init() { fr = new Frame("TextField Demo"); l = new Label("Name: "); tf = new TextField("Thanisa", 15); fr.setLayout(new FlowLayout());  fr.add(l);  fr.add(tf); fr.pack(); fr.show(); } public static void main(String args[]) { TextFieldDemo obj = new TextFieldDemo(); obj.init(); } }

  -! 6 W##,-LE %BG52.'11'((,"!:(<1(0 %BtQt 

--& #TextArea :;"#'& %B9I29"1'(&(2'6//:.K &%B '0'(*:„/"<#<12GCC2/@'0G52 TextArea .
%BD2/61'(<&56

x

row<#col7/.='"@"<*@<#/#,0"EC/6TextArea

x

scrollbar:;"1'(1='4"51'(0%X d C/6TextArea

#'&TextArea.0%0L/5 %B&=',n5,6"%8 x x x x x x x x x x 

public int getColumns() public int getRows() public String getSelectedText() public boolean isEditable() public void select(int selectionStart, int  selectionEnd) public void selectAll() public void setEditable(boolean b) public void setText(String t) public void setColumns(int column) public void setRows(int rows)

,86"%80L/5 %B&=',n %B/$MH9"#'& TextArea .#2'$1,+0L/5C/6#'& TextArea
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -!. D,@/$H'61'(&(2'6TextArea import java.awt.*; public class TextAreaDemo { private Frame fr; private TextArea ta; public void init() { fr = new Frame("TextArea Demo"); ta = new TextArea("Text Area",5,10); fr.setLayout(new FlowLayout()); fr.add(ta); fr.setSize(200,150); fr.setVisible(true); } public static void main(String args[]) { TextAreaDemo obj = new TextAreaDemo(); obj.init(); } }





  -! W##,-LE %BG52.'11'((,"!:(<1(0 %BtQ… 

--- #Checkbox  Checkbox :;"#'& 9%B I29"1'(&(2'6//:.K %B ='4"2' %B#2'$:3™0 !5$942WM29I215 IH/6 %B :;"&@A RE-7B/#7/14(7/G0H#7/1('$1'( Checkbox .0%C2/@'0/$MHC2'6F-7B//LA+'$ @'040'$C/6('$1'(Checkbox0%X X  &%B =',n5,6"%8

    

    





x x 

public Checkbox(String label) public Checkbox(String label, boolean state)

!5$ %B x

:;"D,@1='4"5&*'"(A0B D2"C/6 Checkbox 1(% %B X X  G0HG521='4"5&*'"(A0B D2".*7/@H'0%H':;"falseG0H*M1#7/1 state





#'&Checkbox 0%0L/5 %B&'= ,n5,6"%8

x public String getLabel() x public Object[] getSelectedObjects() x public boolean getState() x public void setLabel(String label) x public void setState(boolean state)  !:(<1(0 %B tQv <&56D,@/$H'61'(9I2 Checkbox !5$!:(<1(0.&(2'6J(0 %B0% //:.KI"A5Checkbox-7B/942WM29I2#7/1&'0//:.K5,6<&569"(M: %BtQP ("'  -!3D,@/$H'61'(&(2'6Checkbox  import java.awt.*;  class CheckboxDemo {  public public static void main(String args[]) { Frame fr = new Frame("Checkbox Demo");  Checkbox c1 = new Checkbox("Visual Basic");  Checkbox c2 = new Checkbox("C++",false); Checkbox c3 = new Checkbox("Java",true);  fr.setLayout(new FlowLayout());  fr.add(c1); fr.add(c2);  fr.add(c3); fr.pack();  fr.show();  }  }  

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6







  -! $ W##,-LE %BG52.'11'((,"!:(<1(0 %BtQv  ('&'0'(* %B.&(2'6&@A RED@, #7/1 %B:;"<++hVe !5$9I2Checkbox9" 1(%"%8.1='4"5942//:.K Checkbox 4#'$D,@/$MH9"1#30H 5%$@1," !5$/$M9H "1#30H C/6 //:.KC/6#'& CheckboxGroup RSB6.D2/69I2 X X  DH/G:"%8&(2'6//:.KI"A5 Checkbox

x

public Checkbox(String label,boolean state, CheckboxGroup group)

x

public Checkbox(String label, CheckboxGroup group, boolean state)

#'& CheckboxGroup G0H9IH#'& %B :;"&H@":(1/+1('JJƒ1
    

    





("'  -!4D,@/$H'6C/61'(&(2'6:,J/=p211=7  import java.awt.*; public class CheckboxGroupDemo { public static void main(String args[]) { Frame fr = new Frame("CheckboxGroup Demo"); CheckboxGroup cg = new CheckboxGroup(); Checkbox c1 = new Checkbox("One", true, cg); Checkbox c2 = new Checkbox("Two", false, cg); Checkbox c3 = new Checkbox("Three", cg, true); fr.setLayout(new GridLayout(3,1)); fr.add(c1); fr.add(c2); fr.add(c3); fr.pack(); fr.show(); } }



  -! % W##,-LE %BG52.'11'((,"!:(<1(0 %BtQz

--4 #Choice  Choice :;"#'& 9%B I29"1'(&(2'6//:.K %B :;"('$1'(942WM29I2&'0'(*#7/1G52 !5$ Choice .<&56('$1'(:('1Z9424K"|-'('$1'( %B#7/1-%$6('$1'(5%$@ :1DA 1H/" %B.0%1'(#7/1('$1'( Choice .<&56('$1'(<(1 %B0%/$MH <#4'10%1'(#A10'&E //:.K Choice .<&56('$1'( ,86405 0%B %/$MH !5$ %B#'& Choice 0% X X  %B &=',n5,6"%8 x

public Choice()

#'&Choice0%0L/5DH'6F %B&=',n5,6"%8 x

 

public void add(String item)

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x x x x x x x

public void addItem(String item) public String getItem(int index) public int getItemCount() public int getSelectedIndex() public String getSelectedItem() public void select(int pos) public void select(String str)



('&'0'(* %B.9&H('$1'(#69"//:.K Choice G52!5$9I20L/5 add(String item) 4(7/ addItem(String item) #'& Choice $,60%0L/5 select(int pos) <# select(String item) -7B/9I29"1'(#7/1942//:.K Choice <&56 ('$1'( %BD='<4"H64(7/C2/@'0 %BD2/61'(942<&56G52 &H@"0L/5 getSelectedIndex() <#getSelectedItem()9I29"1'(<&56D='<4"H64(7/C2/@'0 %B*M1#7/1 !:(<1(0 %B tQs <&56D,@/$H'6J(0 0%B %//:.KI"A5 Choice <&56/$MH ='&,6B  c.addItem() <# c.add() 9I29"1'(9&H('$1'(DH'6F#69"//:.K c &H@"='&,6B  c.select(“Thailand”) :;"1'(1='4"5942//:.K c #7/1<&56('$1'( %BI7B/ Thailand!:(<1(0"%8.942W##,-LE %B:;"&H@"DA5DH/1,+WM29I256, (M:<&569"(M: %BtQPu ("'  -!5 D,@/$H'61'(&(2'6Choice import java.awt.*; public class ChoiceDemo { public static void main(String args[]) { Frame fr = new Frame("Choice Demo"); Choice c = new Choice(); c.addItem("New Zealand"); c.addItem("Thailand"); c.addItem("USA"); c.add("Japan"); c.select("Thailand"); fr.add(c); fr.pack(); fr.show(); } }

    

    





  -! , W##,-LE %BG52.'11'((,"!:(<1(0 %BtQs 

--% #List  List :;"#'& %B9I2&(2'6//:.K %B :;"&H@":(1/+1('JJƒ1-7B/942WM29I2&'0'(* #7/1('$1'(#2'$1,+ Choice
x

row

x

multipleMode

:;"1'(1='4"5942WM29I2&'0'(*#7/1('$1'(4#'$('$1'(

-(2/01,"G524(7/G0H 



&List 0%0L/5 %B&=',n5,6"%8

x public void add(String item) x public void add(String item, int index) #'& List .0%0L/5 add() -7B/9I29"1'(9&H('$1'( D%B 2/61'(942#7/1#69" //:.KC/6#'&List5,6D,@/$H'6!:(<1(0 %BtQPmRSB6.G52W##,-LE5,6<&56/$M9H "(M: %BtQPt

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -! 6 D,@/$H'61'(&(2'6List import java.awt.*; public class ListDemo { private Frame fr; private List l; public void init() { fr = new Frame("List Demo"); l = new List(3,true); l.add("One"); l.add("Two"); l.add("Three"); fr.add(l); fr.pack(); fr.setVisible(true); } public static void main(String args[]) { ListDemo ld = new ListDemo(); ld.init(); } }





  -! - W##,-LE %BG52.'11'((,"!:(<1(0 %BtQPm

-4 '  !:(<1(0.'@':($31DE 0%B %&@H "DA5DH/1,+WM92 I2:;"<++1('JJƒ1 &'0'(* %B.0%0"M942 WM29I2#7/1('$1'(G52 0"M:;"//:.KC/6#'& %B&7+ /50'.'1#'& MenuComponent !5$0%#='5,+I,8"C/6#'&DH'6F5,6<&569"(M: %BtQP…RSB6#'&DH'6F %B&=',n0%5,6"%8 x

MenuBar  :;"#'&

9%B I29"1'(&(2'6//:.K %B 1K+1#3H0C/6//:.KC/6#'& Menu RSB6.:('1Z:;"<*+0"M!5$//:.KC/6#'&"%. 8 D2/60%//:.KC/6 #'&Frame %BMH1,"

    

    





x

Menu

:;"#'& 9%B I29"1'(&(2'6//:.K %B 1K+1#3H0C/6//:.KC/6#'& MenuItem<#D,@<$1('$1'(  

x

MenuItem:;"#'&

x

CheckboxMenuItem

9%B I29"1'(&('6//:.K %B :;"('$1'(

 :;"#'& %B9I29"1'(&(2'6//:.K %B:;"('$1'(!5$ .0%(7B/640'$*M1 %B.<&56CS"8 07B/('$1'("%8*M1#7/1





  -! . #'&&=',nF &%B 7+ /50'.'1#'&MenuComponent 

-4 'MenuBar  #'& MenuBar :;"#'& &%B 7+ /50'.'1#'& MenuComponent RSB6.:;" <*+0"M %B:('1Z/$M+H " Frame <#0%5=7K10251=0 5,6"%8 x public MenuBar() ('&'0'(* %B.9&H//:.KI"A5 MenuBar #69"//:.K:(>  Container G52!5$9I20L/5setMenuBar()C/6#'&Container !:(<1(0 %B tQPP <&56D,@/$H'61'(&(2'6//:.KC/6#'& MenuBar <#2@9&H //:.K5,61#H'@#69"//:.KC/6#'& Frame !:(<1(0"%8.942W##,-LE5,6<&569"(M: %B tQPv(++:ZA+,DA1'(+'6:(> /'..G0H<&56<*+C/60"M4'1G0H0%('$1'(9"0"M

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -! D,@/$H'61'(&(2'6MenuBar  import java.awt.*;  class MenuBarDemo {  public private Frame fr; private MenuBar mb;  public void init() {  fr = new Frame("MenuBar Demo"); mb = new MenuBar();  fr.setMenuBar(mb);  fr.setSize(200,150); fr.setVisible(true);  }  public static void main(String args[]) MenuBarDemo md = new MenuBarDemo();  md.init();  }  } 

{



   -! 3 W##,-LE G%B 52.'11'((,"!:(<1(0 %BtQPP 



-4 'Menu Menu MenuBar

:;"#'& %B9I29"1'(&(2'6('$1'( %B.<&56/$MCH 2'69"//:.KC/6#'& !5$0%X X  %B&=',n5,6"%8

x public Menu() x public Menu(String label) x public Menu(String label, boolean tearOff)



!5$ %B x

label7/C2/@'0

    

%B:('1Z/$MH9"('$1'(

    





 ('.9I20L/5 add() 9"#'& MenuBar -7B/ %B.9&H//:.KC/6#'& Menu #69" MenuBar 1(% %B//:.KC/6#'& Menu :;"('$1'( %BI7B/ Help ('.9I20L/5 setHelpMenu() -7B/9&H//:.K#69"MenuBar !:(<1(0 %B tQP <&56D,@/$H'61'(&(2'6//:.KC/6#'& Menu -7B/9&H#69" MenuBar !5$0%I7B/('$1'(DH'6F!:(<1(0"%. 8 942W##,-LE5,6<&569"(M: %BtQPz ("'  -! $D,@/$H'61'(&(2'6Menu %B9&H#69"//:.KC/6#'&MenuBar import java.awt.*;



public class MenuDemo { private Frame fr; private MenuBar mb; private Menu m1,m2,m3,m4; public void init() { fr = new Frame("Menu Demo"); mb = new MenuBar(); m1 = new Menu("File"); m2 = new Menu("Edit"); m3 = new Menu("View"); m4 = new Menu("Help"); fr.setMenuBar(mb); mb.add(m1); mb.add(m2); mb.add(m3); mb.setHelpMenu(m4); fr.setSize(200,150); fr.setVisible(true); } public static void main(String args[]) { MenuDemo mm = new MenuDemo(); mm.init(); } }

 

   -! 4 W##,-LE %BG52.'11'((,"!:(<1(0 B% tQP  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



-4" 'MenuItem 7/#'& B9% I29"1'(&(2'6('$1'($H/$ %B/$MH9"//:.KI"A5 #'&MenuItem0%X X  %B&'= ,n5,6"%8 MenuItem

Menu

x public MenuItem() x public MenuItem(String label) x public MenuItem(String label, MenuShortcut s)

('&'0'(* %B.9&H//:.KC/6#'& MenuItem #69"//:.KC/6#'& Menu !5$(%$19I20L/5add() 9"#'&Menu "/1.'1"%8('&'0'(* .%B 1='4"5>6=01521C/6 ('$1'( %B/$M9H "//:.KC/6#'& MenuItem G52!5$1'(&(2'6//:.KC/6#'& MenuShortcut %B0%X X 5,6"%8 x public MenuShortcut(int key)



<#2@&H6//:.K5,61#H'@:;"    C/6 X X  C/6 MenuItem .'1 %B1#H'@0' 6,8 405"%8('&'0'(* %B.&(3:C,8"D/"1'(&(2'60"MG525,6"%8  &(2'6//:.KC/6#'& MenuBar <#2@9&H#69"//:.K:(>  Container  &(2'6//:.KC/6#'& Menu 4"SB6//:.K4(7/0'11@H' <#2@9&H#69"//:.K C/6#'& MenuBar  &(2'6//:.KC/6#'& MenuItem 4"SB6//:.K4(7/0'11@H' <#2@9&H#69" //:.KC/6#'&Menu  !:(<1(0 %BtQPc<&56D,@/$H'61'(&(2'6MenuItem<#Menu#69"MenuBar !5$.0%W##,-LE5,6<&569"(M: %BtQPs

    

    





("'  -! % D,@/$H'61'(&(2'6MenuItem  import java.awt.*;  public class MenuItemDemo { private Frame fr;  private MenuBar mb;  private Menu m1,m2,m3,m4; private MenuItem mi1,mi2,mi3,mi4;  private MenuShortcut ms1; public void init() {  fr = new Frame("MenuItem Demo");  mb = new MenuBar(); m1 = new Menu("File");  m2 = new Menu("Edit"); m3 = new Menu("View");  m4 = new Menu("Help"); fr.setMenuBar(mb);  mb.add(m1);  mb.add(m2); mb.add(m3);  mb.setHelpMenu(m4); char key = 'N';  ms1 = new MenuShortcut(key); mi1 = new MenuItem("New",ms1);  mi2 = new MenuItem("Open"); mi3 = new MenuItem("Save");  mi4 = new MenuItem("Exit");  m1.add(mi1); m1.add(mi2);  m1.addSeparator(); m1.add(mi3); m1.addSeparator();  m1.add(mi4);  fr.setSize(200,200); fr.setVisible(true);  } public static void main(String args[]) {  MenuItemDemo mid= new MenuItemDemo(); mid.init(); } }

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



   -! 5 W##,-LE G%B 52.'11'((,"!:(<1(0 %BtQPc 



-4& # CheckboxMenuItem  CheckboxMenuItem 7/('$1'(0"M 0%B % (7B/640'$(+3@H'('$1'("%8*M1#7/1 #'&CheckboxMenuItem0%X X  %B&=',n5,6"%8 x public CheckboxMenuItem() x public CheckboxMenuItem(String label) x public CheckboxMenuItem(String label, boolean state)



!5$ %B x

label7/C2/@'09"('$1'(0"M

x state7/&*'"9"1'(#7/1!5$ ,B@G:.0%H':;"false  "/1.'1"%8('&'0'(* .%B :#%B$"&*'"C/6//:.KC/6#'& CheckboxMenuItem !5$9I20L/5setState(boolean b)  !:(<1(0 %B tQPu<&56D,@/$H'61'(&(2'6//:.KC/6#'&CheckboxMenuItem !5$.0%W##,-LE5,6<&569"(M: %BtQm          

    





("'  -! ,D,@/$H'61'(&(2'6CheckboxMenuItem import java.awt.*; public class CheckboxMenuDemo { private Frame fr; private MenuBar mb; private Menu m1,m2,m3; private MenuItem mi; private CheckboxMenuItem cbm; public void init() { fr = new Frame("CheckboxMenuItem Demo"); mb = new MenuBar(); m1 = new Menu("File"); m2 = new Menu("Edit"); m3 = new Menu("View"); fr.setMenuBar(mb); mb.add(m1); mb.add(m2); mb.add(m3); mi = new MenuItem("Toolbars"); cbm = new CheckboxMenuItem("Status Bar", true); m3.add(mi); m3.add(cbm); fr.setSize(200,200); fr.setVisible(true); } public static void main(String args[]) { CheckboxMenuDemo obj= new CheckboxMenuDemo(); obj.init(); } }



  -!$6W##,-LE %BG52.'11'((,"!:(<1(0 %BtQPu  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



-4- '  +1+  0"M&'0'(* .%B 0%0"M$H/$G52!5$0"M$H/$.:;"//:.KC/6#'& Menu RSB6 C,8"D/"9"1'(&(2'6J(0 0%B % 0"M$H/$0%56, "%8 PQ &(2'6//:.KC/6#'&MenuBar<#2@9&H#6G:9"//:.KC/6#'&Frame Q &(2'6//:.KC/6#'&Menu<#2@9&H#6G:9"//:.KC/6#'&MenuBar cQ &(2'6//:.KC/6#'& Menu &='4(,+0"M$H/$<#2@9&H#6G:9"//:.KC/6 #'&Menu %B:;"0"M4#,1 uQ &(2'6//:.KC/6#'& MeunItem<#2@9&H#6G:9"//:.KC/6#'& Menu %B:;"0"M$H/$  !:(<1(0 %B tQPt <&56D,@/$H'61'(&(2'6 Frame %B0% 0"M$H/$!5$!:(<1(0"%.8 942 W##,-LE5,6<&569"(M: %BtQP ("'  -! -D,@/$H'61'(&(2'6Frame %B0% 0"M$H/$  import java.awt.*;  class SubMenuDemo {  public private Frame fr; private MenuBar mb;  private Menu m1,m2,m3, ms1;  private MenuItem mi2,mi3,mi4, msi1, msi2;  public void init() { fr = new Frame("SubMenuItem Demo");  mb = new MenuBar();  m1 = new Menu("File"); m2 = new Menu("Edit");  m3 = new Menu("View");  fr.setMenuBar(mb); mb.add(m1);  mb.add(m2); mb.add(m3);  ms1 = new Menu("New");  mi2 = new MenuItem("Open"); mi3 = new MenuItem("Save");  mi4 = new MenuItem("Exit");  m1.add(ms1); m1.add(mi2);  m1.addSeparator(); m1.add(mi3);

    

    





 m1.addSeparator();  m1.add(mi4); msi1 = new MenuItem("Window");  msi2 = new MenuItem("Message"); ms1.add(msi1);  ms1.addSeparator(); ms1.add(msi2);  fr.setSize(200,200); fr.setVisible(true); 

} public static void main(String args[]) {  SubMenuDemo obj= new SubMenuDemo(); obj.init();  } }



 



  -!$ W##,-LE %BG52.'11'((,"!:(<1(0 %BtQPt

-% /@#'@ #Component  &H@":(1/+1('JJƒ1DH'6F.0%3#,1?/7B"/' AIH"(M:<++C/6J/"DE &%C/6-78" 4#,64(7/&%C/6-78"4"2' g   V ('&'0'(* .%B 1='4"53#,1?C/6&H@":(1/+ 1('JJƒ1G52 !5$:1DA&H@":(1/+1('JJƒ1.9I23#,1?<++5%$@1,+//:.K:(>  Container %B+((.3/$MH @2"
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 

0L/5 9%B I29"1'(1='4"53#,1?C/6&H@":(1/+1('JJƒ1 Component!5$0%0L/5 %B&=',n7/

./$M9H "#'&

x setFont(Font f) x setForeground(Color c) x setBackground(Color c) 9I29"1'(1='4"5(M:<++C/6J/"DE &H@"0L/5  0L/5 setFont() setForeground() <# setBackground() 9I29"1'(1='4"5&%-78"4"2'<#-78"4#,6 D'0#='5,+ #'&Font :;"#'& 9%B I29"1'(&(2'6//:.K-7B/1='4"5(M:<++C/6J/"DE!5$0% X X 5,6"%8 x 



public Font(String name, int style, int size)

!5$ %B x

name7/I7B/C/6J/"DE

x

style

 :;"(M:<++C/6J/"DE RSB6#'& Font G521='4"5H'6 %BG@27/ Font.PLAIN, Font.BOLD <#Font.ITALIC 

x size7/C"'5C/6J/"DE D,@/$H'6C/61'(&(2'6//:.KC/6#'&Font 0%5,6"%8 x x

Font fn1 = new Font(“AngsanaUPC”,Font.PLAIN,16); Font fn2 = new Font(“Time Romans”, Font.BOLD +Font.ITALIC,14);

 #'& Color :;"#'& %B9I29"1'(&(2'6//:.K&='4(,+1='4"5(M:<++C/6&% !5$0% X X 5,6"%8 public Color(int r, int g, int b)    !5$ %B 

x r, g, b7/H'@'0C20C/6<&6&%<56C%$@<#"8='6A" D'0#='5,+ #'&Color0%3#,1? %B1'= 4"5&% %B9I2 ,B@G:G@2<#2@4#'$F&%/' A IH"  yellow = new Color(255,255,0); black = new Color(0,0,0);

    

    







!:(<1(0 %B tQP… <&56D,@/$H'61'(1='4"53#,1?C/6//:.KC/6#'& Frame<##'&Button9420%&< % #J/"DEDH'6F!5$.G52W##,-LE5,6<&569"N&)W ("'  -! . D,@/$H'61'(1='4"53#,1? 

import java.awt.*;

 class AttributeDemo { public private Frame fr;  private Button bn1,bn2,bn3; 

}



public void init() {  fr = new Frame("ShowAttribute"); bn1 = new Button("OK");  bn2 = new Button("Cancel"); bn3 = new Button("Help");  fr.setLayout(new FlowLayout()); fr.add(bn1); fr.add(bn2);  fr.add(bn3); fr.setFont(new Font("TimesRoman",Font.BOLD,16));  fr.setForeground(Color.blue); fr.setBackground(Color.green);  bn2.setForeground(Color.red); fr.setSize(200,150);  fr.show(); }  public static void main(String args[]) { AttributeDemo ad = new AttributeDemo();  ad.init(); }







-l Z&)WSEM!'!:(<1(0 %BtQP…

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



-8 ''22o' <-1K. N^ 0%#'& %B :;"&H@":(1/+1('JJƒ1 %BI7B/ Canvas RSB6:;""78/ %B@H'6 :#H' &%B '0'(*9I29"1'(@'5(M:1('JJƒ14(7/C%$"C2/@'095FG52 #'&"%.8 0%0L/5 paint() RSB6.*M1(%$19I26'"07B///:.KC/6#'&:('1Z9424K" 4(7/07B///:.KC/6 #'&0%1'(:(,+:#%B$"C"'54(7/D='<4"H6 RSB6.0%W#942='&,B6DH'6F9"0L/5 %B paint()*M1 (%$19I26'" !5$ ,B@G:='&,B6 %B/$MH9"0L/5 paint() .:;"='&,B6 %B 1%$B @C2/61,+1'(@'5(M: 1('JJƒ1DH'6F!5$0L/5paint()0%(M:<++5,6"%8    public void paint(Graphics g) { [statements] }

!5$ %B  x g7///:.KC/6#'&Graphics %B&'0'(*9I29"1'(@'5(M:1('JJƒ1DH'6F x statements7/='&,B69"1'(@'5(M:1('JJƒ1DH'6F

-8 '+ #  0 '22o' 1'(&(2'6>'-1('JJƒ19">'?'.'@' . ='G52!5$1'(&(2'6#'& %B :;"&H@"1('JJƒ1 RSB6&7+ /50'.'1#'&Canvas<#2@ V0L/5paint()!5$C%$"='&,6B 9"1'(@'5 (M:1('JJƒ1DH'6F9"0L/5 D,@/$H'6IH" !:(<1(0 %B tQPv <&56D,@/$H'6C/6#'& MyCanvasRSB6.#'1&2"D(6.'1-A1,5X VPm`PmG:$,6-A1,5Pmm`Pmm ("'  -! 3#'&MyCanvas     

import java.awt.*; public class MyCanvas extends Canvas { public void paint(Graphics g) { g.drawLine(10,10,100,100); } }

#'& MyCanvas :;"#'& %B:;"&H@":(1/+1('JJƒ1#'&4"SB6 H'",8" 1'(. <&56>'-1('JJƒ1C/6#'&"%.8  ='G52!5$1'(C%$"!:(<1(0 ~YO %B0%1'(&(2'6//:.KC/6 #'& Frame %B:;" Container.'1",8"&(2'6//:.KC/6#'& MyCanvas<#[email protected]&H#6 9"//:.KC/6#'& Frame5,6D,@/$H'6!:(<1(0 %B tQPzRSB6.G52W##,-LE:;"5,6<&569"(M: %BtQc     

    





("'  -! 4D,@/$H'61'(9I2#'&MyCanvas        

import java.awt.*; public class GUIDemo { public static void main(String args[]) { Frame fr = new Frame("Draw line"); MyCanvas mc = new MyCanvas(); fr.add(mc); fr.setSize(150,150); fr.setVisible(true); } }

   -!$% W##,-LE G%B 52.'11'((,"!:(<1(0 B% tQPz

-! '("' sT= MM  !5$ @,B G:!:(<1(0 ~YO .0%1'(@'6W,6&H@":(1/+1('JJƒ1 %BR,+R2/"1@H'1'(9I2 D,@.,5@'6W,6 %B1#H'@0'C2'6D2" (BorderLayout, FlowLayout <#GridLayout @AL%1'( .%B &(2'6!:(<1(0~YO %BR,+R2/"CS8"&'0'(* ='G52!5$1'(&(2'6//:.KC/6#'&C/6 #'&Panel0'IH@$9"1'(.,5W,6  ('&'0'(* %B.9&H//:.KC/6#'& Panel #69" Container D,@/7B" !5$(' &'0'(* .%B &H6&H@":(1/+1('JJƒ1#69" Panel /%1 %4"SB6 ,86"%8 ('&'0'(* .%B 1='4"5942 Panel
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 //:.K p2.0%D,@.,5@'6W,6:;"<++GridLayout!:(<1(0"%8.942W##,-LE5,6<&569"(M: %BtQu ("'  -! 5D,@/$H'61'(&(2'6!:(<1(0~YO %BR,+R2/"  import java.awt.*;   public class StickyPad { private Frame fr;  private Panel p1, p2;  private TextArea ta1, ta2;  private Button bn1, bn2, bn3; public void init() {  fr = new Frame("Sticky Pad");  p1 = new Panel();  p2 = new Panel();  bn1 = new Button("Submit"); bn2 = new Button("Leave");  bn3 = new Button("Return");  ta1 = new TextArea(4,40);  ta2 = new TextArea(4,40); ta1.setBackground(Color.pink);  ta1.setFont(new Font("Dialog",Font.PLAIN,20));  ta2.setBackground(Color.lightGray);  ta2.setFont(new Font("Dialog",Font.PLAIN,20)); p1.setLayout(new GridLayout(2,1));  p1.add(ta1);  p1.add(ta2); p2.setLayout(new FlowLayout());  p2.add(bn1);  p2.add(bn2); p2.add(bn3);  fr.add(p1); fr.add(p2,BorderLayout.SOUTH);  fr.setSize(400,300);  fr.show(); }  public static void main(String args[]) { StickyPad obj = new StickyPad();  obj.init();  } 

}

    

    











  -!$, W##,-LE %BG52.'11'((,"!:(<1(0 %BtQPs

-< " '*ktVU_  >@/7^ :;"<-1K.&='4(,+-,f"'!:(<1(0 ~YO RSB60%&H@":(1/+1('JJƒ1 %B0'1 I"A51@H' 0%B %/$M9H "<-1K. N^ "/1.'1"%8&@H ":(1/+1('JJƒ1C/6<-1K. >@/7^ .0% #,1? %B5%1@H'&H@":(1/+1('JJƒ1C/6<-1K.N^ &H@":(1/+1('JJƒ1C/6<-1K. >@/7^&'0'(*1='4"5(M:<++C/63==w ,7J ?883 %B ='942G52!:(<1(0~YO %B0%(M:<++C/6 1('JJƒ1407/"1,"9" 31<-#DJ/(E0 RSB6.@/7^ /$MH9"<-1K. javax.swing RSB6#'& %B :;"&H@":(1/+ 1('JJƒ1C/6<-1K. >@/7^ 31#'&.&7+ /50'.'1#'& JComponent 5,6<&569" N&)W  !5$#'& JComponent .&7+ /50'.'1#'& Container 9"<-1K. N^/%1DH/4"SB6

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



--#'&DH'6F &%B 7+ /50'.'1#'&JComponent 

 <-1K. >@/7^ .0%#'& %B :;"&H@":(1/+1('JJƒ1 %B&/5#2/61,+#'&9" <-1K.N^!5$#'&4#H'"%.8 0%I7B/CS8"D2"52@$D,@/,1?(‘J’!5$0%#'& &%B =',n5,6"%8 x

JFrame:;"#'&

%B :;"J(09"<-1K.>@/7^

x

JPanel:;"#'&

%B :;"Panel9"<-1K.>@/7^ 

x

JButton:;"#'&

x

JLabel

%B ='4"2' %B:;":30™ 9"<-1K.>@/7^

:;"#'& 9%B I29"1'(&(2'6//:.K %BG@29"1'(<&56C2/@'09"

<-1K.>@/7^ x

JTextField

:;"#'& 9%B I29"1'(:„/"C2/@'04"SB6+(( ,59"<-1K.

>@/7^ x

JTextArea

 :;"#'& %B9I29"1'(:„/"C2/@'04#'$+(( ,59"<-1K.

>@/7^ x

JScrollBar

:;"#'& %B ='4"2' %B:;"<*+@+30-7B/942WM29I2#7B/"G:$,6 D='<4"H6 D%B 2/61'(G529"<-1K.>@/7^

x

JCheckBox:;"#'&

x

JChoice:;"#'&

    

%B ='4"2' %B#2'$:3™09"<-1K.>@/7^

%BW9M2 I2&'0'(*#7/1('$1'(G529"<-1K.>@/7^

    





-< #JFrame <-1K. \  0%#'&:(>  Container %B  ContainerC/6<-1K.N^7/ JFrame, JDialog, JPanel <# JApplet !5$ @,B G:!:(<1(0 ~YO %B:;"!:(<1(0.'@':($31DE.9I2 Container %B:;"//:.K C/6#'&JFrame #'&JFrame .&7+ /50'.'1#'&Frame !5$0%X X  %B&=',n5,6"%8 x public JFrame() x public JFrame(String title)  //:.KC/6#'& Jframe .








  -!$. 'MF&)W(NF['LJframe

  ('G0H&'0'(* %B.9&H&@H ":(1/+1('JJƒ1#69" JFrame G52!5$D(6  Container <++4"SB6 ('&'0'(* . %B (%$1//:.KC/6#'&:(>  Container

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 5,61#H'@0'G52!5$9I20L/5 I%B 7B/ getContentPane() <#&'0'(* %B.9&H&@H ":(1/+ 1('JJƒ1#69"//:.K5,61#H'@G52!5$9I20L/5add() 5,6D,@/$H'6IH" Container content = fr.getContentPane(); content.setLayout(new BorderLayout()); content.add(bn1,BorderLayout.SOUTH);

 !:(<1(0 %B tQm <&56D,@/$H'61'(9I2#'&DH'6F9"<-1K. \  -7B/&(2'6 !:(<1(0idQRSB6942W##,-LE5,6<&569"(M: %BtQv 

("'  -!$6  (FLM idQE([ ML['  "!>@/7^ import java.awt.*; import javax.swing.*; public class StickyPadSwing { private JFrame fr; private JPanel p1, p2; private JTextArea ta1, ta2; private JButton bn1, bn2, bn3; public void init() { fr = new JFrame("Sticky Pad"); p1 = new JPanel(); p2 = new JPanel(); bn1 = new JButton("Submit"); bn2 = new JButton("Leave"); bn3 = new JButton("Return"); ta1 = new JTextArea(4,40); ta2 = new JTextArea(4,40); ta1.setBackground(Color.pink); ta1.setFont(new Font("Dialog",Font.PLAIN,20)); ta2.setBackground(Color.lightGray); ta2.setFont(new Font("Dialog",Font.PLAIN,20)); p1.setLayout(new GridLayout(2,1)); p1.add(ta1); p1.add(ta2); p2.setLayout(new FlowLayout()); p2.add(bn1); p2.add(bn2); p2.add(bn3); Container c = fr.getContentPane(); c.add(p1); c.add(p2,BorderLayout.SOUTH); fr.setSize(400,300); fr.show(); }

    

    





public static void main(String args[]) { StickyPadSwing obj = new StickyPadSwing(); obj.init(); }  

}



 

  -!$3 W##,-LE %BG52.'11'((,"!:(<1(0 %BtQm  "/1.'1"%8('&'0'(* .%B 1='4"5 X  C/6//:.KI"A5 JFrame G52 !5$(%$19I20L/5 setContentPane() !:(<1(0 %B tQP <&56D,@/$H'61'(&(2'6 //:.KI"A5 JPanel CS8"0'<#2@"='&H@":(1/+1('JJƒ19&H#69"//:.K p1 .'1",8" 1='4"5942 p1 :;" X  C/6//:.K fr I"A5 JFrame !5$9I20L/5 setContentPane()

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  -!$ D,@/$H'61'(&(2'6Jframe !5$9I20L/5

setContentPane()

import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { JFrame fr = new JFrame("SwingDemo"); JPanel p1 = new JPanel(); JButton bn1 = new JButton("New"); p1.add(bn1); fr.setContentPane(p1); fr.pack(); fr.show(); } }

-< #JComponent #'& JComponent0%0L/5 %B-AB0#,1?DH'6F9421,+//:.K %B :;"&H@":(1/+ 1('JJƒ1/' AIH" x

setBorder(Border

bd)

:;"0L/5&='4(,+1='4"5C/+9421,+

&H@":(1/+1('JJƒ1 x

:;"0L/5&='4(,+1='4"5C2/@'0 .%B  <&56:;"9421,+&H@":(1/+1('JJƒ1

setToolTipText(Swing text)



-<" 'D) /@#'@01 C  <-1K.\ $,60%0L/5/7B"F %B9I29"1'(1='4"5(M:#,1?E<#3#,1?5H"C/6 //:.K %B :;"&H@":(1/+1('JJƒ1DH'6F-AB0DA0/' A IH" x

void setMnemonic(char c)4(7/

x

void setMnemonic(int i)

:;"0L/59"1'(1='4"5%$E %B :;" X 9421,+//:.KC/6#'&JButton x

void setIcon(Icon c)

    

    





:;"0L/59"1'(9&HG//" X #69"//:.KC/6&H@":(1/+1('JJƒ1DH'6F IH":3™0  "/1.'1"%8<-1K. \  ./"3n'D942W9M2 I2&'0'(*1='4"5 w V  C/6 !:(<1(0 idQ +"<-#DJ/(E0DH'6F/6G52 !5$0%#'& I%B 7B/ LookAndFeel %B9I29"1'( 1='4"5(M:<++DH'6FC/6&H@":(1/+1('JJƒ1IH" J/"DE  C"'5  &%  1'(.,51'(1,+ 4D31'(E}:;"D2"!5$ ,B@G:!:(<1(0idQ %B9I2<-1K.\ .&(2'6//:.KC/6 #'& UIManager CS8"0'D/"(,"!:(<1(0 -7B/D(@.&/+(M:<++ w V  C/6 !:(<1(0idQ<#('&'0'(* %B.1='4"5(M:<++wV940HG52!5$9I20L/5   UIManager.setLookAndFeel(LoodAndFeel l)

/& x #'& %B/$M9H "<-1K. java.awt &'0'(*"='0'9I2&(2'6!:(<1(0idQ <++`==w ,7J g883 D'0<-#DJ/(E0 %B9I26'"G52 !5$0%#'& Component :;" K2B8053,KK C/6 31#'& %B :;"#'&:(> _=71,/780<##'&:(> &H@":(1/+1('JJƒ1 x #'&:(> _=71,/780 %B&=',n7/#'&Frame<#Panel x #'&:(> &H@":(1/+1('JJƒ1 %B&=',n7/Button, Label, TextField, TextArea, Checkbox, Choice <# List 

x (M:<++1'(.,5@'6W,6&H@":(1/+1('JJƒ19"D,@9&H&H@":(1/+1('JJƒ10% ,86405  (M:<++7/ BorderLayoutI FlowLayoutI GridLayoutI CardLayout <#GridBagLayout x 1'(.,5@'6W,6C/6&H@":(1/+1('JJƒ1<++ BorderLayout .:;"1'(@'6D'0 A)DH'6FG52  A)&H@" FlowLayout.@'6G@29"D='<4"H6+"&35!5$(%$6.'1R2'$ G:C@'&='4(,+ GridLayout.@'6(%$6.'1R2'$G:C@'<#+"#6#H'69"IH/6$H/$ %B0%C"'5 H'1,"D'0.='"@"<*@<#/#,0"E G%B 52(+3G@2 x

 

.<&56C2/@'0 RSB6WM92 I2G0H&'0'(*:„/"C2/@'0G52
 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x

Checkbox .:;"IH/6942WM29I2#7/14(7/G0H#7/1!5$&'0'(*#7/1G524#'$IH/6-(2/0

1," RSB6.
CheckboxGroup

%B.&'0'(*#7/1G52-%$6IH/65%$@

.<&56('$1'( %B*1M #7/1-%$6('$1'(5%$@ !5$.<&564#'$('$1'( 07B/WM29I2#A10'&E H'",8" RSB6.
x #'& %B."='0'9I29"1'(<&56<*+0"M<#0"M$H/$7/ MenuBarI Menu <# MenuItem x #'& Font <# Color .*M1"='0'9I29"1(% %BD2/61'((+33#,1? J/"DE <#&%C/6D,@9&H&@H ":(1/+1('JJƒ1<#&H@":(1/+1('JJƒ1 x &(2'6 GGm['! !&USEME(LML&)W Š'LF 'GGm atWLO&E !LCanvasM =-800/J8 ZEpaint() x #'&Graphics! ) ZE[' EN&GGmFn( ZE x #'&9"<-1K. javax.swing .*M1"='0'9I29"1'(&(2'6 idQ #2'$1,+ java.awt
    





                          

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

Related Documents

Chap 5
December 2019 27
Chap 5
November 2019 27
Chap 5
June 2020 15
Chap 5
May 2020 14
Chap-5
November 2019 19
Chap 5
November 2019 20