/* Consultas de Libros por TITULO.
el programa lee el fichero Libros.dat, (he tenido que llamarlo libros.txt,
por que el servidor no permite el .DAT)que contiene los libros y sus datos,y
separa la información de manera que la busqueda de libros disponibles
pueda realizarse por palabras de titulo o por temas.
*/
// Realizado en Diciembre de 1996 por:
// Jose Carreres
// Javier Magdalena
// enrique Minguet
import java.awt.*;
import java.applet.*;
import java.io.StreamTokenizer;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.*;
//Cargamos las clases justas que vamos a utilizar.
public class ConsultasLibros extends Applet {
// Consultas de Libros, applet.
public CardLayout layoutManager;
public CLASSPprincipal Pprincipal;
public CLASSListalibros Listalibros;
public static Hashtable htconsultas;
public void init()
{
layoutManager = new CardLayout();
setLayout(layoutManager);
htconsultas = new Hashtable();
Llenarhtconsultas();
// Crea una instancia de nuestra clase panel
Pprincipal = new CLASSPprincipal(this, this);
add("Pprincipal", Pprincipal);
}
public String getAppletInfo()
{
return "Consulta de libros remota.";
}
public boolean handleEvent(Event e)
{
if (e.id == Event.WINDOW_DESTROY)
{
System.exit(0);
}
return false;
}
void Llenarhtconsultas()
/* ***************************************************************
procedimiento que lee el fichero y rellena la tabla Hash con todos los
datos de los libros que aparecen en él.
**************************************************************** */
/* Obiene el documento Libros.dat de la red y lo vuelca en una tabla Hash
"htconsultas", para agilizar las operaciones de busqueda.
*/
{
InputStream is = null;
URL urlPhtitulo;
try
{
urlPhtitulo = new URL(getDocumentBase(), "Libros.dat");
//obtiene la direccion base, donde estará el documento.
try
{
is = urlPhtitulo.openStream();
StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(is, 4000));
//caracteres que reconocerá el StreamToke.
st.eolIsSignificant(true);
st.commentChar('#');
st.slashSlashComments(true);
st.whitespaceChars('%', '%');
st.wordChars('(', ')');
st.wordChars(',', ',');
st.wordChars('-', '-');
st.wordChars('.', '.');
st.wordChars(':', ':');
st.wordChars('$', '$');
st.wordChars('-', 'z');
st.wordChars(' ', ' ');
st.wordChars('0', '9');
htconsultas.clear();
scan:
while (true)
switch (st.nextToken())
{
case StreamTokenizer.TT_EOF:
break scan;
default:
break;
case StreamTokenizer.TT_WORD:
String strRecord = st.sval;
String strValue = "";
st.nextToken();
while (st.ttype != StreamTokenizer.TT_EOL &&
st.ttype != StreamTokenizer.TT_EOF)
{
if (st.ttype == StreamTokenizer.TT_WORD)
{
strValue = strValue + st.sval;
}
//aunque no se dará el caso en que el token
//sea numerico, esta es una clase que podriamos
//reutilizar.
else
if (st.ttype == StreamTokenizer.TT_NUMBER)
{
strValue = strValue + String.valueOf(st.nval).toString();
}
st.nextToken();
}
/*el primer campo, titulo,será la clave.
los siguientes campos, los coloca en un string, separandolos por el signo $
de forma que el la tabla Hass, inserta la clave, y el string.*/
htconsultas.put(strRecord, strValue);
break;
}
is.close();
}
catch(Exception e)
{
String mensage = e.toString();
showStatus("Excepción ..." + mensage);
}
}
catch (MalformedURLException e)
{
String mensage = e.toString();
showStatus("Excepción ..." + mensage);
}
}
public static void main(String args[])
{
ConsultasLibros consultaslibros = new ConsultasLibros();
consultaslibros.init();
consultaslibros.start();
}
}
/**************************************************************************
Definición del contenedor de la interfaz grafica.
(pantalla principal (panel))
**************************************************************************/
class CLASSPprincipal extends CLASSPanel
{
public CLASSCEtemas CEtemas;
public CLASSEdatos Edatos;
public CLASSETitulo ETitulo;
public CLASSCTtitulo CTtitulo;
public CLASSEisbn Eisbn;
public CLASSCTisbn CTisbn;
public CLASSEautor Eautor;
public CLASSCTautor CTautor;
public CLASSEeditorial Eeditorial;
public CLASSEtema Etema;
public CLASSCTeditorial CTeditorial;
public CLASSCTtema CTtema;
public CLASSBpalabratitulo Bpalabratitulo;
public CLASSBnuevabusqueda Bnuevabusqueda;
public CLASSBtema Btema;
public CLASSCTpalabratitulo CTpalabratitulo;
public CLASSListalibros Listalibros;
public ConsultasLibros applet;
public ConsultasLibros parent;
CLASSPprincipal(ConsultasLibros app, ConsultasLibros aParent)
{
applet = app;
parent = aParent;
Edatos = new CLASSEdatos(applet, this);
ETitulo = new CLASSETitulo(applet, this);
CTtitulo = new CLASSCTtitulo(applet, this);
Eisbn = new CLASSEisbn(applet, this);
CTisbn = new CLASSCTisbn(applet, this);
Eautor = new CLASSEautor(applet, this);
CTautor = new CLASSCTautor(applet, this);
Eeditorial = new CLASSEeditorial(applet, this);
CTeditorial = new CLASSCTeditorial(applet, this);
Etema = new CLASSEtema(applet, this);
CTtema = new CLASSCTtema(applet, this);
Bpalabratitulo = new CLASSBpalabratitulo(applet, this);
Bnuevabusqueda = new CLASSBnuevabusqueda(applet, this);
Btema = new CLASSBtema(applet, this);
CEtemas = new CLASSCEtemas(applet, this);
CTpalabratitulo = new CLASSCTpalabratitulo(applet, this);
Listalibros = new CLASSListalibros(applet, this);
// Crea el rotulo movil y lo añade al panel principal
CLASSCartelMovil cartelmovil = new CLASSCartelMovil(applet, this);
add(cartelmovil);
setLayout(null);
add(Eeditorial);
add(CTeditorial);
add(CTautor);
add(Eautor);
add(CTisbn);
add(Eisbn);
add(CTtitulo);
add(ETitulo);
add(Edatos);
add(Etema);
add(CTtema);
add(Listalibros);
add(CTpalabratitulo);
add(CEtemas);
add(Btema);
add(Bpalabratitulo);
add(Bnuevabusqueda);
setTop(0);
setLeft(0);
resize(800, 500);
setBackground(Color.white);
// inhabilitando los campos de texto.
CTisbn.setEditable(false);
CTtitulo.setEditable(false);
CTeditorial.setEditable(false);
CTtema.setEditable(false);
CTautor.setEditable(false);
LlenarCEtemas(CEtemas.choice);
}
public void LlenarCEtemas(Choice celeccion)
//Recorre toda la tabla Hash y muestra en la caja de eleccion "choice"
//de "CElecciontemas", todos los temas disponibles en el fichero,
//sin repetir ninguno.
{
String tema=new String();
String palabra=new String();
int numero=0;
int i=0;
boolean yaexiste=false;
for (Enumeration e = applet.htconsultas.elements();e.hasMoreElements();)
//recorro toda la tabla hash, e inserto el tema de cada uno de los
//libros en el "choice",sin repetir ninguno.
{
//en la talba hash, hay un solo string con todos los campos separados
//por un $,por lo tanto tengo que obtener el tema mediante un filtro.
palabra=e.nextElement().toString();
StringTokenizer filtro=new StringTokenizer(palabra,"$");
tema=filtro.nextToken();
//miro que no esté ya.
yaexiste=false;
numero=celeccion.countItems();
i=0;
if (numero>=1){
while ((i 5)
parent.counter = 0;
}
parent.repaint();
try
{
this.sleep(60);
} catch (InterruptedException e) {
};
}
}
CartelMovil_Kicker()
{
}
}
class CLASSCartelMovil extends CLASSPanel
{
public CartelMovil_Kicker Kicker;
public ConsultasLibros applet;
public Object parent;
int ANCHO_APPLET = 600;
int leftbanner = 0;
int bottombanner = 60;
int x1 = ANCHO_APPLET;
int counter = 0;
int[] stringwidths;
String[] wordarray = {"Consulta ", "de un archivo remoto", "via internet",
"Realizado en ", "Java ",
"Elija opción de busqueda"};
Color[] stringcolors = {Color.red, Color.yellow, Color.white, Color.cyan, Color.green, Color.orange};
FontMetrics fm = null;
CLASSCartelMovil(ConsultasLibros app, Object aParent)
{
applet = app;
parent = aParent;
Kicker = new CartelMovil_Kicker(applet, this);
setLayout(null);
setFont(new Font("Courier",0,8));
setTop(10);
setLeft(0);
setHeight(61);
setWidth(ANCHO_APPLET);
setForeground(Color.white);
setBackground(Color.black);
setFontName("TimesRoman");
setFontStyle(Font.BOLD);
setFontSize(22);
initialize();
}
public void paint(Graphics g)
{
//dibuja unas líneas a modo de marco para al banner
g.setColor(Color.white);
g.drawLine(leftbanner, 0, ANCHO_APPLET, 0);
g.drawLine(ANCHO_APPLET, bottombanner, leftbanner, bottombanner);
g.setColor(Color.lightGray);
g.drawLine(leftbanner, 2, ANCHO_APPLET, 2);
g.drawLine(ANCHO_APPLET, bottombanner-2, leftbanner, bottombanner-2);
// se encarga de desplazar el texto por el marco banner
g.clearRect(leftbanner+1, 4, 600, bottombanner-8);//140
g.clipRect(leftbanner+1, 4, 600, bottombanner-8);
g.setColor(stringcolors[counter]);
g.drawString(wordarray[counter], x1, 40);
}
public void initialize()
{
Kicker.start();
}
public void update(Graphics g)
{
paint(g);
}
CLASSCartelMovil()
{
}
}
class CLASSBoton extends Button
{
public ConsultasLibros applet;
public ConsultasLibros parent;
public CLASSBoton(Object app, Object aParent)
{
setFont(new Font("Courier",0,8));
setForeground(Color.black);
setBackground(Color.lightGray);
setFontName("Courier");
setFontStyle(Font.PLAIN);
}
public void refreshComponent()
{
// Refresca el componente despues de hacer alguna camio en el.
}
public void setTop(int aParam)
{
move(bounds().x, aParam);
}
public void setLeft(int aParam)
{
move(aParam, bounds().y);
}
public void setHeight(int aParam)
{
resize(bounds().width, aParam);
}
public void setWidth(int aParam)
{
resize(aParam, bounds().height);
}
public void setFontName(String aParam)
{
setFont(new Font(aParam, getFont().getStyle(), getFont().getSize()));
}
public void setFontStyle(int aParam)
{
setFont(new Font(getFont().getName(), aParam, getFont().getSize()));
}
public void setFontSize(int aParam)
{
setFont(new Font(getFont().getName(), getFont().getStyle(), aParam));
}
public CLASSBoton()
{
}
}
class CLASSEtiqueta extends Label
{
public ConsultasLibros applet;
public ConsultasLibros parent;
public CLASSEtiqueta(Object app, Object aParent)
{
setFont(new Font("Courier",0,8));
setAlignment(Label.LEFT);
setForeground(Color.black);
setBackground(Color.lightGray);
setFontName("Courier");
setFontStyle(Font.PLAIN);
setFontSize(15);
}
public void refreshComponent()
{
}
public void setTop(int aParam)
{
move(bounds().x, aParam);
}
public void setLeft(int aParam)
{
move(aParam, bounds().y);
}
public void setHeight(int aParam)
{
resize(bounds().width, aParam);
}
public void setWidth(int aParam)
{
resize(aParam, bounds().height);
}
public void setFontName(String aParam)
{
setFont(new Font(aParam, getFont().getStyle(), getFont().getSize()));
}
public void setFontStyle(int aParam)
{
setFont(new Font(getFont().getName(), aParam, getFont().getSize()));
}
public void setFontSize(int aParam)
{
setFont(new Font(getFont().getName(), getFont().getStyle(), aParam));
}
public CLASSEtiqueta()
{
}
}
class CLASSCTexto extends TextField
{
public ConsultasLibros applet;
public ConsultasLibros parent;
public CLASSCTexto(Object app, Object aParent)
{
setFont(new Font("Courier",0,8));
setForeground(Color.black);
setBackground(Color.white);
setFontName("Courier");
setFontStyle(Font.PLAIN);
setFontSize(15);
}
public void refreshComponent()
{
}
public void setTop(int aParam)
{
move(bounds().x, aParam);
}
public void setLeft(int aParam)
{
move(aParam, bounds().y);
}
public void setHeight(int aParam)
{
resize(bounds().width, aParam);
}
public void setWidth(int aParam)
{
resize(aParam, bounds().height);
}
public void setFontName(String aParam)
{
setFont(new Font(aParam, getFont().getStyle(), getFont().getSize()));
}
public void setFontStyle(int aParam)
{
setFont(new Font(getFont().getName(), aParam, getFont().getSize()));
}
public void setFontSize(int aParam)
{
setFont(new Font(getFont().getName(), getFont().getStyle(), aParam));
}
public CLASSCTexto()
{
}
}
class CLASSPanel extends Panel
{
public ConsultasLibros applet;
public ConsultasLibros parent;
public CLASSPanel(Object app, Object aParent)
{
setLayout(null);
setFont(new Font("Courier",0,8));
setForeground(Color.black);
setBackground(Color.lightGray);
setFontName("Courier");
setFontStyle(Font.PLAIN);
setFontSize(15);
}
public void refreshComponent()
{
}
public void setTop(int aParam)
{
move(bounds().x, aParam);
}
public void setLeft(int aParam)
{
move(aParam, bounds().y);
}
public void setHeight(int aParam)
{
resize(bounds().width, aParam);
}
public void setWidth(int aParam)
{
resize(aParam, bounds().height);
}
public void setFontName(String aParam)
{
setFont(new Font(aParam, getFont().getStyle(), getFont().getSize()));
}
public void setFontStyle(int aParam)
{
setFont(new Font(getFont().getName(), aParam, getFont().getSize()));
}
public void setFontSize(int aParam)
{
setFont(new Font(getFont().getName(), getFont().getStyle(), aParam));
}
public CLASSPanel()
{
}
}
               (
geocities.com/collegepark/quad)                   (
geocities.com/collegepark)