Vous êtes sur la page 1sur 13

UNIDAD 7: JAVA REGISTROS Y ARCHIVOS SECUENCIALES

JAVA TEMA 2: JAVA REGISTROS


Ya se ha visto como variables simples pueden almacenar una sola pieza de
informacin y como arreglos pueden almacenar un conjunto de ellas del
mismo tipo y al mismo tiempo, estos dos mecanismos pueden manejar una
gran variedad de situaciones, pero a menudo se necesita trabajar sobre datos
de diversos tipos, en este caso ni variables escalares ni arreglos son
adecuados.
Para resolver estos problemas los lenguajes de programacin proveen de un
tipo de dato especial llamado registros.
Un registro es una variable especial que tiene la capacidad de almacenar datos
de diferentes tipos.
Sin embargo JAVA, usa en su lugar una CLASE.
Este metodo tiene la ventaja de que ademas de incluir los campos
tradicionales de un registro (en forma de atributos), tambien puede incorporar
una serie de metodos que permiten procesar de manera mas facil los campos o
atributos de la clase.
Ejemplo;
class alumno{
void alumno(){};
static String nombre= new String();
static int edad;
void inicializar(){
alumno.nombre=pepe el toro;
alumno.edad=18; };
void desplegar(){
System.out.println(alumno.nombre);
System.out.println(alumno.edad);

};
} termina la clase
Programa ejemplo;
import java.io.*;
class prog33{
public static void main(String[] args) {
alumno.inicializar();
alumno.desplegar();
} // cierra main
} // cierra clase
class alumno{
void alumno(){};
static String nombre= new String();
static int edad;
static void inicializar(){
alumno.nombre="pepe el toro";
alumno.edad=18; };
static void desplegar(){
System.out.println(alumno.nombre);
System.out.println(alumno.edad);
};
} // temina la clase

Format formatos[]=new Format[2]; formatos[0]=new AudioFormat(AudioFormat.IMA4);


formatos[1]=new VideoFormat(VideoFormat.CINEPAK); FileTypeDescriptor tipo=new
FileTypeDescriptor(FileTypeDescriptor.QUICKTIME); ProcessorModel modelo=new
ProcessorModel(formatos,tipo);
try { p=Manager.createRealizedProcessor(modelo);
} catch (NoProcessorException e) { e.printStackTrace();
} catch (CannotRealizeException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
}
DataSource entrada=p.getDataOutput(); MediaLocator destino=new
MediaLocator(file://+file.getAbsolutePath());
DataSink salida=null;
try {
salida=Manager.createDataSink(entrada, destino); salida.open();
} catch (NoDataSinkException e) { e.printStackTrace(); } catch (SecurityException e)
{ e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
}
try {
salida.start();
} catch (IOException e) { e.printStackTrace();
}
try { Thread.sleep(2000);
} catch (InterruptedException e) { e.printStackTrace();
}
p.start(); panelPrincipal.add(p.getVisualComponent(),BorderLayout.CENTER); panelPrincipal.updateUI();
}

camara ip online echa en java

bueno aqui les dejo el codigo de camara ip en java el cual puedes ver en tiempo real lo que pasa
en el mundo, tiene diferentes ips y a la cual ustedes pueden aadir extras para ver la camarita ,
tambien pueden ingresar el tiempo en que va a refrescar la camara, y ademas comoe xtra
acomodar el tamao de la imagen de la camara si mas ancho mas alto.
bueno vamos para el codigo primero obvio creamos un proyecto y luego creamos un pakete yo lo
voy a llamar camaraonline dentro de ese pakete creamos una clase llamada dibujartodo y en esa
clase ponemos el siguiente codigo:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package camaraonline;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ImageIcon;

