Compendio Karla

Embed Size (px)

Citation preview

  • 7/24/2019 Compendio Karla

    1/27

    package cronometro;

    import java.awt.BorderLayout;

    import java.awt.Color;

    import java.awt.Font;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JLael;

    import javax.swing.!"#anager;

    pulic class Cronometro extends JFrame implements $unnale% ActionListener

    &

    pulic static int ono' ();

    pulic Cronometro*+

    &

    set,itle*-cronometro-+;

    seti/e*0))% 1))+;

    set2e3aultClose4peration*JFrame.E5",6476CL4E+;

    setLayout*new BorderLayout*++;

    88Eti9ueta donde se colocara el tiempo

    tiempo ( new JLael*-)):)):)))-+;

    tiempo.setFont*new Font*Font.E$"F% Font.B4L2% 0)++;

    tiempo.setori/ontalAlignment*JLael.CE7,E$+;

    tiempo.setForeground*Color.BL!E+;

    tiempo.setBackground*Color.

  • 7/24/2019 Compendio Karla

    2/27

    add*tiempo% BorderLayout.CE7,E$+;

    88Boton iniciar

    JButton tn ( new JButton*-"niciar-+;

    tn.addActionListener*t=is+;

    add*tn% BorderLayout.4!,+;

    88Boton reiniciar inicia nuevamente desde )

    JButton tn>( new JButton*-$einiciar-+;

    tn>.addActionListener*t=is+;

    add*tn>% BorderLayout.EA,+;

    88oton parar

    JButton tnC( new JButton*-top-+;

    tnC.addActionListener*t=is+;

    add*tnC% BorderLayout.

  • 7/24/2019 Compendio Karla

    3/27

    milesimas (;

    88cuando llega a ))) osea segundo aumneta segundo

    88y las milesimas de segundo de nuevo a )

    i3 *milesimas (()))+

    &

    milesimas ( );

    segundos (;

    i3 *segundos (( D)+

    &

    segundos();

    minutos ;

    @

    @

    i3*minutos )+min( -)- minutos;

    else min(minutos.totring*+;

    i3*segundos)+seg(-)- segundos;

    else seg( segundos.totring*+;

    i3*milesimas)+mil(-)- milesimas;

    else mil( milesimas.totring*+;

    tiempo.set,ext*min -:- seg -:- mil+;

    @

    @catc=*Exception e+&@

    tiempo.set,ext*-)):)):)))-+;

    @

    pulic void action>er3ormed*ActionEvent evt+&

    4ject o(evt.getource*+;

    i3* o instanceo3 JButton+

  • 7/24/2019 Compendio Karla

    4/27

    &

    JButton tn ( *JButton+o;

    i3*tn.get,ext*+.e9uals*-"niciar-++&

    i3*ono'(()+&

    ono'(;

    iniciarCronometro*+;

    @

    @

    i3*tn.get,ext*+.e9uals*-$einiciar-++&

    i3 *ono' (( +&

    ono' ( );

    pararCronometro*+;

    @

    @

    i3*tn.get,ext*+.e9uals*-stop-++&

    i3 *ono' (( +&

    detenerConometro*+;

    @

    @

    @

    @

    pulic void iniciarCronometro*+&

    cronometroActivo ( true;

    =ilo ( new ,=read*t=is+;

    =ilo.start*+;

    @

  • 7/24/2019 Compendio Karla

    5/27

    pulic void pararCronometro*+&

    cronometroActivo ( 3alse;

    @

    pulic void detenerConometro*+&

    =ilo.stop*+;

    @

    pulic static void main*tringG args+&

    new Cronometro*+;

    @

    JLael tiempo;

    ,=read =ilo;

    oolean cronometroActivo;

    @

    package layouts;

    import java.awt.BorderLayout;

    import java.awt.Container;

    import javax.swing.JFrame;

    import javax.swing.JLael;

  • 7/24/2019 Compendio Karla

    6/27

    pulic class orderlayout extends JFrame&

    pulic static Hnal int

  • 7/24/2019 Compendio Karla

    7/27

    pulic static void main *tring G args+&

    orderlayout gui( new orderlayout*+;

    gui.set?isile*true+;

    @

    @

    package layouts;

    import java.awt.Color;

    import java.awt.Container;

    import java.awt.IridLayout;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import javax.swing.JButton;

    import javax.swing.JFrame;

  • 7/24/2019 Compendio Karla

    8/27

    pulic class otones extends JFrame implements ActionListener&

    JButton oton% oton1% otonK% oton% oton0% otonD% oton% otonM%otonN;

    88constructor

    pulic otones*+&

    super *-otoesdecolores-+;

    Container contenedor (getContent>ane*+;

    88matri/ de KxK

    setLayout*new IridLayout*K%K%%++;

    oton( new JButton *-rojo-+;

    oton.setForeground*Color.red+;

    contenedor.add*oton+;

    oton1( new JButton *-verde-+;

    oton1.setForeground*Color.I$EE7+;

    contenedor.add*oton1+;

    otonK( new JButton *-a/ul-+;

    otonK.setForeground*Color.lue+;

    contenedor.add*otonK+;

    oton( new JButton *-amarillo-+;

    oton.setForeground*Color.yellow+;

    contenedor.add*oton+;

    oton0( new JButton *-naranja-+;

    oton0.setForeground*Color.orange+;

    contenedor.add*oton0+;

  • 7/24/2019 Compendio Karla

    9/27

    otonD( new JButton *-rosa-+;

    otonD.setForeground*Color.pink+;

    contenedor.add*otonD+;

    oton( new JButton *-magenta-+;

    oton.setForeground*Color.magenta+;

    contenedor.add*oton+;

    otonM( new JButton *-cyan-+;

    otonM.setForeground*Color.cyan+;

    contenedor.add*otonM+;

    otonN( new JButton *-negro-+;

    otonN.setForeground*Color.lack+;

    contenedor.add*otonN+;

    88llamando al metodo para generar -listeners-

    addListeners*+;

    @

    private void addListeners*+&

    oton.addActionListener*t=is+;

    oton1.addActionListener*t=is+;

    otonK.addActionListener*t=is+;

  • 7/24/2019 Compendio Karla

    10/27

    oton.addActionListener*t=is+;

    oton0.addActionListener*t=is+;

    otonD.addActionListener*t=is+;

    oton.addActionListener*t=is+;

    otonM.addActionListener*t=is+;

    otonN.addActionListener*t=is+;

    @

    pulic void action>er3ormed*ActionEvent e+&

    i3*e.getource*+((oton+&

    oton.setBackground*Color.red+;

    @

    i3*e.getource*+((oton1+&

    oton1.setBackground*Color.I$EE7+;

    @

    i3*e.getource*+((otonK+&

    otonK.setBackground*Color.lue+;

    @

    i3*e.getource*+((oton+&

    oton.setBackground*Color.yellow+;

    @

    i3*e.getource*+((oton0+&

    oton0.setBackground*Color.orange+;

    @

    i3*e.getource*+((otonD+&

  • 7/24/2019 Compendio Karla

    11/27

    otonD.setBackground*Color.pink+;

    @

    i3*e.getource*+((oton+&

    oton.setBackground*Color.magenta+;

    @

    i3*e.getource*+((otonM+&

    otonM.setBackground*Color.cyan+;

    @

    i3*e.getource*+((otonN+&

    otonN.setBackground*Color.lack+;

    @

    @

    pulic static void main*tringG ar+&

    otones 3ormulario(new otones*+;

    3ormulario.setBounds*)% )% D))% 0))+;

    3ormulario.set?isile*true+;

    @

  • 7/24/2019 Compendio Karla

    12/27

    @

    package layouts;

    import java.awt.Color;

    import java.awt.Container;

    import java.awt.IridLayout;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import javax.swing."mage"con;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    8OO

    O

    O Paut=or $ee

    O8

    pulic class imagenes extends JFrame implements ActionListener&

    JButton oton% oton1% otonK% oton% oton0% otonD% oton% otonM%otonN;

  • 7/24/2019 Compendio Karla

    13/27

    88constructor

    pulic imagenes *+&

    super *-otoesdecolores-+;

    Container contenedor (getContent>ane*+;

    88matri/ de KxK

    setLayout*new IridLayout*K%K%%++;

    oton( new JButton *-rojo-+;

    oton.setForeground*Color.red+;

    contenedor.add*oton+;

    oton1( new JButton *-verde-+;

    oton1.setForeground*Color.I$EE7+;

    contenedor.add*oton1+;

    otonK( new JButton *-a/ul-+;

    otonK.setForeground*Color.lue+;

    contenedor.add*otonK+;

    oton( new JButton *-amarillo-+;

    oton.setForeground*Color.yellow+;

    contenedor.add*oton+;

    oton0( new JButton *-naranja-+;

    oton0.setForeground*Color.orange+;

    contenedor.add*oton0+;

    otonD( new JButton *-rosa-+;

    otonD.setForeground*Color.pink+;

    contenedor.add*otonD+;

  • 7/24/2019 Compendio Karla

    14/27

    oton( new JButton *-magenta-+;

    oton.setForeground*Color.magenta+;

    contenedor.add*oton+;

    otonM( new JButton *-cyan-+;

    otonM.setForeground*Color.cyan+;

    contenedor.add*otonM+;

    otonN( new JButton *-negro-+;

    otonN.setForeground*Color.lack+;

    contenedor.add*otonN+;

    88llamando al metodo para generar -listeners-

    addListeners*+;

    @

    private void addListeners*+&

    oton.addActionListener*t=is+;

    oton1.addActionListener*t=is+;

    otonK.addActionListener*t=is+;

    oton.addActionListener*t=is+;

    oton0.addActionListener*t=is+;

    otonD.addActionListener*t=is+;

    oton.addActionListener*t=is+;

  • 7/24/2019 Compendio Karla

    15/27

    otonM.addActionListener*t=is+;

    otonN.addActionListener*t=is+;

    @

    pulic void action>er3ormed*ActionEvent e+&

    i3*e.getource*+((oton+&

    "mage"con ima ( new "mage"con*-a.jpg-+;

    oton.set"con*ima+;

    =ilo ilo( new =ilo*oton+;

    ilo.start*+;

    @

    i3*e.getource*+((oton1+&

    "mage"con ima1 ( new "mage"con*-.jpg-+;

    oton1.set"con*ima1+;

    =ilo ilo( new =ilo*oton1+;

    ilo.start*+;

    @

    i3*e.getource*+((otonK+&

    "mage"con imaK ( new "mage"con*-c.J>I-+;

    otonK.set"con*imaK+;

    =ilo ilo( new =ilo*otonK+;

    ilo.start*+;

    @

    i3*e.getource*+((oton+&

    "mage"con ima ( new "mage"con*-d.J>I-+;

    oton.set"con*ima+;

    =ilo ilo( new =ilo*oton+;

  • 7/24/2019 Compendio Karla

    16/27

    ilo.start*+;

    @

    i3*e.getource*+((oton0+&

    "mage"con ima0 ( new "mage"con*-e.J>I-+;

    oton0.set"con*ima0+;

    =ilo ilo( new =ilo*oton0+;

    ilo.start*+;

    @

    i3*e.getource*+((otonD+&

    "mage"con imaD ( new "mage"con*-3.J>I-+;

    otonD.set"con*imaD+;

    =ilo ilo( new =ilo*otonD+;

    ilo.start*+;

    @

    i3*e.getource*+((oton+&

    "mage"con ima ( new "mage"con*-g.jpg-+;

    oton.set"con*ima+;

    =ilo ilo( new =ilo*oton+;

    ilo.start*+;

    @

    i3*e.getource*+((otonM+&

    "mage"con imaM( new "mage"con*-=.jpg-+;

    otonM.set"con*imaM+;

    =ilo ilo( new =ilo*otonM+;

    ilo.start*+;

    @

  • 7/24/2019 Compendio Karla

    17/27

    i3*e.getource*+((otonN+&

    "mage"con imaN ( new "mage"con*-j.jpg-+;

    otonN.set"con*imaN+;

    =ilo ilo( new =ilo*otonN+;

    ilo.start*+;

    @

    @

    pulic static void main*tringG ar+&

    imagenes 3ormulario(new imagenes*+;

    3ormulario.setBounds*)% )% D))% 0))+;

    3ormulario.set?isile*true+;

    @

    @

  • 7/24/2019 Compendio Karla

    18/27

    package Fiesta;

    import Fiesta.2esincroni/ado;

    pulic class Borrac=o extends ,=read &

    private 2esincroni/ado sincro;

    private int numero;

    pulic Borrac=o*2esincroni/ado x% int numer+&

    sincro(x;

    numero(numer;

    @

    pulic void run*+&

    int value;

    3or*int i(; i;i+&

    value(sincro.getContenido*+;

    ystem.out.println*-Borrac=oQ - t=is.numero - ,oma -value -cervesa-+;

    try&

    88 proar consumidor mas rapido

  • 7/24/2019 Compendio Karla

    19/27

    88sleep*))+;

    88proar productor mas rapido

    sleep*))+;

    @catc=*"nterruptedException e+&

    @

    @

    @

    @

    package Fiesta;

    pulic class 2esincroni/ado &

    private int contenido;

    pulic int getContenido*+ &

    return contenido;

    @

    pulic void setContenido*int contenido+ &

    t=is.contenido ( contenido;

    @

    @

    package Fiesta;

  • 7/24/2019 Compendio Karla

    20/27

    import Fiesta.2esincroni/ado;

    pulic class #esero extends ,=read&

    private 2esincroni/ado sincro;

    private int numero;

    pulic #esero *2esincroni/ado c % int numer +&

    sincro ( c;

    numero ( numer;

    @

    pulic void run*+&

    3or *int i(; i; i+&

    sincro.setContenido*i+;

    ystem.out.println*-#eseroQ-t=is.numero - irve -i +;

    try&

    sleep*))+;

    @catc=*"nterruptedException e+&

    e.printtack,race*+;

    @

    @

    @

    package Fiesta;

    import Fiesta.2esincroni/ado;

  • 7/24/2019 Compendio Karla

    21/27

  • 7/24/2019 Compendio Karla

    22/27

    import Fiesta.#esero;

    pulic class >ruea>roductorConsumidor &

    pulic static void main*tring argsG+&

    2esincroni/ado desi( new 2esincroni/ado*+;

    #esero p ( new #esero*desi%+;

    Borrac=o c( new Borrac=o*desi%+;

    p.set>riority*,=read.#A56>$"4$",R+;

    c.set>riority*,=read.#"76>$"4$",R+;

    p.start*+;

    c.start*+;

    @

    @

    package sincro1;

  • 7/24/2019 Compendio Karla

    23/27

    pulic class >ruea>roductorConsumidor &

    pulic static void main*tring argsG+&

    2esincroni/ado d( new 2esincroni/ado*+;

    >roductor p ( new >roductor*d%+;

    Consumidor c( new Consumidor*d%+;

    p.start*+;

    c.start*+;

    @

    @

    package sincro1;

    pulic class Consumidor extends ,=read &

    private 2esincroni/ado sincro;

    private int numero;

    pulic Consumidor*2esincroni/ado x% int numer+&

    sincro(x;

    numero(numer;

    @

    pulic void run*+&

    int value;

    3or*int i(; i;i+&

    value(sincro.getContenido*+;

  • 7/24/2019 Compendio Karla

    24/27

    ystem.out.println*-Consumidor Q - t=is.numero -otiene - value+;

    try&

    88 proar consumidor mas rapido

    88sleep*))+;

    88proar productor mas rapido

    sleep*))+;

    @catc=*"nterruptedException e+&

    @

    @

    @

    @package sincro1;

    pulic class 2esincroni/ado &

    private int contenido;

    pulic int getContenido*+ &

    return contenido;

    @

    pulic void setContenido*int contenido+ &

    t=is.contenido ( contenido;

    @

    @

    package sincro1;

  • 7/24/2019 Compendio Karla

    25/27

    pulic class >roductor extends ,=read&

    private 2esincroni/ado sincro;

    private int numero;

    pulic >roductor *2esincroni/ado c % int numer +&

    sincro ( c;

    numero ( numer;

    @

    pulic void run*+&

    3or *int i(; i; i+&

    sincro.setContenido*i+;

    ystem.out.println*->roductor Q-t=is.numero - produce-i +;

    try&

    sleep*))+;

    @catc=*"nterruptedException e+&

    @

    @

    @

    @

  • 7/24/2019 Compendio Karla

    26/27

    package sincroK;

    import sincroK.2esincroni/ado;

    import sincroK.Consumidor;

    import sincroK.>roductor;

    pulic class >ruea>roductorConsumidor &

    pulic static void main*tring argsG+&

    2esincroni/ado desi( new 2esincroni/ado*+;

    >roductor p ( new >roductor*desi%+;

    Consumidor c( new Consumidor*desi%+;

    p.set>riority*,=read.#A56>$"4$",R+;

    c.set>riority*,=read.#"76>$"4$",R+;

    p.start*+;

  • 7/24/2019 Compendio Karla

    27/27

    c.start*+;

    @

    @