Foros del Web » Programación para mayores de 30 ;) » Programación General »

Alguien sabe llevar una aplicacion JAVA a APPLET ??????

Estas en el tema de Alguien sabe llevar una aplicacion JAVA a APPLET ?????? en el foro de Programación General en Foros del Web. Buenas, necesito que alguien me ayude. Tengo una aplicacion JAVA para control de camaras web y necesito llevar esa aplicacion a un APPLET para transmitir ...
  #1 (permalink)  
Antiguo 12/05/2008, 07:14
 
Fecha de Ingreso: febrero-2008
Mensajes: 2
Antigüedad: 16 años, 2 meses
Puntos: 0
Alguien sabe llevar una aplicacion JAVA a APPLET ??????

Buenas, necesito que alguien me ayude. Tengo una aplicacion JAVA para control de camaras web y necesito llevar esa aplicacion a un APPLET para transmitir via web las imagenes, pero no he podido llevar ese codigo a APPLET ..............Les voy a dejar el código Java de la aplicacion. Si alguien puede ayudarme por favor, se los agradezco. OJO: para que les funcione este código, tienen que instalar el JMF de SUN y en mi caso use una webcam Genius.

Codigo JAVA:

import javax.swing.*;
import javax.swing.event.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.util.*;
import javax.media.cdm.CaptureDeviceManager;
import javax.media.format.*;
import javax.media.protocol.*;
import java.awt.Image;
import java.util.Vector;
import java.util.Iterator;
import javax.imageio.*;
import java.io.*;
import java.awt.image.RenderedImage;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class captura extends JFrame implements ActionListener {

Player player = null;
JPanel panelCam,panelBotones,panelIm;
JButton boton = null;
JButton botonSalir = null;
JButton botonGuardar = null;
ImagePanel panelImagen = null;
Image img = null;
String dispositivo = "";

public void marco() throws Exception{
boton = new JButton();
boton.setText("Capturar");
boton.setSize(100,40);
boton.addActionListener(this);
botonGuardar = new JButton();
botonGuardar.setText("Guardar");
botonGuardar.setSize(100,40);
botonGuardar.addActionListener(this);
botonSalir = new JButton();
botonSalir.setText("Salir");
botonSalir.setSize(100,40);
botonSalir.addActionListener(this);
panelCam = new JPanel();
panelBotones = new JPanel();
panelIm = new JPanel();
panelImagen = new ImagePanel();
// para saber el dispositivo hacemos CaptureDeviceManager.getDeviceList() y devuelve un vector
// con los dispositivos instalados y reconocidos
CaptureDeviceInfo dev = CaptureDeviceManager.getDevice(dispositivo);
Format[] cfmts = dev.getFormats();
RGBFormat fmt = (RGBFormat)cfmts[4];
//obtengo el locator del dispositivo
MediaLocator loc = dev.getLocator();
player = Manager.createRealizedPlayer(loc);
player.start();
// esto lo saqué del foro jmf de Sun, hay que "parar un poco la aplicacion"
Thread.sleep(1000);
Component comp;

if ((comp = player.getVisualComponent()) != null)
{
// mostramos visualmente el reproductor
panelCam.add(comp,BorderLayout.CENTER);
this.getContentPane().add(panelCam,BorderLayout.NO RTH);

}

panelBotones.add(boton,BorderLayout.EAST);
panelBotones.add(botonGuardar,BorderLayout.CENTER) ;
panelBotones.add(botonSalir,BorderLayout.WEST);
this.getContentPane().add(panelBotones,BorderLayou t.CENTER);
panelIm.add(panelImagen,BorderLayout.CENTER);
this.getContentPane().add(panelIm,BorderLayout.SOU TH);
this.setSize(350,600);
this.setVisible(true);
}


public void seleccion() throws Exception{
ActionListener al = new ActionListener()
{
public void actionPerformed(ActionEvent evt){

dispositivo = evt.getActionCommand();
System.out.println("Dispositivo seleccionado: " + dispositivo);
}
};
Vector listaDispositivos = null;
//buscamos los dispositivos instalados
listaDispositivos = CaptureDeviceManager.getDeviceList();
JFrame marcoSel = new JFrame();
JPanel panelRB = new JPanel();
Iterator it = listaDispositivos.iterator();
while (it.hasNext()){
CaptureDeviceInfo cdi = (CaptureDeviceInfo)it.next();
panelRB.add(new JRadioButton(cdi.getName()));
}
ButtonGroup grupo = new ButtonGroup();
for (int i=0;i<panelRB.getComponentCount();i++){
grupo.add((JRadioButton)panelRB.getComponent(i));
JRadioButton boton = (JRadioButton)panelRB.getComponent(i);
boton.addActionListener(al);
}

marcoSel.getContentPane().add(panelRB,BorderLayout .CENTER);
marcoSel.setSize(300,300);
marcoSel.setVisible(true);
while (dispositivo.compareTo("") == 0){
//espera a que se haga la seleccion
}
marcoSel.dispose();
}

public void actionPerformed(ActionEvent e) {
String ac = e.getActionCommand();
if (ac.equals("captura")){
// capturamos la imagen
FrameGrabbingControl fgc = (FrameGrabbingControl)
player.getControl("javax.media.control.FrameGrabbi ngControl");
Buffer buf = fgc.grabFrame();
// creamos la imagen awt
BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
img = btoi.createImage(buf);
// la mostramos en nuestro panel
panelImagen.setImage(img);

}
if (ac.equals("guardar")){
if (img != null){
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
int result = chooser.showOpenDialog(null);
Integer i = new Integer(chooser.APPROVE_OPTION);
if (i != null) {

File archivo = chooser.getSelectedFile();
String imagen = archivo.getAbsolutePath();
System.out.println("imagen: "+imagen);
if (imagen.lastIndexOf(".") > 0){
imagen = imagen.substring(0,imagen.lastIndexOf("."));
}
imagen = imagen + ".JPG";
System.out.println("imagen:" + imagen);
File imagenArch = new File(imagen);
String formato = "JPEG";

try{
ImageIO.write((RenderedImage) img,formato,imagenArch);
}catch (IOException ioe){System.out.println("Error al guardar la imagen");}

}
}
else {
JFrame alerta = new JFrame();
alerta.setSize(300,100);
JPanel panelmsj = new JPanel();
JLabel msj = new JLabel();
msj.setText("Antes de guardar debes realizar una captura");
panelmsj.add(msj);
alerta.getContentPane().add(panelmsj);
alerta.setLocationRelativeTo(this);
alerta.setVisible(true);
alerta.setEnabled(true);
alerta.show();


}
}
if (ac.equals("salir")){
player.close();
System.exit(0);

}
}
public static void main(String[] args) throws Exception {
captura cap = new captura();
cap.seleccion();
cap.marco();
}
class ImagePanel extends Panel
{
public Image myimg = null;

public ImagePanel()
{
setLayout(null);
setSize(320,240);
}

public void setImage(Image img)
{
this.myimg = img;
repaint();
}

public void paint(Graphics g)
{
if (myimg != null)
{
g.drawImage(myimg, 0, 0, this);
}
}
}
}
  #2 (permalink)  
Antiguo 15/05/2008, 07:01
Avatar de dogduck  
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
Re: Alguien sabe llevar una aplicacion JAVA a APPLET ??????

http://www.forosdelweb.com/f45/conve...applet-391094/

salu2
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:35.