import javax.swing.JComponent;
import javax.swing.JPanel;
/**
*
* @author andres2288
*/
public class dibujartodo extends JComponent{

private Dimension d = new


Dimension(640,480);//352,240//640,480//[352, 286]
JPanel pa=null;
private int x1=400;
private int y1=400;
private int posx=0;
private int posy=0;
private int tiempo=2000;
private String mundo="http://123.220.250.252/";
private

Image snap= new

ImageIcon( getClass().getResource("/livecam/snap.jpg") ).getImage() ;


private String Axis="axis-cgi/jpg/image.cgi?
resolution="+d.width+"x"+d.height+"";
public dibujartodo(JComponent contenedor,JPanel p){
super();
this.setBounds(0, 0,contenedor.getWidth() ,
contenedor.getHeight());
contenedor.add(this);
/*

d.width=358;
d.height=500;*/

this.pa=p;
}

@Override
public void paint(Graphics g){
super.paint(g);
//

getGrafo().paint(g);
try {
//libera lo que se halla almacenado en el buffer
snap.flush();
//carga la nueva imagen
/* ----------------- */
//Odate street
//snap = new ImageIcon(new URL("http://www.odate-

houjinkai.or.jp/snap.jpg")).getImage();
//tienda japon
//snap = new ImageIcon(new
URL("http://www.hifido.co.jp/camera/osu.jpg")).getImage();
//barberia japon
//snap = new ImageIcon(new URL("http://www.salonnet.org/realtime100.jpg")).getImage();
//Camaras AXIS
//aeropuerto de rochester
//snap = new ImageIcon(new
URL("http://84.92.80.192:8081/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();
//snap = new ImageIcon(new
URL("http://206.127.116.63/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();
//snap = new ImageIcon(new URL("http://62.42.19.194/axiscgi/jpg/image.cgi?resolution=352x240")).getImage();
//tokio
//snap = new ImageIcon(new
URL("http://221.255.120.171/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();

//restorant
//snap = new ImageIcon(new URL( "http://80.25.78.169/" +
this.Axis )).getImage();
//calle
System.out.println(""+x1+"-->"+y1+"\n"+"pox"+getPosx()
+"posy"+getPosy()+"\n"+pa.getY());
if(mundo.indexOf("jpg")!=-1){
snap = new ImageIcon(new URL(mundo)).getImage();
}
else{
snap = new ImageIcon(new URL( mundo +
this.Axis )).getImage();
}
/* ----------------- */
} catch (MalformedURLException ex) {
}
g.drawImage(snap, 0, 0, x1, y1,

null);

}
//metodo que descarga una imagen de internet y la coloca en
el JLabel
private void Cargar_Imagen(){
try {
//libera lo que se halla almacenado en el buffer
snap.flush();
//carga la nueva imagen
/* ----------------- */
//Odate street
//snap = new ImageIcon(new URL("http://www.odatehoujinkai.or.jp/snap.jpg")).getImage();

//tienda japon
//snap = new ImageIcon(new
URL("http://www.hifido.co.jp/camera/osu.jpg")).getImage();
//barberia japon
//snap = new ImageIcon(new URL("http://www.salonnet.org/realtime100.jpg")).getImage();
//Camaras AXIS
//aeropuerto de rochester
//snap = new ImageIcon(new
URL("http://84.92.80.192:8081/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();
//snap = new ImageIcon(new
URL("http://206.127.116.63/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();
//snap = new ImageIcon(new URL("http://62.42.19.194/axiscgi/jpg/image.cgi?resolution=352x240")).getImage();
//tokio
//snap = new ImageIcon(new
URL("http://221.255.120.171/axis-cgi/jpg/image.cgi?
resolution=352x240")).getImage();
//restorant
//snap = new ImageIcon(new URL( "http://80.25.78.169/" +
this.Axis )).getImage();
//calle
snap = new ImageIcon(new URL( "http://123.220.250.252/" +
this.Axis )).getImage();
/* ----------------- */
} catch (MalformedURLException ex) {
}

private Thread hilo1 = new Thread()


{

@Override
public void run()
{
try
{
while(true)
{

//aumentamos dependiendo
pa.repaint();
hilo1.sleep(getTiempo());
System.out.println(""+tiempo);
}
} catch (java.lang.InterruptedException ie)
{ System.out.println(ie.getMessage()); }
}
};

public void aumentay(){


y1+=+15;
}
/**
* @return the hilo1

*/
public Thread getHilo1() {
return hilo1;
}
/**
* @param hilo1 the hilo1 to set
*/
public void setHilo1(Thread hilo1) {
this.hilo1 = hilo1;
}
/**
* @return the tiempo
*/
public int getTiempo() {
return tiempo;
}
/**
* @param tiempo the tiempo to set
*/
public void setTiempo(int tiempo) {
this.tiempo = tiempo;
}
/**
* @return the mundo
*/
public String getMundo() {
return mundo;
}
/**

* @param mundo the mundo to set


*/
public void setMundo(String mundo) {
this.mundo = mundo;
}
/**
* @return the x1
*/
public int getX1() {
return x1;
}
/**
* @param x1 the x1 to set
*/
public void setX1(int x1) {
this.x1 = x1;
}

/**
* @return the posx
*/
public int getPosx() {
return posx;
}
/**
* @param posx the posx to set
*/
public void setPosx(int posx) {
this.posx = posx;
}

/**
* @return the posy
*/
public int getPosy() {
return posy;
}
/**
* @param posy the posy to set
*/
public void setPosy(int posy) {
this.posy = posy;
}
/**
* @return the y1
*/
public int getY1() {
return y1;
}
/**
* @param y1 the y1 to set
*/
public void setY1(int y1) {
this.y1 = y1;
}
}

luego creamos un formulario Jframe como lo entiendan llamado visual ponemos las siguientes
variables en ese formulario.

DefaultComboBoxModel dc1 = new DefaultComboBoxModel();


private dibujartodo contenedor;
int sleep=2000;
luego en el construtor ponemos el siguiente codigo:

super("por andres2288");
initComponents();
contenedor= new dibujartodo(panel1,panel1);
dc1.addElement("http://123.220.250.252/");
dc1.addElement("http://www.odatehoujinkai.or.jp/snap.jpg");
dc1.addElement("http://www.hifido.co.jp/camera/osu.jpg");
dc1.addElement("http://www.salon-net.org/realtime100.jpg");
dc1.addElement("http://84.92.80.192:8081/axiscgi/jpg/image.cgi?resolution=352x240");
dc1.addElement("http://206.127.116.63/axiscgi/jpg/image.cgi?resolution=352x240");
dc1.addElement("http://62.42.19.194/axis-cgi/jpg/image.cgi?
resolution=352x240");
dc1.addElement("http://221.255.120.171/axiscgi/jpg/image.cgi?resolution=352x240");
dc1.addElement("http://128.97.43.214/");
creamos un boton llamado play y cuando le den click va a ejecutar el siguiente codigo

if(!contenedor.getHilo1().isAlive()){
contenedor.getHilo1().start();
}

else{
contenedor.getHilo1().resume();
}
bueno ustedes le agregan lo otro ya que es facil y eso es todo.
aqui les dejo el .jar descarga

Vous aimerez peut-être aussi