Your SlideShare is downloading. ×
Semana 12   interfaces gráficas de usuario
Semana 12   interfaces gráficas de usuario
Semana 12   interfaces gráficas de usuario
Semana 12   interfaces gráficas de usuario
Semana 12   interfaces gráficas de usuario
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Semana 12 interfaces gráficas de usuario

468

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
468
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CLASE PANTALLA<br />package org.proyecto;<br />import java.awt.*;<br />import java.awt.event.*;<br />import java.io.*;<br />import javax.swing.*;<br />import java.util.Vector;<br />public class Pantalla extends JFrame{<br />StringBuffer lee1;<br />String [] recibe;<br />Vector vector;<br />public Pantalla(){<br />// Creando los objetos del menú.<br />menubarra = new MenuBar();<br />menu1 = new Menu();<br />menu2 = new Menu();<br />about = new MenuItem();<br />salir = new MenuItem(); <br />material1 = new MenuItem();<br /> <br />// Creando objetos para los botones de Eliminar y Reservar.<br />eliminar = new Button("Eliminar");<br />etiqueta = new Label();<br />boton2 = new Button("Reservar");<br /> <br />// Listado de libros y revistas.<br />lista = new List();<br />lista.setMultipleMode(false);<br />setTitle("Mi Biblioteca");<br />setResizable(false);<br /> <br />// Texto en los menús.<br />menu1.setLabel("Registro");<br />menu2.setLabel("Ayuda");<br />about.setLabel("Acerca de...");<br />salir.setLabel("Salir");<br /> material1.setLabel("Agregar Material");<br /> <br /> // Ir a las ventanas de los menús.<br /> menu1.add(material1);<br /> menu2.add(about);<br /> menu2.add(salir);<br /> menubarra.add(menu1);<br /> menubarra.add(menu2);<br /> <br /> // Muestra la barra del menú.<br /> // También se definen los tamaños de los botones y etiquetas.<br /> setMenuBar(menubarra);<br /> eliminar.setBounds(100,380,100,30);<br />getContentPane().add(eliminar);<br />etiqueta.setBounds(200,25,200,30);<br />etiqueta.setText("Listado de libros y/o revistas:");<br />getContentPane().add(etiqueta);<br />boton2.setBounds(400,380,100,30);<br />getContentPane().add(boton2);<br />lista.setBounds(40,60,520,250);<br />getContentPane().add(lista);<br />contra = new TextField();<br />contra.setBounds(400,430,100,25);<br />getContentPane().add(contra);<br />labe = new Label("ID:");<br />labe.setBounds(370,430,30,25);<br />getContentPane().add(labe);<br />// Con addWindowListener se registra un receptor de eventos en la ventana. <br />addWindowListener(new WindowAdapter() {<br />public void windowClosing(WindowEvent evt) {<br />exitForm(evt);<br /> }<br />});<br />// Con el addActionListener se asocia el evento del clic del mouse con el item del menú.<br />salir.addActionListener(new java.awt.event.ActionListener(){<br />public void actionPerformed(java.awt.event.ActionEvent evt){<br />salida(evt);<br />}<br />});<br />material1.addActionListener(new java.awt.event.ActionListener(){<br />public void actionPerformed(java.awt.event.ActionEvent evt){<br />materia1(evt);<br />}<br />});<br />boton2.addActionListener(new java.awt.event.ActionListener(){<br />public void actionPerformed(java.awt.event.ActionEvent evt){<br />reserva(evt);<br />}<br />});<br />eliminar.addActionListener(new java.awt.event.ActionListener(){<br />public void actionPerformed(java.awt.event.ActionEvent evt){<br />elimina(evt);<br />}<br />});<br />// Aquí se crea la ventana principal con sus dimensiones y color de fondo.<br />// También se crea un archivo para almacenar los datos de los préstamos.<br />setBackground((java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.background"));<br />Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();<br />setSize(new java.awt.Dimension(600, 550));<br />setLocation((screenSize.width-786)/2,(screenSize.height-550)/2);<br />getContentPane().setLayout(null);<br />setVisible(true);<br />lugar1="C:tareaarchivosmaterial.datos";<br />lee1 = readFile(lugar1);<br />datos1 = lee1.toString();<br />separaString1(datos1);<br />} // Fin del public pantalla. <br /> <br />public void separaString1(String cadena){<br />String eval,valor;<br />int i,j=0;<br />for(i=0;i<cadena.length();i++){<br />eval = cadena.substring(i,i+1);<br />if(eval.equals(",")){<br />valor = cadena.substring(j,i+1);<br />j=i+1;<br />lista.addItem(valor);<br />}<br />}<br />}<br />// En el método main creamos la pantalla.<br />public static void main (String [] args){<br />new Pantalla();<br />}<br />// Aquí se guarda en el archivo la información y salimos del sistema.<br />private void salida(java.awt.event.ActionEvent evt){<br />String nuevo="";<br /> <br />for(int i=0;i<lista.getItemCount();i++){<br />nuevo = nuevo + lista.getItem(i);<br />}<br />saveFile(lugar1,nuevo,false);<br />System.exit(0);<br />}<br />// Salimos de la pantalla<br />private void exitForm(WindowEvent evt){<br />String nuevo="";<br /> <br />for(int i=0;i<lista.getItemCount();i++){<br />nuevo = nuevo + lista.getItem(i);<br />}<br />saveFile(lugar1,nuevo,false);<br />System.exit(0);<br />}<br />// Método para reservar o prestar el libro o revista.<br />private void reserva(ActionEvent evt){<br />if(contra.getText().equals("")){<br />JOptionPane.showMessageDialog(getParent(),"Debe digitar el ID");<br />}<br />else{<br />String nuevo;<br />String linea = lista.getSelectedItem();<br />int i = lista.getSelectedIndex();<br />String valida = linea.substring(linea.length()-6,linea.length()-1);<br />if(valida.equals("LIBRE")){<br />nuevo = linea.substring(0,linea.length()-6)+contra.getText()+",";<br />contra.setText("");<br />lista.replaceItem(nuevo,i);<br />}<br />else{<br />JOptionPane.showMessageDialog(getParent(),"Ese material ya esta reservado");<br />}<br />}<br />}<br />// Método para eliminar de la lista los libros o revistas.<br />private void elimina(ActionEvent evt){<br />String linea = lista.getSelectedItem();<br />lista.remove(linea);<br />}<br />// Ventana para agregar un libro o revista.<br />private void materia1(java.awt.event.ActionEvent evt){<br />dialogo2 = new Dialog(this);<br />texto21 = new TextField();<br />texto22 = new TextField();<br />texto23 = new TextField();<br />label21 = new Label("Tipo:");<br />label22 = new Label("Codigo:");<br />label23 = new Label("Nombre:");<br />label24 = new Label("Autor:");<br />ok32 = new Button("Aceptar");<br />choice2 = new Choice();<br />dialogo2.setTitle("Agregar Material");<br />dialogo2.setLocation(250,150);<br />dialogo2.setSize(350,400);<br />dialogo2.setLayout(null);<br />dialogo2.show();<br />texto21.setBounds(150,150,150,20);<br />texto22.setBounds(150,180,150,20);<br />texto23.setBounds(150,210,150,20);<br />label21.setBounds(70,50,60,20);<br />label22.setBounds(70,150,60,20);<br />label23.setBounds(70,180,60,20);<br />label24.setBounds(70,210,60,20);<br />ok32.setBounds(125,320,100,30);<br />choice2.setBounds(150,50,150,25);<br />choice2.addItem("libro");<br />choice2.addItem("revista");<br />dialogo2.add(texto21);<br />dialogo2.add(texto22);<br />dialogo2.add(texto23);<br />dialogo2.add(label21);<br />dialogo2.add(label22);<br />dialogo2.add(label23);<br />dialogo2.add(label24);<br />dialogo2.add(ok32);<br />dialogo2.add(choice2);<br /> <br />// Con addWindowListener se registra un receptor de eventos en la ventana. <br />dialogo2.addWindowListener(new java.awt.event.WindowAdapter(){<br />public void windowClosing(java.awt.event.WindowEvent evt){<br />dialogo2.setVisible(false);<br /> dialogo2.dispose();<br /> }<br /> });<br /> <br />// Con el addActionListener se asocia el evento del clic del mouse con el item del menú.<br />ok32.addActionListener(new ActionListener(){<br />public void actionPerformed(ActionEvent e){<br />String material = choice2.getSelectedItem()+";"+texto21.getText()+";"+texto23.getText()+";"+texto22.getText()+";"+"LIBRE"+",";<br />dialogo2.setVisible(false);<br />dialogo2.dispose();<br />lista.addItem(material);<br />}<br />});<br />} // Fin de la ventana agregar material.<br />// Método para abrir el archivo con la información.<br />public StringBuffer readFile(String filename){<br />StringBuffer sb = new StringBuffer();<br />try{<br />File file = new File(filename);<br />String line = null;<br />BufferedReader br = new BufferedReader(new FileReader(file));<br />while ((line = br.readLine()) != null){<br />sb.append(line);<br />}<br />br.close();<br />}<br />catch (FileNotFoundException fnfe){}<br />catch (IOException ioe){}<br />return sb;<br />}<br />// Método para guardar el archivo con la información.<br />public void saveFile(String filename, String dataToWrite, boolean append){<br />try{<br />FileWriter fw = new FileWriter(filename, append);<br />fw.write(dataToWrite);<br />fw.close();<br />}<br />catch (IOException ioe){}<br />}<br />public String replaceValues (String path, String [] valuesToSearch, String [] valuesToReplace){<br />String line;<br />StringBuffer textComplete = new StringBuffer();<br />String tempText = "";<br />try{<br />BufferedReader br = new BufferedReader(new FileReader(path));<br />while ((line = br.readLine()) != null){<br />textComplete.append(line);<br />}<br />br.close();<br />}<br />catch (FileNotFoundException fnfe){}<br />catch (IOException ioe){}<br />for (int i=0; i<valuesToSearch.length; i++){<br />int position = textComplete.indexOf(valuesToSearch[i]);<br />if (position>0 ){<br />tempText = textComplete.substring(0,position);<br />tempText = tempText + valuesToReplace[i] + textComplete.substring(position+valuesToSearch[i].length(),textComplete.length());<br />textComplete = new StringBuffer(tempText);<br />}<br />}<br />return tempText;<br />}<br /> // Declaración de variables.<br />private Menu menu1;<br /> private Menu menu2;<br /> private MenuBar menubarra;<br /> private MenuItem about;<br /> private MenuItem salir;<br /> private MenuItem material1;<br /> private Button eliminar;<br /> private Label etiqueta;<br /> private Button boton2;<br /> private Dialog dialogo2;<br /> private TextField texto21;<br /> private TextField texto22;<br /> private TextField texto23;<br /> private Label label21;<br /> private Label label22;<br /> private Label label23;<br /> private Label label24;<br /> private Button ok32;<br /> private Choice choice2;<br /> private List lista;<br /> private String lugar1,datos1;<br /> private TextField contra;<br /> private Label labe;<br />} // Fin de la clase Pantalla.<br />

×