ORIENTADA A OBJETOS 2
ACTIVIDAD 3
UNIDAD 2
MENS Y VENTANAS
FACILITADOR (A): JEANETTE CORINA CASTAEDA CORRAL
ALUMNO (A): DIXIE ROSARIO CENICEROS ALVARADO
AL12501794
17 de julio de 2014
Ahora que aprendiste todas las caractersticas de funcionamiento para los mens y
ventanas, ests listo para realizar las siguientes instrucciones. Propsito: Constru
ir mens
y ventanas grficas, as como identificar su declaracin e implementar su m
anipulacin.
Instrucciones:
1. Identifica los diferentes tipos de mens y ventanas grficas vistas en el desarro
llo de la
unidad.
2. Identifica su estructura algortmica (pasos) y sintctica (cdigo).
3. Crea un proyecto en NetBeans, que contenga un programa donde apliq
ues todos los
contenedores y controles identificados en los puntos 1 y 2.
.
Descripcin del cdigo
package poo2_u2_a3_dica;
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link].*;
/**
*
* @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");
[Link](elemento1);
sub1=new JMenuItem("Abrir Ventana");
[Link](this);
[Link](sub1);
sub2=new JMenuItem("Menu Emergente");
[Link](this);
[Link](sub2);
sub3=new JMenuItem("Salir");
[Link](this);
[Link](sub3);
elemento2=new JMenu("JFileChooser");
[Link](elemento2);
sub4=new JMenuItem("File");
[Link](this);
[Link](sub4);
}
@Override
public void actionPerformed(ActionEvent e) {
Container f=[Link]();
if ([Link]()==sub1) {
Ventana2 vtn =new Ventana2();
vtn.Ventana2();
}
if ([Link]()==sub2) {
int a = [Link](null,"Deseas continuar");
String b = [Link]("Ingresa un dato");
Object[] valores = { "Uno", "Dos", "Tres" };
Object valorElegido = [Link](null,"Elige",
"Entrada",
JOptionPane.INFORMATION_MESSAGE, null,valores, valores[0])
;
[Link](null, "Mensaje", "Cuidado",
JOptionPane.WARNING_MESSAGE);
[Link](null, "Algo fallo", "Error",
JOptionPane.ERROR_MESSAGE);
[Link](null, "Sin icono", "Plano",
JOptionPane.PLAIN_MESSAGE);
Object[] opciones = { "Yes", "No" };
[Link](null, "Presiona Yes Para continuar",
"Selecciona",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null, opciones, opciones[0]);
}
if ([Link]()==sub3) {
[Link](0);
}
if ([Link]()==sub4) {
JFileChooser fc = new JFileChooser();
[Link](null);
File file = [Link]();
[Link](file);
}
}
public static void main(String[] ar) {
POO2_U2_A3_DICA frame =new POO2_U2_A3_DICA();
[Link](50,50,300,200);
[Link](true);
}
}
package poo2_u2_a3_dica;
import [Link];
import [Link];
import [Link];
import
import
import
import
[Link];
[Link];
[Link];
[Link];
/**
*
* @author dx
*/
public class Ventana2 {
JPopupMenu popup = new JPopupMenu();
public void Ventana2(){
JFrame frame = new JFrame("POO2_U2_A2_DICA");
[Link](null);
[Link](300, 300);
[Link](true);
[Link](new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e){ [Link](0);
} });
JMenuItem menu0 = new JMenuItem("Esto es un Menu Poppup");
JMenuItem menu1 = new JMenuItem("Menu Poppup");
JMenuItem menu2 = new JMenuItem("Item del Menu Poppup");
[Link](menu0);[Link](menu1); [Link](menu2);
[Link](popup, BorderLayout.LINE_START);
JLabel lbl1 = new JLabel();
[Link]("Aqui hay un menu poppup");
[Link](lbl1, BorderLayout.LINE_END);
}
public void dispose() {
throw new UnsupportedOperationException("Not supported yet."); //To chan
ge body
of generated methods, choose Tools | Templates.
}
}
Cdigo de colores:
Amarillo. Todas las libreras a importar
Verde lima. Se declaran los componentes a usar.
Turquesa. Se declara el JFrame y se le integran los JPanel para saber dnde va
cada uno.
Fucsia. Configuracin de los diferentes tipos de mens y componentes
Gris. Se cierra el JFrame invocado pero no termina el programa
Morado. Creamos objetos e invocamos la clase