Está en la página 1de 18

GRUPO N3

INTEGRANTES:

CUNYA CAMPOS ANGIE PAMELA

FARFAN CRUZ LUIS MANUEL

GUERRERO ESTRADA FRANK JHONAIKER

NAVARRO YAMUNAQUE LIDIA DEL ROSARIO

VARGAS CORONADO JANS CRISTHIAN

DOCENTE:

ING. JENNIFER SULLN CHINGA

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 crean 2 etiquetas, 1 textfield y un jpassword y son agregados al panel


JLabel text=new JLabel("Usuario: ");
text.setBounds(50,40,100,30);
panel1.add(text);
JTextField user=new JTextField(10);
user.setBounds(70,40,100,30);
panel1.add(user);
JLabel text1=new JLabel("Password: ");
text1.setBounds(50,40,100,30);
panel1.add(text1);
JPasswordField contrasea=new JPasswordField(10);
panel1.add(contrasea);

//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());

if (user.getText().equals(us) && clave.equals(pass)){


ventana.setVisible(false);
Principal f1=new Principal();
f1.mostrar();
}else{
JOptionPane.showMessageDialog(null, "Acceso denegado:\n" + "Por favor ingrese
un usuario y/o contrasea vlido",
"Acceso denegado", JOptionPane.ERROR_MESSAGE);

}
}
});
//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 para mostrar el explorador de archivos


boton2.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent evento )
{
new Arbol();
}
});

//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);

}
}
);

JToolBar barra2=new JToolBar();


barra2.setBounds(0,200,20,200);
String text=texto.getText();
String cont=String.valueOf(cuentaPalabras(text));
JLabel con=new JLabel(cont +" PALABRAS");
barra2.add(con);
barra2.setFloatable(false);

//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;

for (int i = 0; i < s.length(); i++) {


// Si el char is una letra, word = true.
if (Character.isLetter(s.charAt(i)) && i != finDeLinea) {
palabra = true;
// Si el char no es una letra y an hay ms letras,
// el contador continua.
} else if (!Character.isLetter(s.charAt(i)) && palabra) {
conteoPalabras++;
palabra = false;
// ltima palabra de la cadena; si no termina con una no letra ,
} else if (Character.isLetter(s.charAt(i)) && i == finDeLinea) {
conteoPalabras++;
}
}
return conteoPalabras;
}

}
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);

// Inicializamos el modelo de la tabla


tabladatos = new DefaultTableModel();

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);

tabla.setPreferredScrollableViewportSize(new Dimension(500, 80));


// tabla.setRowSorter(trsfiltro);

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.

//String ayuda = tabla.getValueAt(filaseleccionada, num_columna).toString());


String nom = (String)tabla.getValueAt(filaseleccionada, 0);
String ape = (String)tabla.getValueAt(filaseleccionada, 1);
al.setText(nom+" "+ape);
}
}catch (HeadlessException ex){
JOptionPane.showMessageDialog(null, "Error: "+ex+"\nIntntelo nuevamente", " .::Error
En la Operacion::." ,JOptionPane.ERROR_MESSAGE);
}
}
});
ventana.add(panel1);
ventana.setVisible(true);

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

Crear Archivo de Texto:


Usando Jtree para ver los archivos del Sistema Operativo

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);

File f=new File("/");


DefaultMutableTreeNode top=new DefaultMutableTreeNode(f);
populatenode(top, f);
raiz=new JTree(top);
DefaultTreeCellRenderer render= (DefaultTreeCellRenderer)raiz.getCellRenderer();
render.setLeafIcon(new ImageIcon("/home/luis/file-manager.png"));
raiz.getSelectionModel().addTreeSelectionListener(this);

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();
}

private boolean populatenode(DefaultMutableTreeNode node,File f){


node.removeAllChildren();
return populatenode(node,f,2);
}
private boolean populatenode(DefaultMutableTreeNode node,File f,int depth){
File[] archivos=f.listFiles(new FileFilter(){
public boolean accept(File pathname){
return pathname.isDirectory();
}
});

if (archivos != null && depth > 0) {


for (int i = 0; i < archivos.length; i++) {
DefaultMutableTreeNode curr=
new DefaultMutableTreeNode(archivos[i]);

populatenode(curr,archivos[i],depth -1);
node.add(curr);
}

}
return true;
}
public void valueChanged(TreeSelectionEvent e) {

DefaultMutableTreeNode node=(DefaultMutableTreeNode)
raiz.getLastSelectedPathComponent();

if (node == null) return;

File f=(File) node.getUserObject();


File[] archivos=f.listFiles(new FileFilter(){
public boolean accept(File pathname){
return pathname.isFile();
}
});

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();

if (node == null) return;

setCursor(new Cursor(Cursor.WAIT_CURSOR));

File f=(File) node.getUserObject();


populatenode(node,f);

JTree arbol=(JTree) e.getSource();


DefaultTreeModel model=(DefaultTreeModel) arbol.getModel();
model.nodeStructureChanged(node);

setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

También podría gustarte