Retroceder   Foros del Web > Temas generales de computación > Programación

Respuesta
 
Herramientas Desplegado
Antiguo 12-may-2008, 07:14   #1 (permalink)
danieln21 ha deshabilitado el karma
 
Fecha de Ingreso: febrero-2008
Mensajes: 2
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 :-S..............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);
}
}
}
}
danieln21 está desconectado   Responder Citando
Antiguo 15-may-2008, 07:01   #2 (permalink)
dogduck está en el buen camino
 
Avatar de dogduck
 
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 1.892
Re: Alguien sabe llevar una aplicacion JAVA a APPLET ??????

convertir aplicacion en Applet

salu2
__________________
http://javcasta.es
dogduck está desconectado   Responder Citando
Respuesta
No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 05:22.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93