Sunteți pe pagina 1din 15

Universidad Politcnica Salesiana

Facultad de Ingeniera Elctrica


Nombre: Jefferson Enrquez Fecha: 08/10/2014 Fecha de entrega: mircoles 09 de octubre del 2013 INFORME 1 Tema: Pantallas Objetivo Principal: Saber programar pantallas en java

Objetivos Secundarios: Utilizar las pantallas y sus opciones para la utilizacin de estas con diferentes eventos de JAVA. Ver las diferentes formas de programar eventos en una pantalla con su respectivo cdigo de programacin. Saber las propiedades bsicas de cada evento y de la pantalla para una mejor ocupacin de ella. Solo ocupar lo necesario en las pantallas ya que se puede confundir con las otras opciones de estas. Repaso Ejercicio N1: package repaso; import java.io.*; * @author HP public class Repaso { * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here InputStreamReader dato=new InputStreamReader(System.in); BufferedReader dato1=new BufferedReader (dato); double vec1[],vec2[]; vec1=new double[6]; double aux,suma;

int dim; suma=0; try { // REALIZAR UN PROGRAMA PARA INGRESAR UN VECTOR DE 6 ELEMENTOS // Y ORDENARLOS ASCENDENTEMENTE VISUALIZAR EL VECTOR ORIGINAL Y EL ORDENADO for (int i = 0; i < 6; i++) { System.out.println("Ingrese el elemento "+(i+1)+" del vector 1"); vec1[i]=Double.parseDouble(dato1.readLine()); } for (int i = 0; i < 6; i++) { System.out.println(vec1[i]); } System.out.println("ordenamiento ascendente"); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6-1; j++) { if (vec1[j+1]>vec1[j]) { aux=vec1[j+1]; vec1[j+1]=vec1[j]; vec1[j]=aux; } } } System.out.println("visualizacion del vector ordenado ascendentemente"); for (int i = 0; i < 6; i++) { System.out.println(vec1[i]); } Visualizacin.-

Ejercicio N2: System.out.println("REALIZAR UN PROGRAMA QUE PERMITA SUMAR LOS ELEMENTOS"); System.out.println("PARES DE UN VECTOR DE DIMENSION DESCONOCIDA"); System.out.println(""); System.out.println("ingrese la dimension del vector"); dim=Integer.parseInt(dato1.readLine()); vec2=new double [dim]; for (int i = 0; i < dim; i++) { System.out.println("ingrese el elemento "+(i+1)+" del vector 2"); vec2[i]=Double.parseDouble(dato1.readLine()); if (vec2[i]%2==0) { suma=suma+vec2[i]; } } System.out.println("la suma de los elementos pares del vector 2 es "+suma); } Visualizacin.-

Pantallas CARATULA private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Graficos g1 = new Graficos(); g1.setVisible(true); this.setVisible(false); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jOptionPane1.showMessageDialog(null, "GRACIAS POR USAR EL SISTEMA ", "CAJA DE MENSAJES", 0, null); System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Caratula.class.getName()).log(java.util.logging.Level. SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Caratula.class.getName()).log(java.util.logging.Level. SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Caratula.class.getName()).log(java.util.logging.Level. SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Caratula.class.getName()).log(java.util.logging.Level. SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Caratula().setVisible(true); }

IMAGENES private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Caratula g1 = new Caratula(); g1.setVisible(true); this.setVisible(false); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 018.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_DEFAULT)); jLabel2.setIcon(icono); this.repaint(); ImageIcon fot1 = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 017.jpg"); Icon icono1 = new ImageIcon(fot1.getImage().getScaledInstance(jLabel3.getWidth(), jLabel3.getHeight(), Image.SCALE_DEFAULT)); jLabel3.setIcon(icono1); this.repaint(); ImageIcon fot2 = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 022.jpg");

