Unidad 3 Interfaz de Escritorio SWING

Embed Size (px)

Citation preview

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    1/87

    U IIII E

    SWING

    1

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    2/87

    INDICE

    •   I

    •  S ?

    •  3.1.B S

    •  C •  M

    •   3.2.C

    •   E

    •  3.3.A D

    2

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    3/87

    I•   L

    (GUI) J 1.0

    GUI

    . E . E

    , AWT J 1.0

    GUI

    . A, :

    GUI

    .

    Ejemplo utilizando

    componentes AWT

    3

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    4/87

    I. (C.)•   A, AWT J 1.0

    . E ? E AWT

    ,

    .

    •   L  

    AWT J 1.1

    ,

    B,

      .

    4

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    5/87

    I. (C.)

    •   2  AWT J

    1.0 , J

    F C (JFC), GUI

    . S JB ,

    ( )

    GUI

    .

    5

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    6/87

    E

    S

    6

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    7/87

    I. (C.)

    •   U (GUI, ) . L

    GUI.

    •   L GUI

    GUI. U GUI .

    7

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    8/87

    ?

    •   L  

      .

    •   A

    .

    •   L

    J; ,

    B JB.

    8

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    9/87

    ?

    •   S AWT

    , JC, .

    •   H S AWT, S

    .

    9

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    10/87

    ?

    •   L .

    .

    •   S   AWT M,SP

    C P AWT S,

    S.

    10

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    11/87

    3.1 B S

    Q ?

    •   C C, , ;

    .

    •   C 3 API: 2D,

    .

    •   S AWT,

    J 1.0 GUI.

    •   L S AWT, ;

    . 11

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    12/87

    Q ?•   : , , ,

    , , , .

    •   C.

    •   B

     

    •   C

    •  

      12

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    13/87

    Q ?•   L AWT C

    C.

    •   L C

    C

    ,

    C C.

    13

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    14/87

    Q ?

    E :

    D :

    Q ,

    .

    D () :

    S .

    D : G .A ,

    . E

    .14

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    15/87

    C

    •   :

    (JF), (JA) JD. E .

    •   C : , , .; .

    •   C

    : JP JSP, .

      . 15

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    16/87

    E

    SWING ( ),

    ()

    AWT ( )

    16

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    17/87

    E SWING AWT.

    17

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    18/87

    C

    C

    C

    B

    CB

    CB

    B

    BA

    Componentes ycontenedores más

    usados.

    18

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    19/87

    C H C

    :

    : B : : C

    : C, CB : CB

    19

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    20/87

    C

    H C :

    :

    : A

    :

    Y C : B :

    Z : C20

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    21/87

    C I C:

    • P

    • W

    • D• F

    T

    C.21

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    22/87

    C

    •   H , , W, L

    .•  L :

     – : S

    JL. – B: S

    JB

     – C : S JTF , JTA .

    22

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    23/87

    C  – C : S

    JCB

     – B : S JRB

     – . S

    JCB – B : S

    JSB

     – C : S JOP

    23

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    24/87

    C •   P GUI,

    , .

    •   T C

    .

    •   C C

    . U

    .

    24

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    25/87

    C

    A :

    •   ( , ); //

    •    B( C );

    •    ( F );

    •    ( V );

    25

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    26/87

    R•   U

    ( ).

    •  L   JC.

      H   JL:•    ()

    C ; .

    •    (S ) //

    C .

    26

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    27/87

    R

    M:

    •   S ()D .

    •    ( S )F .

     –  N: P  ().

    27

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    28/87

    B

    •   U

    .

    •  T : B , .

    •   U

    .

    28

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    29/87

    B•   L

    B

    •   L

    CB

    •   L

    B

    29

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    30/87

    B

    C JB:

    •    B( ) //

    C •    B (S ) ;

    C

    •   E .

    •   U GUI , .

    30

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    31/87

    E B

    •   C . E .

    •   L GUI , , .

    •   U   ; , , .

    •   E .

    31

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    32/87

    E B•   L

      .

    •   L E

     ..

    •   L (JL) (JP) NO

    .

    32

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    33/87

    C T•   L

    .

    •  E E. E .

    •   L .

    •   L JC.

    33

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    34/87

    C T•   C:•   ()

    C JTF.

    •   ( )  // C JTF

    .

    •   ( )   //

    C JTF .

    •   (

    ,   // )   //

    C JTF .

    34

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    35/87

    JCB•   G

    (S)

    •   S .

    •   S .

    35

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    36/87

    JCB

    A :

    •   CB( );

    •   CB( );//

    •    ( ); //

    •   O ( );//

    •    ( );// . P 0

       ( ); // •    ( );//

    .

    36

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    37/87

    JCB JRB•   I / 

    /  .

      S .•  A :

    •  CB( );

    •  CB( ); •  CB( , );

    •   ( ); //

    •   ( );

    •   ( );

    37

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    38/87

    JL•   M   ,

    .

    •   P : I

    R S

    R M

    E:

    S = , , ; JL = JL();

    38

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    39/87

    JPF•   O .

    A :

    •   C('')  .

    •   ()  .

    39

    M

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    40/87

    M

    ● L .

    ● E ().

    ● P :

    •   DD (B)

    •   S ()

    •   C ()

    40

    M

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    41/87

    M•   L DD ,

    , A.

    •   L .

    •   L , ( ) .

    •   S B,   .41

    3 2 C C

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    42/87

    3.2 C C

    •   S

    .

     – : .

     – : .

     – : ,

    , ,

    JF.42

    C C

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    43/87

    C C

    A :

       ( LM );•    ( C );

    •   ( C , O );

    43

    JFrame  JDialog

    C C

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    44/87

    •   C :

    E

    .

    C C

    44

    •   C :E

    .

    C C

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    45/87

    DS F, , F, .

    ● P :

    N : N F.

    M: I .

    ● U :  (M)

    C C

    45

    M

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    46/87

    M •

      E J ()

    .

    M •   C

    . E .

    •   E 3 :

    46

    O E S L

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    47/87

    O E, S L•   E ()

    , ,

    , .

    •   E : , , , .

    •   E

    ( ).•   A ,

    ( )

    .

    •   E ( )

    .47

    G AE

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    48/87

    G AE

    48

    G E AE

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    49/87

    G E AE•

      A , , ,

    A

    L ( AL ).

    •   C (

    ),

    E (AE )

    (P(E))

    E .

    •   E (), ,

    ,

    .   49

    E, ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    50/87

    , ,

    50

    E, ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    51/87

    51

    , ,

    E, ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    52/87

    52

    E, ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    53/87

    53

    , ,

    J E J

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    54/87

    J E J

    54

     java.lang

     java.util

     java.awt

     java.awt.event

    O L

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    55/87

    O L•

     U     .

    •   L : –  AL

     –  AL

     – 

     KL –  CL

     –  ML

     –  MML

     –  CL

     –  TL

    55

    E D E

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    56/87

    E D E•   S P :

    C   JP  A

     (A )

      S , .

    •   P

    :

    .() ;

    56

    E D E

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    57/87

      E:U 1 = U();

    JB 1 = JB(OK);

    1.AL(1);

    •   L B1.AL(1);

    1

    1.

    •   C  

    . A, OK, A 1.  A  .

    57

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    58/87

    I, A

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    59/87

    I, A

    •   P ,

    J

    A (A), A.

    •   L A

    .

    •   A,

    L A

    .59

    I, A

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    60/87

    60

    I, A

    I, A

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    61/87

    61

    I, A

    E G

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    62/87

    62

    •   U , .

    •   E

    .

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    63/87

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    64/87

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    65/87

    V()

    //

    S.(0);

    (S )

    AS P =

    AS(A S);

    P.();

    //

    65

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    66/87

    •   E J, IDE

    .

    •   E IDE

    , .

    •   S N.

    66

    •   C , F JF

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    67/87

    , F JF

    , A

    67

    •   E ,

    A:

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    68/87

    , . A:

    Area de

    trabajo

    Paleta

    Propiedades

    68

    •   E ,

    , . A:

    •   A   ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    69/87

    ,

    ; .

    •   A ,

      .

    69

    •   C , N

    L

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    70/87

    L .•   N ,

    .

    70

    •   C ,

    L

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    71/87

    .

    71

    •   N

    ,

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    72/87

    ,

    TB.

    72

    •   E C() N

    , IDE

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    73/87

    V.•   L

     BA  .

    •   E JF

    . E

    V,

    .

    73

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    74/87

    •   C:

    •   E 5 L:

     –  

     –  

     –  B

     –  B –  C

    •   P L,

    : –   (LM );

     –  N:

    74

    T (L)

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    75/87

    75

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    76/87

    B

    •   C ,

    . E .

    •   V :

    BL.NORTH ()

    BL.SOUTH ()BL.EAST()

    BL.WEST ()

    BL.CENTER (

    .

    76

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    77/87

    •   C

    , . L .

    •   C.

      ( , )

    C GL .

      ( , , , )

    C GL .

    77

    C

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    78/87

    N /*

    * AS.

    ** */

    ;

    AS ..JF

    /** C AS */

    AS()

    C();

    78

    /** T

    * .

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    79/87

    * WARNING: D NOT .* T

    * F E.

    */

    //

    C() 

    DCO(..WC.EXITONCLOSE);WL( ...WA()

    C(...WE )

    WC();

    );

    79

     ..GL =

     ..GL(CP());

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    80/87

    CP().L();

    .HG(

    .PG(..GL.A.LEADING).

    G(0, 400, S.MAXVALUE));

    .VG(

    .PG(..GL.A.LEADING).G(0, 300, S.MAXVALUE)

    );

    ();

    80

    //

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    81/87

     C(...WE )

    // TODO: A :V();

    ()

    S.(0);

    81

    /**

    * @

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    82/87

    */

    ( )  ..EQ.L( R()

    () AS().V();

    );

    // D // F

      82

    E

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    83/87

    JPM// Demonstrating JPopupMenus

    import java.awt.*;import java.awt.event.*;

    import javax.swing.*;

     public class PopupTest extends JFrame { private JRadioButtonMenuItem items[]; private final Color colorValues[] =

    { Color.BLUE, Color.YELLOW, Color.RED };

     private JPopupMenu popupMenu;

    // set up GUI public PopupTest(){

    super( "Using JPopupMenus" );

    83

    ItemHandler handler = new ItemHandler();

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    84/87

    String colors[] = { "Blue", "Yellow", "Red" };

    // set up popup menu and its items

    ButtonGroup colorGroup = new ButtonGroup();

     popupMenu = new JPopupMenu();

    items = new JRadioButtonMenuItem[ 3 ];// construct each menu item and add to popup menu;

    // also enable event handling for each menu item 

    for ( int count = 0; count < items.length; count++ )

    {

    items[ count ] = new JRadioButtonMenuItem(colors[ count ] ); popupMenu.add( items[ count ] );colorGroup.add( items[ count ] );items[ count ].addActionListener( handler );

    }

    84

    getContentPane().setBackground( Color.WHITE );

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    85/87

    // declare a MouseListener for the window that

    //displays a JPopupMenu when the popup trigger

    //event occurs

    addMouseListener(new MouseAdapter() { // anonymous inner class

    // handle mouse press event

     public void mousePressed( MouseEvent event )

    {

    checkForTriggerEvent( event );}

    // handle mouse release event

     public void mouseReleased( MouseEvent event )

    {checkForTriggerEvent( event );

    }

    85

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    86/87

     public static void main( String args[] )

    {

  • 8/20/2019 Unidad 3 Interfaz de Escritorio SWING

    87/87

    PopupTest application = new PopupTest();application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );

    }

    // private inner class to handle menu item events

     private class ItemHandler implements ActionListener{

    // process menu item selections public void actionPerformed( ActionEvent event ){

    // determine which menu item was selected for ( int i = 0; i < items.length; i++ )if ( event.getSource() == items[ i ] ) {getContentPane().setBackground( colorValues[ i ]

    );return; } }

    } // end private inner class ItemHandler

    87