Java - Como imprimo 16 lineas de texto???

 
Vista:

Como imprimo 16 lineas de texto???

Publicado por Alvaro (1 intervención) el 22/11/2006 15:18:13
/*
HOLA, COMO ÑPUEDO IMPRIMIR EN PANTALLA 16 LINES Y PRESIONAR UN BOTON O UNA TECLA SEGUIR MOSTRANDO LAS SIGUIENTES 16 LINEAS HASTA TERMINAR DE MOSTRAR TODO.
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class ProyectoFinal
{
public static void main(String[] args)
{
F F1 = new F("Hexaminator");
if (args.length == 1)
{
File FL1 = new File(args[0]);
Archivo A1 = new Archivo(args[0], F1.TA1, F1.TA2, F1.LB2, F1.LB3, FL1);
A1.Leer();
}
}
}

class F extends Frame
{
Label LB1, LB2, LB3;
TextArea TA1, TA2;
Panel P1, P2;
MenuItem MI1, MI2, MI3;
Menu M1, M2;
MenuBar MB1;
JFileChooser FC1 = new JFileChooser();
int Valor;
File FL1;
Long Tamano;

public F(String Titulo)
{
super(Titulo);
this.setLayout(new BorderLayout());

MI1 = new MenuItem("Abrir");
MI1.addActionListener(new ALM1());
MI2 = new MenuItem("Salir");
MI2.addActionListener(new ALM1());

M1 = new Menu("Archivo");
M1.add(MI1);
M1.addSeparator();
M1.add(MI2);

MI3 = new MenuItem("Sobre Hexaminator");
MI3.addActionListener(new ALM2());

M2 = new Menu("Ayuda");
M2.add(MI3);

MB1 = new MenuBar();
MB1.add(M1);
MB1.add(M2);

P1 = new Panel();
P1.setLayout(new BorderLayout());

LB2 = new Label(" Archivo: ");
LB3 = new Label(" Tamaño: ");

P1.add("West", LB2);
P1.add("East", LB3);

P2 = new Panel();

TA1 = new TextArea(34,66);
TA2 = new TextArea(34,40);

P2.add(TA1);
P2.add(TA2);

this.setMenuBar(MB1);
this.add("South", P1);
this.add("Center", P2);

this.addWindowListener(new WAE());
this.setResizable(false);
this.setSize(800, 600);
this.show();
}

class ALM1 implements ActionListener
{

public void actionPerformed(ActionEvent evt)
{
// getActionCommand(): TERNA UN STRING.
// compareTo("Salir"): COMPARA EL STRING ANTERIOR CON "SALIR"
// SIN SON IGUALES RETORNA UN 0
if (evt.getActionCommand().compareTo("Salir")==0)
{
// SALIR DEL PROGRAMA
System.exit(0);
}
else
{
if (evt.getActionCommand().compareTo("Abrir")==0)
{
// ABRIR ARCHIVO.
Valor = FC1.showOpenDialog(FC1);

if (Valor == JFileChooser.APPROVE_OPTION)
{
// ARCHIVO
FL1 = FC1.getSelectedFile();
// TRABAJAR CON ARCHIVO
Archivo A1 = new Archivo(FL1.getPath(), TA1, TA2, LB2, LB3, FL1);
A1.Leer();

}
else
{
LB2.setText(" Archivo: No se pudo abrir");
}

}
}
}
}

class ALM2 implements ActionListener
{

public void actionPerformed(ActionEvent evt)
{
if (evt.getActionCommand().compareTo("Sobre Hexaminator")==0)
{
// MOSTRAR INFORMACION SOBRE CREADORES
About F2 = new About(F.this);
}
}
}

class WAE extends WindowAdapter
{
public void windowClosing(WindowEvent evt)
{
// SALIR DEL PROGRAMA
System.exit(0);
}
}

}

class About extends Dialog
{
Label LB1, LB2, LB3;
Button B1;
Panel P1, P2;

public About(F F7)
{
super(F7, "Sobre Hexaminator", true);
this.setLayout(new BorderLayout());

LB1 = new Label(" Autores: Gabriel Estrada C. y Alvaro Salgado C.");
LB2 = new Label(" Versión: 1.0");
LB3 = new Label(" Lenguaje: JAVA");

P1 = new Panel();
P1.setLayout(new GridLayout(3,2));
P1.add(LB1);
P1.add(LB2);
P1.add(LB3);

B1 = new Button("Aceptar");
B1.addActionListener(new ALA());

P2 = new Panel();
P2.add(B1);

this.add("Center", P1);
this.add("South", P2);
this.setResizable(false);
this.pack();
this.show();
}

class ALA implements ActionListener
{

public void actionPerformed(ActionEvent evt)
{
// OCULTAR DIALOG
About.this.setVisible(false);
}

}
}

class Archivo
{

String Ruta;
TextArea TA1, TA2;
Label LB2, LB3;
File FL1;
Long Tamano;

Archivo(String Ruta, TextArea TA1, TextArea TA2, Label LB2, Label LB3, File FL1)
{
this.Ruta = Ruta;
this.TA1 = TA1;
this.TA2 = TA2;
this.LB2 = LB2;
this.LB3 = LB3;
this.FL1 = FL1;
}

void Leer()
{
try
{

FileReader FR = new FileReader(Ruta);
BufferedReader IN = new BufferedReader(FR);
int L;
int CT1 = 0;
int CT2 = 0;
String C = new String();

// ARCHIVO Y TAMAÑO
LB2.setText(" Archivo: " + FL1.getName());
LB3.setText("Tamano: " + Tamano.toString(FL1.length()/1024) + " Kb");

while((L = IN.read()) != -1)
{
if (CT2 < 8)
{
if (CT1 < 16)
{
if ((L >= 0 && L <= 31) || (L >= 128 && L <= 255))
{
TA2.append(".");
}
else
{
//C = C.toUpperCase((char)L + "");
TA2.append((char)L + "");
}

C=Integer.toHexString(L);

switch(C.length())
{
case 1:
TA1.append("0" + C.toUpperCase());
break;
case 2:
TA1.append("" + C.toUpperCase());
break;
}

if (CT1 < 15)
{
TA1.append(" ");
}

CT1 = CT1 + 1;
}
else
{
CT1 = 0;
TA1.append("\n");
TA2.append("\n");
}

CT2 = CT2 + 1;
}
else
{
CT2 = 0;
// DISPARADOR
}
}
}
catch(IOException e)
{
LB2.setText("Archivo: "+e.getMessage());
}
}
}

// FALTA -> 1. LIMPIAR TEXTAREA.
// 2. DETENER DESPUES DE IMPRIMIR 16 LINEAS (XX).
// 3. LB2 y LB3: MOSTRAR CONTENIDO COMPLETO (X).
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Como imprimo 16 lineas de texto???

Publicado por yo (12 intervenciones) el 27/11/2006 12:22:28
Con un bucle que escriba las lineas y un escuchador para el boton o la tecla.
Cuando se pulse el boton o la tecla ir al bucle.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar