Documentos de Académico
Documentos de Profesional
Documentos de Cultura
CasoProblema01 PDF
CasoProblema01 PDF
INTEGRANTES:
DOCENTE:
CURSO:
PROGRAMACIN VISUAL II
FACULTAD:
INGENIERA DE SISTEMAS
FILIAL PIURA
package casoproblema01;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author luis
*/
public class CasoProblema01 {
/**
* @param args the command line arguments
*/
public static Image icono(){//metodo para poner el icono a la ventana inicio
Image
valor=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("img/spotify.png"));//
se asigna la ruta donde esta la imagen a usar como icono.
return valor;//retorna la imagen
}
public static void main(String[] args) {
// se crea el formulario de acceso junto a un panel se asigna un tamao a la ventana
JFrame ventana=new JFrame("Acceso Sistema");
JPanel panel1=new Jpanel();
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setBounds(500,300,250,120);
ventana.setIconImage(icono());
panel1.setLayout(new FlowLayout());
//se crea un boton para acceder al sistema validando un usuario y contrasea. Si la contrasea y
usuario son correctos nos permitira acceder a las opciones caso contrario se enviara un mensaje de
error.
JButton boton=new JButton("INGRESAR");
panel1.add(boton);
boton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
String us="Luis";
String pass="1234";
String clave=new String(contrasea.getPassword());
}
}
});
//se agrega el panel a la ventana, esta ventana no podra ser redimensionada y por ltimo se
hace visible
ventana.add(panel1);
ventana.setResizable(false);
ventana.setVisible(true);
}
}
Pantalla de Inicio de Sesin:
Men de Opciones;
package casoproblema01;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author luis
*/
public class Principal {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
mostrar();//se llama al mtodo mostrar
}
public static Image icono(){
Image
valor=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("img/menu-
hover.png"));
return valor;
}
public static void mostrar(){//metodo el cual contiene las opcione a realizar
//se crea la ventana y se le da un titulo, adems la ventana aparecer maximizada
JFrame ventana=new JFrame("MENU PRINCIPAL");
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setExtendedState(JFrame.MAXIMIZED_BOTH);
ventana.setIconImage(icono());
//se crea un desktopPane y se agregar a la ventana al igual que una barra d opciones
JDesktopPane dp=new JDesktopPane();
ventana.getContentPane().add(dp);
JToolBar barra=new JToolBar();
barra.setBounds(100,200,10,20);
//se crea el panel y los botonos que contienen las opciones del sistema y se agregan a la barra
JPanel panel1=new JPanel();
panel1.setLayout(new FlowLayout());
JButton boton=new JButton("Registro De Notas");
JButton boton1=new JButton("Editor");
JButton boton2=new JButton("Archivos");
barra.add(boton);
barra.add(boton1);
barra.add(boton2);
barra.setFloatable(false);
barra.addSeparator();
//se crea un segundo panel con una nueva barra y nuevos botones y se agregan a la nueva barra
junto con un textarea y todos se agrega al panel
JPanel panel2=new JPanel();
panel2.setLayout(new FlowLayout());
JToolBar barra1=new JToolBar();
barra1.setBounds(100,200,200,150);
JButton abrir=new JButton("Abrir");
JButton nuevo=new JButton("Nuevo");
JButton guardar=new JButton("Guardar");
barra1.add(nuevo);
barra1.add(abrir);
barra1.add(guardar);
barra1.setFloatable(false);
barra1.addSeparator();
JTextArea texto=new JTextArea(25,80);
texto.setLineWrap(true);
texto.setWrapStyleWord(true);
panel2.add(barra1);
panel2.add(texto);
//se crea el formulario intero se le asigna un tamao el desktopPane va contener a este nuevo
formulario interno
JInternalFrame internal1=new JInternalFrame("Editor",true,true,true,true);
internal1.add(panel2);
internal1.setBounds(550,500,250,90);
internal1.setResizable(true);
dp.add(internal1);
//se programa el boton para que al hacer clic nos muestre el formulario de registro de notas
boton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
new RegistrarNotas();
}
});
//se programa el boton para mostrar el formulario interno en este caso el editor de textos se mostrar
aqu
boton1.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
internal1.setVisible(true);
}
});
//se programa el boton abrir de la segunda barra en el formulario interno el cual nos mostrara la ruta
para poder abrir un archivo de texto
abrir.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
try {
String nombre="";
String TEXTO;
JFileChooser MI_ARCHIVO=new
JFileChooser(System.getProperty("/home/Luis"));
MI_ARCHIVO.showOpenDialog(texto);
File ABRIR=MI_ARCHIVO.getSelectedFile();
if(ABRIR != null) {
nombre=MI_ARCHIVO.getSelectedFile().getName();
texto.setText("");
FileReader FICHERO=new FileReader(ABRIR);
BufferedReader LEER=new BufferedReader(FICHERO);
internal1.setTitle(nombre+"- Editor");
while((TEXTO=LEER.readLine()) != null) {
texto.append(TEXTO+ "\n"); //append Concatena la linea leida
}
LEER.close();
texto.setVisible(true);
}
} catch(FileNotFoundException exp) {
JOptionPane.showMessageDialog(null, "El archivo no existe o no se"+
"encuentra en esta carpeta.","Error",
JOptionPane.WARNING_MESSAGE);
} catch(Exception exp) {
System.out.println(exp);
}
}
});
//el boton nuevo nos limpiara el textarea en el caso que contenga texto caso contrario se visualizar
nuevo.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
texto.setVisible(true);
if (texto.getText()== null) {
}else{
texto.setText("");
texto.requestFocus();
}
// texto.removeAll();
// texto.setVisible(true);
}
}
);
//se agrega todo a la ventana principal y al formulario interno tanto panel como barras
respectivamente y en determinada posicin
ventana.getContentPane().add(barra, BorderLayout.NORTH);
internal1.getContentPane().add(barra1, BorderLayout.NORTH);
internal1.getContentPane().add(texto);
JScrollPane scroll = new JScrollPane(texto);
internal1.getContentPane().add(scroll);
internal1.getContentPane().add(barra2, BorderLayout.SOUTH);
texto.setVisible(false);
ventana.setVisible(true);
}
public static int cuentaPalabras(String s){
int conteoPalabras = 0;
boolean palabra = false;
int finDeLinea = s.length() - 1;
}
Formulario con las opciones del sistema
Registro de Matricula
package casoproblema01;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
/**
*
* @author luis
*/
public class RegistrarNotas {
private JFrame ventana;
private JDialog ventanasecundaria;
private JTable tabla;
private DefaultTableModel tabladatos;
private TableRowSorter trsfiltro;
/**
* @param args the command line arguments
*/
public static Image icono(){
Image
valor=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("img/spotify.png"));
return valor;
}
public static void main(String[] args) {
new RegistrarNotas();//se visualizar el formulario con las opciones para registrar y sacar
promedio
}
public RegistrarNotas(){
//se crea la ventana un panel y una ventana secundaria que ser un Jdialog cada una con un tamao
ventana=new JFrame("Registro de Notas");
JPanel panel1=new JPanel();
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setBounds(500,200,250,400);
ventana.setIconImage(icono());
panel1.setLayout(new FlowLayout());
ventanasecundaria=new JDialog(ventana,"Buscar Alumno");
ventanasecundaria.setBounds(400, 300, 550, 200);
//se crean las etiquetas y las cajas de texto y botones y se agregan al panel
JLabel alum=new JLabel("Alumno: ");
alum.setBounds(50,40,100,30);
panel1.add(alum);
JTextField al=new JTextField(10);
al.setEditable(false);
al.setBounds(70,40,100,30);
panel1.add(al);
ButtonGroup grupo=new ButtonGroup();
JRadioButton u1=new JRadioButton("Un. I",true);
JRadioButton u2=new JRadioButton("Un. II",false);
JRadioButton u3=new JRadioButton("Un. III",false);
grupo.add(u1);
grupo.add(u2);
grupo.add(u3);
JButton buscar=new JButton("...");
panel1.add(buscar);
panel1.add(u1);
panel1.add(u2);
panel1.add(u3);
panel1.add(new JLabel("Nota 01:"));
JTextField n1=new JTextField(10);
panel1.add(n1);
panel1.add(new JLabel("Nota 02:"));
JTextField n2=new JTextField(10);
panel1.add(n2);
panel1.add(new JLabel("Nota 03:"));
JTextField n3=new JTextField(10);
panel1.add(n3);
panel1.add(new JLabel("Nota 04:"));
JTextField n4=new JTextField(10);
panel1.add(n4);
panel1.add(new JLabel("Nota 05:"));
JTextField n5=new JTextField(10);
panel1.add(n5);
panel1.add(new JLabel("Nota 06:"));
JTextField n6=new JTextField(10);
panel1.add(n6);
JButton cal=new JButton("Promedio Alumno");
panel1.add(cal);
panel1.add(new JLabel("Promedio U. 1"));
JTextField prom1=new JTextField(10);
panel1.add(prom1);
panel1.add(new JLabel("Promedio U. 2"));
JTextField prom2=new JTextField(10);
panel1.add(prom2);
panel1.add(new JLabel("Promedio U. 3"));
JTextField prom3=new JTextField(10);
panel1.add(prom3);
panel1.add(new JLabel("Promedio Final"));
JTextField pfin=new JTextField(10);
panel1.add(pfin);
prom1.setEditable(false);
prom2.setEditable(false);
prom3.setEditable(false);
pfin.setEditable(false);
prom1.setText("0");
prom2.setText("0");
prom3.setText("0");
pfin.setText("0");
JButton agregar=new Jbutton("Aadir");
//boton para calcular el promedio de las notas por unidad
cal.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
int nt1,nt2,nt3,nt4,nt5,nt6;
nt1=Integer.parseInt(n1.getText());
nt2=Integer.parseInt(n2.getText());
nt3=Integer.parseInt(n3.getText());
nt4=Integer.parseInt(n4.getText());
nt5=Integer.parseInt(n5.getText());
nt6=Integer.parseInt(n6.getText());
if (u1.isSelected()==true && nt1<=20 && nt2<=20 && nt3<=20 && nt4<=20 &&
nt5<=20 && nt6<=20) {
prom1.setText(String.valueOf(promedio(nt1,nt2,nt3,nt4,nt5,nt6)));
}else if(u2.isSelected()==true && nt1<=20 && nt2<=20 && nt3<=20 && nt4<=20 &&
nt5<=20 && nt6<=20){
prom2.setText(String.valueOf(promedio(nt1,nt2,nt3,nt4,nt5,nt6)));
}else if(u3.isSelected()==true && nt1<=20 && nt2<=20 && nt3<=20 && nt4<=20 &&
nt5<=20 && nt6<=20){
prom3.setText(String.valueOf(promedio(nt1,nt2,nt3,nt4,nt5,nt6)));
}else{
JOptionPane.showMessageDialog(null,"Las notas van de 0 a 20");
}
int p1,p2,p3;
p1=Integer.parseInt(prom1.getText());
p2=Integer.parseInt(prom2.getText());
p3=Integer.parseInt(prom3.getText());
if (p1==0 || p2==0 || p3==0) {
}else{
int promedio=(p1+p2+p3)/3;
pfin.setText(String.valueOf(promedio));
}
}
});
JLabel etiqueta1=new JLabel("Buscar Alumno: ");
JTextField bal=new JTextField(10);
bal.setBounds(70,40,100,30);
// JTable tabla = new Jtable();
//boton buscar nos abrira el Jdialog para buscar al alumno en nuestros registros
buscar.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
JPanel panel=new JPanel();
panel.setLayout(new FlowLayout());
ventanasecundaria.setVisible(true);
panel.add(etiqueta1);
panel.add(bal);
Object[][] data = {
{"Mary", "Campione", "F"},
{"Lucas", "Huml", "M"},
{"Kathya", "Walrath", "F"},
{"Marcus", "Andrews", "M"},
{"Angela", "Lalth","F"},
{"Jos", "Camos", "M"},
{"Laura", "Hamilton", "F"},
{"Ral", "Ramos", "M"},
{"Ingrid", "Alvarez", "F"},
{"Andrs", "Lpez","M"}
};
String[] columnas = {"Nombre", "Apellido", "Sexo"};
tabla = new JTable(data, columnas);
panel.add(agregar);
JScrollPane scroll= new JScrollPane(tabla);
panel.add(scroll, BorderLayout.CENTER);
ventanasecundaria.getContentPane().add(panel);
});
//boton agregar nos enviara el nombre y apellido del alumno seleccionado a nuestro formulario de
registro de notas
agregar.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
int filaseleccionada;
try{
//Guardamos en un entero la fila seleccionada.
filaseleccionada = tabla.getSelectedRow();
if (filaseleccionada == -1){
JOptionPane.showMessageDialog(null, "No ha seleccionado ninguna fila.");
} else {
// ventana.setVisible(true);
// ventanasecundaria.
bal.addKeyListener(new KeyAdapter() {
public void keyDown(final KeyEvent e){
String filtro;
int columna;
filtro=bal.getText().toLowerCase();
columna=0;
trsfiltro.setRowFilter(RowFilter.regexFilter(filtro, columna));
tabla.setRowSorter(trsfiltro);
}
});
}
//metodo para calcular el promedio de las notas
public static Integer promedio(int n1,int n2,int n3,int n4,int n5,int n6){
int pro;
pro=(n1+n2+n3+n4+n5+n6)/6;
return pro;
}
Buscar Alumno
Promedio del Alumno
package casoproblema01;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
/**
*
* @author luis
*/
public class Arbol extends Frame implements TreeSelectionListener{
private JScrollPane scrollraiz;
private JTree raiz;
private DefaultListModel modelo;
private JList lista;
private JScrollPane scrolldir;
public Arbol(){
JFrame v = new JFrame();
v.setBounds(30, 40, 200, 200);
scrollraiz=new JScrollPane(raiz);
scrollraiz.setVerticalScrollBarPolicy(
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
v.getContentPane().add(scrollraiz, BorderLayout.WEST);
modelo=new DefaultListModel();
lista=new JList(modelo);
scrolldir=new JScrollPane(lista);
scrolldir.setVerticalScrollBarPolicy(
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
v.getContentPane().add(scrolldir, BorderLayout.CENTER);
v.pack();
v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v.setBounds(300, 300, 500, 450);
v.setTitle("Administrador de Archivos-by Luis F. Cruz");
v.setIconImage(icono());
v.setVisible(true);
}
public Image icono(){
Image valor=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("img/file-
manager.png"));
return valor;
}
public static void main(String[] args) {
new Arbol();
}
populatenode(curr,archivos[i],depth -1);
node.add(curr);
}
}
return true;
}
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node=(DefaultMutableTreeNode)
raiz.getLastSelectedPathComponent();
modelo.removeAllElements();
if (archivos != null)
for (int i = 0; i < archivos.length; i++) {
modelo.addElement(archivos[i]);
}
}
public void extenderarbol(TreeSelectionEvent e){
raiz.addTreeExpansionListener((TreeExpansionListener) this);
TreePath path=e.getPath();
DefaultMutableTreeNode node=
(DefaultMutableTreeNode) path.getLastPathComponent();
setCursor(new Cursor(Cursor.WAIT_CURSOR));
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));