JAVA 8 GUI

download JAVA 8 GUI

of 12

Transcript of JAVA 8 GUI

  • 8/9/2019 JAVA 8 GUI

    1/26

    JAVA Software Development

    Paradigm

    Advance OO Programming

    BSCS Semester 6

    MCS 3

    Course Instructor: Ms. Iram

  • 8/9/2019 JAVA 8 GUI

    2/26

    Window Fundamental

    7-2

    Component

    Container 

    WindowPanel

    Frame Applet

  • 8/9/2019 JAVA 8 GUI

    3/26

    •  Abstract Windowin !ool"it #AW!$

    • Swins

    7-3

  • 8/9/2019 JAVA 8 GUI

    4/26

    Swin %s AW!

    •  AW! is &a%a's oriinal set o( classes (or buildin )*Is *ses +eer com+onents o( t,e S ,ea%/wei,t 0ot trul/ +ortable

    • 1ue to S's underl/in dis+la/ manaement s/stem

    • Swin is desined to sol%e AW!'s +roblems  4a%a li,twei,t com+onents

    • 1rawin o( com+onents is done in 4a%a

    5a/s out consistentl/ on all Ss *ses AW! e%ent ,andlin

  • 8/9/2019 JAVA 8 GUI

    5/26

    6-

    Swins

    • 85AF #8luable 5oo" and Feel$.

    • &a%a +ro%ides se%eral 5AFs9 includin: Metal;    +lat(orm inde+endent

    Windows;  

     (or Windows Windows Classic;    li"e Windows 95 

    Moti(;    (or Unix  < Linux 

     tr/

     =

      *IManaer.set5oo"AndFeel#+la(0ame$

     >

     catc, #?@ce+tion e@$ = ... >

  • 8/9/2019 JAVA 8 GUI

    6/26

    6-6

    )*I Com+onents

    • Com+onents are created usin constructors:

    •!o be usable9 a com+onent must be added tot,e a++lication's content +ane; or to anot,er

    com+onent:

      &5abel uest new &5abel #)uest;$

      &8anel score8anel new &8anel#$  score8anel.add #uest$

  • 8/9/2019 JAVA 8 GUI

    7/26

    Im+lementin a Swin )*I

    • Im+ort 4a%[email protected] 4a%a.io.9 4a%a.awt.

    • Ma"e a s+eci(ic class to do )*I (unctions

    • S+eci(/ all t,e )*I (unctions

  • 8/9/2019 JAVA 8 GUI

    8/26

    Im+lementin a Swin )*I

  • 8/9/2019 JAVA 8 GUI

    9/26

    &Frame

    • Frames are t,e basis o( an/ &a%a )*I

    • Frame is t,e actual window t,at encom+asses /our)*I ob4ects a )*I can ,a%e multi+le (rames

    • !,e &; +re(i@ is at t,e beinnin o( an/ Swin

    com+onent's name #to distinuis, t,em (rom AW!com+onents$

    • &Frame is a wra++er around AW!'s Frame

  • 8/9/2019 JAVA 8 GUI

    10/26

    Frame

  • 8/9/2019 JAVA 8 GUI

    11/26

    8anel

  • 8/9/2019 JAVA 8 GUI

    12/26

    &Scroll8ane

  • 8/9/2019 JAVA 8 GUI

    13/266-3

    Swing  com+onents

    • Com+onents discussed: &5abel

    &Button

    &!oleButton &C,ec"Bo@

    &ComboBo@

    &Slider 

    &!e@tField

    &8asswordField

    &!e@tArea

    C,a+ter:  6

  • 8/9/2019 JAVA 8 GUI

    14/26

    Model-Eiew-Controller 

    • 1esin +attern o(ten used in Swin ob4ects

    • Brea"s a )*I ob4ect down into t,ree +arts

    Model; manaes t,e data used b/ t,e ob4ect Eiew; manaes t,e ra+,ical

  • 8/9/2019 JAVA 8 GUI

    15/26

    Model-Eiew-Controller 

    • Swin com+onents t,at use t,e MEC +attern9

    suc, as &5ist and &!able9 enerall/ ,a%e one

    class t,at controls bot, t,e %iew and t,e

    controller and a se+arate class t,at controlst,e model

  • 8/9/2019 JAVA 8 GUI

    16/26

    Model-Eiew-Controller 

    • 8rorammer instantiates a model #e..9 t,e1e(ault!ableModel class$9 t,en loads t,at model wit, t,edata to be dis+la/ed in t,e )*I

    &!able table new &!able#1e(ault!ableModel model$

    • I( t,e +rorammer instantiates t,e )*I ob4ect wit,out amodel9 t,e %iew

  • 8/9/2019 JAVA 8 GUI

    17/26

    5a/out Manaers• ?%er/ +anel ,as a la/out manaer 

    • 5a/out manaers tell &a%a w,ere to +ut com+onents w,en/ou add t,em to a +ane

    • awt

  • 8/9/2019 JAVA 8 GUI

    18/26

    6-

    1e(ault 5a/outs

    • ?ac, com+onent ,as a de(ault la/out

    manaer9 w,ic, remains in e((ect until t,e

    com+onent's set5a/out met,od is called.

    • !,e de(aults are:Content +ane Border5a/out

    &8anel Flow5a/out

    Bo@ Bo@5a/out

  • 8/9/2019 JAVA 8 GUI

    19/26

    6-

    Flow5a/out

      Container c etContent8ane#$

      c.set5a/out#new FlowLayout()$

      c.add #new &Button #Bac" to Start$$

      c.add #new &Button #8re%ious Slide$$

      c.add #new &Button #0e@t Slide$$  c.add #new &Button #5ast Slide$$

      c.add #new &Button #?@it$$

  • 8/9/2019 JAVA 8 GUI

    20/26

    6-2G

    Bo@5a/out

    • In a ,oriHontal bo@9 com+onents are +laced

    ,oriHontall/9 le(t to ri,t.

    • In a %ertical bo@9 com+onents are +laced

    %erticall/9 to+ to bottom.

    oriHontal; or%ertical; ,as

    not,in to do wit,

    t,e s,a+e o( t,e

    bo@ itsel(.

  • 8/9/2019 JAVA 8 GUI

    21/26

    6-2

    Bo@5a/out #cont'd$

    • Bo@5a/out is t,e de(ault la/out (or a Bo@ 

    container.

      Bo@ bo@ Bo!create"ori#ontalBo()

      bo@. add #...$

     

  • 8/9/2019 JAVA 8 GUI

    22/26

    6-22

    Bo@5a/out #cont'd$

      Container c etContent8ane#$

      c.set5a/out#new Flow5a/out#$$

      Bo &o ' Bo!createVerticalBo()

      &o!add #new &Button #0e@t Slide$$

      &o!add #new &Button #8re%ious Slide$$

      &o!add #[email protected] #2G$ $  &o!add #new &Button #?@it$$

      c.add #&o$

     Adds e@tra

    %ertical s+ace

    betweencom+onents

  • 8/9/2019 JAVA 8 GUI

    23/26

    6-23

    )rid5a/out

    • S+lits t,e +anel into a rid wit, i%en

    numbers o( rows and columns.

    • 8laces com+onents into t,e rid cells.

    • Forces t,e siHe o( eac, com+onent to occu+/t,e w,ole cell.

    •  Allows additional s+acin between cells.

  • 8/9/2019 JAVA 8 GUI

    24/26

    6-2J

    )rid5a/out #cont'd$

      Container c etContent8ane#$

      c.set5a/out #new ridLayout(* +* ,%* +% )$

      c.add #new &Button #Bac" to Start$$

      c.add #new &Button #8re%ious Slide$$

      c.add #new &Button #0e@t Slide$$

      c.add #new &Button #5ast Slide$$  c.add #new &Button #?@it$$

    ?@tra s+acebetween t,e

    cells #in +i@els$

  • 8/9/2019 JAVA 8 GUI

    25/26

    6-2

    Border5a/out

    • 1i%ides t,e area into (i%e reions and adds a

    com+onent to t,e s+eci(ied reion.

    • Forces t,e siHe o( eac, com+onent to occu+/t,e w,ole reion.

    0D!

    S*!

    C?0!?D ?AS!W?S!

  • 8/9/2019 JAVA 8 GUI

    26/26

    6 26

    Border5a/out #cont'd$

      Container c etContent8ane#$

      c.set5a/out#new BorderLayout()$