POO2_U2_A3_DICA

August 8, 2017 | Author: Dixie Ceniceros | Category: Software Development, Software, Areas Of Computer Science, Software Engineering, Computer Programming
Share Embed Donate


Short Description

Download POO2_U2_A3_DICA...

Description

UNIVERSIDAD ABIERTA Y A DISTANCIA DE MEXICO

PROGRAMACIÓN ORIENTADA A OBJETOS 2

ACTIVIDAD 3 UNIDAD 2 MENÚS Y VENTANAS

FACILITADOR (A): JEANETTE CORINA CASTAÑEDA CORRAL

ALUMNO (A): DIXIE ROSARIO CENICEROS ALVARADO AL12501794

17 de julio de 2014

Ahora que aprendiste todas las características de funcionamiento para los menús y ventanas, estás listo para realizar las siguientes instrucciones. Propósito: Construir menús y ventanas gráficas, así como identificar su declaración e implementar su manipulación. Instrucciones: 1. Identifica los diferentes tipos de menús y ventanas gráficas vistas en el desarrollo de la unidad. 2. Identifica su estructura algorítmica (pasos) y sintáctica (código). 3. Crea un proyecto en NetBeans, que contenga un programa donde apliques todos los contenedores y controles identificados en los puntos 1 y 2. .

Descripción del código package poo2_u2_a3_dica; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.*; /** * * @author dx */ public class POO2_U2_A3_DICA extends JFrame implements ActionListener{ private JMenuBar barra; private JMenu elemento1,elemento2; private JMenuItem sub1,sub2,sub3,sub4;

public POO2_U2_A3_DICA() { setLayout(null); barra=new JMenuBar(); setJMenuBar(barra); elemento1=new JMenu("Opciones"); barra.add(elemento1); sub1=new JMenuItem("Abrir Ventana"); sub1.addActionListener(this); elemento1.add(sub1); sub2=new JMenuItem("Menu Emergente"); sub2.addActionListener(this); elemento1.add(sub2); sub3=new JMenuItem("Salir"); sub3.addActionListener(this); elemento1.add(sub3); elemento2=new JMenu("JFileChooser"); barra.add(elemento2); sub4=new JMenuItem("File"); sub4.addActionListener(this); elemento2.add(sub4); } @Override public void actionPerformed(ActionEvent e) { Container f=this.getContentPane();

if (e.getSource()==sub1) { Ventana2 vtn =new Ventana2(); vtn.Ventana2(); } if (e.getSource()==sub2) { int a = JOptionPane.showConfirmDialog(null,"Deseas continuar"); String b = JOptionPane.showInputDialog("Ingresa un dato"); Object[] valores = { "Uno", "Dos", "Tres" }; Object valorElegido = JOptionPane.showInputDialog(null,"Elige", "Entrada", JOptionPane.INFORMATION_MESSAGE, null,valores, valores[0]); JOptionPane.showMessageDialog(null, "Mensaje", "Cuidado", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(null, "Algo fallo", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "Sin icono", "Plano", JOptionPane.PLAIN_MESSAGE); Object[] opciones = { "Yes", "No" }; JOptionPane.showOptionDialog(null, "Presiona Yes Para continuar", "Selecciona", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,null, opciones, opciones[0]); } if (e.getSource()==sub3) { System.exit(0); } if (e.getSource()==sub4) { JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); File file = fc.getSelectedFile(); System.out.print(file); } } public static void main(String[] ar) { POO2_U2_A3_DICA frame =new POO2_U2_A3_DICA(); frame.setBounds(50,50,300,200); frame.setVisible(true); } } package poo2_u2_a3_dica; import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;

import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; /** * * @author dx */ public class Ventana2 { JPopupMenu popup = new JPopupMenu();

public void Ventana2(){ JFrame frame = new JFrame("POO2_U2_A2_DICA"); frame.setLocationRelativeTo(null); frame.setSize(300, 300); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e){ System.exit(0); } });

JMenuItem menu0 = new JMenuItem("Esto es un Menu Poppup"); JMenuItem menu1 = new JMenuItem("Menu Poppup"); JMenuItem menu2 = new JMenuItem("Item del Menu Poppup"); popup.add(menu0);popup.add(menu1); popup.add(menu2); frame.add(popup, BorderLayout.LINE_START); JLabel lbl1 = new JLabel(); lbl1.setText("Aqui hay un menu poppup"); frame.add(lbl1, BorderLayout.LINE_END); } public void dispose() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }

}

Código de colores: Amarillo. Todas las librerías a importar Verde lima. Se declaran los componentes a usar. Turquesa. Se declara el JFrame y se le integran los JPanel para saber dónde va cada uno. Fucsia. Configuración de los diferentes tipos de menús y componentes Gris. Se cierra el JFrame invocado pero no termina el programa Morado. Creamos objetos e invocamos la clase

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF