package tarea3.docx

download package tarea3.docx

of 6

Transcript of package tarea3.docx

  • 8/17/2019 package tarea3.docx

    1/6

    package tarea3_programa1;

    import java.awt.EventQueue;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

     

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JLae!;

    import javax.swing.J"ane!;

    import javax.swing.J#extFie!$;import javax.swing.%wing&onstants;

    import javax.swing.or$er.#it!e$Bor$er;

    '((

     (

     ( )aut*or a$ria_++1

     ('

     

    pu!ic c!ass ,a!or -

     

    private JFrame rm&a!cu!ava!or;

      private J#extFie!$ txt,a!or1;

      private J#extFie!$ txt,a!or/;

  • 8/17/2019 package tarea3.docx

    2/6

      private J#extFie!$ txt,a!or3;

      private J#extFie!$ txt0esu!ta$o;

     

    '((

      ( Lana !a ap!icaci2n.

      ( )param args

      ('

      pu!ic static voi$ main%tring45 args6 -

      EventQueue.invokeLater6 78 -

      tr9 -  ,a!or win$ow : new ,a!or6;

      win$ow.rm&a!cu!ava!or.set,isi!etrue6;

      catc* Exception e6 -

     

      6;

     

     

    '((

      ( &onstructor< crea !a ap!icaci2n.

      ('

      pu!ic ,a!or6 -

      initia!ie6;

     

     

    '((

      ( =nicia!ia to$o e! conteni$o $e! rame principa!.

  • 8/17/2019 package tarea3.docx

    3/6

      ('

      private voi$ initia!ie6 -

      rm&a!cu!ava!or : new JFrame6;

      rm&a!cu!ava!or.set#it!e>&a!cu!a va!or>6;

      rm&a!cu!ava!or.set0esia!ea!se6;

      rm&a!cu!ava!or.setBoun$s1++? 1++? @+? /3@6;

      rm&a!cu!ava!or.seteau!t&!oseCperationJFrame.ED=#_C_&LC%E6;

      rm&a!cu!ava!or.get&ontent"ane6.setLa9outnu!!6;

     

     J"ane! pane!,a!or : new J"ane!6;  pane!,a!or.setBor$ernew #it!e$Bor$ernu!!? >va!or>?

     #it!e$Bor$er.LEA=? #it!e$Bor$er.#C"? nu!!? nu!!66;

      pane!,a!or.setBoun$s1+? /@? @/@? 1GH6;

      rm&a!cu!ava!or.get&ontent"ane6.a$$pane!,a!or6;

      pane!,a!or.setLa9outnu!!6;

     

    '' &rean$o etiIuetas<

      JLae! !!ota1 : new JLae!>,a!or 16;

      !!ota1.setorionta!A!ignment%wing&onstants.0=#6;

      !!ota1.setBoun$s1+? /@? +? //6;

      pane!,a!or.a$$!!ota16;

     

     JLae! !ota/ : new JLae!>,a!or /6;

      !ota/.setorionta!A!ignment%wing&onstants.0=#6;

      !ota/.setBoun$s1+? K? +? //6;

      pane!,a!or.a$$!ota/6;

     

  • 8/17/2019 package tarea3.docx

    4/6

      JLae! !!ota3 : new JLae!>,a!or 36;

      !!ota3.setorionta!A!ignment%wing&onstants.0=#6;

      !!ota3.setBoun$s1+? +? +? //6;

      pane!,a!or.a$$!!ota36;

     

    '' instancian$o !os #extFie!$

      txt,a!or1 : new J#extFie!$6;

      txt,a!or1.setBoun$sG? /? /H? /+6;

      pane!,a!or.a$$txt,a!or16;

      txt,a!or1.set&o!umns1+6; 

    txt,a!or/ : new J#extFie!$6;

      txt,a!or/.set&o!umns1+6;

      txt,a!or/.setBoun$sG? H? /H? /+6;

      pane!,a!or.a$$txt,a!or/6;

     

    txt,a!or3 : new J#extFie!$6;

      txt,a!or3.set&o!umns1+6;

      txt,a!or3.setBoun$sK+? 1? /H? /+6;

      pane!,a!or.a$$txt,a!or36;

     

    txt0esu!ta$o : new J#extFie!$6;

      txt0esu!ta$o.set&o!umns1+6;

      txt0esu!ta$o.setBoun$s1H? 133? /H? /+6;

      pane!,a!or.a$$txt0esu!ta$o6;

     

  • 8/17/2019 package tarea3.docx

    5/6

      ''crean$o e! ot2n

      JButton tn&a!cu!ar,a!or : new JButton>&a!cu!ar ,a!or>6;

      ''aMa$ien$o e! !istener para Iue$ar a !a escuc*a $e! evento &L=&N 

      tn&a!cu!ar,a!or.a$$ActionListenernew&a!cu!a,a!orActionListener66;

      tn&a!cu!ar,a!or.setBoun$s/+? 133? 1? /+6;

      pane!,a!or.a$$tn&a!cu!ar,a!or6;

     

    '((

      ( &a!cu!a e! prome$io $e !as tres notas.

      ('

      c!ass &a!cu!a,a!orActionListener imp!ements ActionListener -

     

    )Cverri$e

      pu!ic voi$ action"erorme$ActionEvent e6 -

     

    ''recogemos !as notas $e !os textOe!$

      %tring str1 : txt,a!or1.get#ext6;

      %tring str/ : txt,a!or1.get#ext6;

      %tring str3 : txt,a!or1.get#ext6;

     

    ''convertimos a enteros para po$er traajar con e!!os.

      int n1 : =nteger.parse=ntstr16;

      int n/ : =nteger.parse=ntstr/6;

      int n3 : =nteger.parse=ntstr36;

  • 8/17/2019 package tarea3.docx

    6/6

     

    ''ca!cu!amos e! prome$io

      int suma : n1 P n/ P n3;

      int ,a!or : suma ' 3;

     

    '' convertimos a %tring nuevamente

      %tring resu!ta$o : %tring.va!ueC,a!or6;

     

    ''ponemos e! resu!ta$o en e! textOe!$ correspon$iente

    txt0esu!ta$o.set#extresu!ta$o6;