Icon icono2 = new ImageIcon(fot2.getImage().getScaledInstance(jLabel4.getWidth(), jLabel4.getHeight(), Image.SCALE_DEFAULT)); jLabel4.setIcon(icono2); this.repaint(); jLabel2.setVisible(true); jLabel3.setVisible(true); jLabel4.setVisible(true); } private void formWindowActivated(java.awt.event.WindowEvent evt) { // TODO add your handling code here: jLabel2.setVisible(false); jLabel3.setVisible(false); jLabel4.setVisible(false); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Chequeos g1 = new Chequeos(); g1.setVisible(true); this.setVisible(false); }

CHEQUEOS private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here: Graficos gr1 = new Graficos(); gr1.setVisible(true); this.setVisible(false); } private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 004.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel4.getWidth(), jLabel4.getHeight(), Image.SCALE_DEFAULT)); jLabel4.setIcon(icono); this.repaint(); if(jCheckBox3.isSelected()) { jLabel4.setVisible(true); } else { jLabel4.setVisible(false); } } private void formWindowActivated(java.awt.event.WindowEvent evt) { // TODO add your handling code here: jLabel2.setVisible(false); jLabel3.setVisible(false); jLabel4.setVisible(false); } private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 012.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_DEFAULT)); jLabel2.setIcon(icono); this.repaint(); if(jCheckBox1.isSelected()) {

jLabel2.setVisible(true); } else { jLabel2.setVisible(false); } } private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 005.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel3.getWidth(), jLabel3.getHeight(), Image.SCALE_DEFAULT)); jLabel3.setIcon(icono); this.repaint(); if(jCheckBox2.isSelected()) { jLabel3.setVisible(true); } else { jLabel3.setVisible(false); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Opciones g1 = new Opciones(); g1.setVisible(true); this.setVisible(false); }

OPCIONES private void formWindowActivated(java.awt.event.WindowEvent evt) { // TODO add your handling code here: jLabel4.setVisible(false); jLabel3.setVisible(false); jLabel2.setVisible(false); } private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 023.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_DEFAULT)); jLabel2.setIcon(icono); this.repaint(); if(jRadioButton1.isSelected()) { jLabel2.setVisible(true);

jLabel4.setVisible(false); jLabel3.setVisible(false); jRadioButton2.setSelected(false); jRadioButton3.setSelected(false); } else { jLabel2.setVisible(false); } } private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 024.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel3.getWidth(), jLabel3.getHeight(), Image.SCALE_DEFAULT)); jLabel3.setIcon(icono); this.repaint(); if(jRadioButton2.isSelected()) { jLabel3.setVisible(true); jLabel2.setVisible(false); jLabel4.setVisible(false); jRadioButton1.setSelected(false); jRadioButton3.setSelected(false); } else { jLabel3.setVisible(false); } } private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 021.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel4.getWidth(), jLabel4.getHeight(), Image.SCALE_DEFAULT)); jLabel4.setIcon(icono); this.repaint();

if(jRadioButton3.isSelected()) { jLabel4.setVisible(true); jLabel2.setVisible(false); jLabel3.setVisible(false); jRadioButton1.setSelected(false); jRadioButton2.setSelected(false); } else { jLabel4.setVisible(false); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Chequeos gr1 = new Chequeos(); gr1.setVisible(true); this.setVisible(false); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Datos gr1 = new Datos(); gr1.setVisible(true); this.setVisible(false); }

DATOS private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Opciones gr1 = new Opciones(); gr1.setVisible(true); this.setVisible(false); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String nom,ape; int edad; double peso; nom=jTextField1.getText(); ape=jTextField2.getText(); edad= Integer.parseInt(jTextField3.getText()); peso= Double.parseDouble(jTextField4.getText()); jLabel6.setText("Hola soy "+nom+" "+ape+" mi edad es "+edad+" aos mi peso es "+peso+" kilos"); }

Conclusiones: Cada swing controls tiene propiedades de color, fuente, tamao y estas son reaccionan a eventos con botn, desplazar, seleccionar, des chequear. [1] Cuando se inserta una imagen en jLabel esta no va a salir ajustada en jLabel para ello toca poner el siguiente cdigo ImageIcon fot = new ImageIcon("C:/Users/J3ff3r/Pictures/2013-10-04 jeffer/jeffer 005.jpg"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(jLabel3.getWidth(), jLabel3.getHeight(), Image.SCALE_DEFAULT)); jLabel3.setIcon(icono); this.repaint(); en importa las libreras import java.awt.Image; import javax.swing.Icon; import javax.swing.ImageIcon; [2] Los jLabel y jButton estos componentes no sirven para mostrar variables pero con propiedades especificas cada uno de estos componentes [3]

[1] www.apuntes.delibertad.com. [En lnea]. Available: http://apuntes.delibertad.com/java/evento-del-boton-cerrar-de-las-ventanas/. [ltimo acceso: 08 10 2013]. [2] www.apuntesdejava.com, [En lnea]. Available: http://aflrovvs.blogspot.com/2012_09_01_archive.html. [ltimo acceso: 2013 10 08]. [3] www.slodeshare.com, [En lnea]. Available: http://www.slideshare.net/jorgeadelmo/tutorial-netbeans. [ltimo acceso: 2013 10 08].

S-ar putea să vă placă și