Incompatibilidade versão 6

1 resposta
grbabus

Fala minha gente sou novo aqui no forum, mas já estou lançando minha 1º bomba
e o seguinte, fiz um codigo a um tempinho atrás (em 2005), e ele funciona corretamente até na versão 5, do java agora quando instala, a versão 6, o bicho para tudo.

bom explicando meu codigo, ele faz o seguinte fica pegando imagem de um servidor, após escolher o combox, com a camera selecionada ele fica pedindo imagem ao servidor, num certo tempo pre determinado em nano segundos, isso até a versão 5, o que acontece na versão 6 e que ele simplesmente pede uma imagem e pronto não fica continuando o ciclo, bom ai vai o codigo para vcs me ajudarem.
//***********************************

import java.awt.<em>;

import java.applet.</em>;

import <a href="http://java.net">java.net</a>.<em>;

import <a href="http://java.io">java.io</a>.</em>;

import java.util.<em>;

import java.text.</em>;

import java.awt.event.*;
public class Cam1 extends java.applet.Applet implements Runnable

{

private Image 			imageAppArea,

imageAppArea1;
private MediaTracker 	mediaTracker_track1;

private Thread 	thread_This;			                // Thread for refreshing image
private boolean bServerTimeOut = false;   				// The server was disconnect the applet

private Choice choice_image  =  new Choice();					// Combo boxes for jpg names
private Choice choice_cam    =  new Choice();					// Combo boxes for camera choices

private Label label_Status = new Label("", Label.CENTER);

private String  strLink = null;
private boolean isImage = false;
private boolean isFirstTime = true;

private Image offscreenImg;
private Graphics offscreenG;

private String	strCodebase = null;

static long THREAD_MILLISENCONDS = 266;

@Override
public void init()
{
	String	strLista = null, strFundo = null, strLogo = null;
	URL urlAux;

	urlAux = getCodeBase();
	strCodebase = urlAux.toString();
	if(strCodebase == null)
		return;

	strLista = getParameter("LISTA");
	strFundo = getParameter("FUNDO");
	strLogo  = getParameter("LOGO");

    mediaTracker_track1 = new MediaTracker(this);

    offscreenImg = createImage(320,240);
    offscreenG = offscreenImg.getGraphics();
    offscreenG.setColor(Color.blue);
    offscreenG.fillRect(0,0,320,240);

	try
	{
		if(strFundo != null)
		{
			urlAux = new URL(strCodebase + strFundo);
			imageAppArea = getImage(urlAux);
		}

        if(strLogo == null)
			strLogo = "X";

        urlAux = new URL(strCodebase + strLogo);
        imageAppArea1 = getImage(urlAux);
        mediaTracker_track1.addImage(imageAppArea1, 0);

		choice_cam.addItem(strLogo);
		choice_image.addItem("Nenhuma");

		add(choice_image);

		add(label_Status);
		label_Status.setVisible(false);

		// Read cam.txt
		urlAux = new URL(strCodebase + strLista);
		BufferedReader input;
		String string_FileLine;

		input = new BufferedReader(new InputStreamReader(urlAux.openStream()));
		if((string_FileLine = input.readLine()) != null)
			strLink = string_FileLine;

		while((string_FileLine = input.readLine()) != null)
		{
			choice_cam.addItem(RetornaCamJpg(string_FileLine));
			choice_image.addItem(RetornaNomeCam(string_FileLine));
		}

		input.close();
		choice_image.select("Nenhuma");
	}
	catch(Exception e)
	{
		showStatus("Erro: Donwload arquivo de parâmetros: " + e.toString());
		return;
	}
}

public void update(Graphics g)
{
	paint(g);
}

public void paint(Graphics g)
{
	if(isFirstTime)
		choice_image.setBounds(13,266,117,30);

	if(imageAppArea != null)
		g.drawImage(imageAppArea, 0, 240, this);

    if(mediaTracker_track1.checkID(0))
	{
		if(imageAppArea != null)
		{
			offscreenG.drawImage(imageAppArea1, 0, 0,320,240, this);
			g.drawImage(offscreenImg, 0, 0,320,240, this);
		}
	}
}

@Override
public synchronized boolean action(Event event, Object obj)
{
	if(event.target instanceof Choice)
	{
		try
		{
			 URL url_Image;
			String strAux = choice_cam.getItem(choice_image.getSelectedIndex());
			url_Image = new URL(strCodebase + strAux);

			if(ServerTimeOut(url_Image))
			{
				bServerTimeOut = true;
				return true;
			}

			imageAppArea1 = getImage(url_Image);
			mediaTracker_track1.addImage(imageAppArea1,0);
		}
		catch(Exception e)
		{
			showStatus("Erro: Donwload imagem: " + e.toString());
			return false;
	    }

		isImage = !(choice_image.getSelectedItem() == "Nenhuma");

		repaint();
        return true;
	}
	return false;
}

@Override
public synchronized boolean mouseMove(Event e , int x, int y)
{
	if(x >= 165 && x <= 320 && y >= 240 && y <= 295)
		setCursor (new Cursor (Cursor.HAND_CURSOR));
	else if(x >= 130 && x <= 160 && y >= 250 && y <= 290)
		setCursor (new Cursor (Cursor.HAND_CURSOR));
	else
		setCursor (new Cursor (Cursor.DEFAULT_CURSOR));

	return true;
}

@Override
public synchronized boolean mouseDown(Event e , int x, int y)
{
   	if(x >= 165 && x <= 320 && y >= 240 && y <= 295) // link
		OpenLink();
	if(x >= 130 && x <= 160 && y >= 250 && y <= 290) // snapshot
		SaveSnapshot();

	return true;
}

private String RetornaCamJpg(String s)
{
	String strAux;
    strAux = s.substring(s.lastIndexOf(';') + 1, s.length());
    return strAux;
}

private String RetornaNomeCam(String s)
{
	String strAux;
    strAux = s.substring(0, s.lastIndexOf(';'));
    return strAux;
}

private void OpenLink()
{
    try
    {
         URL url_Link;
         url_Link = new URL("http://" + strLink);
         AppletContext browser = getAppletContext();
         browser.showDocument(url_Link, "_blank" );
    }
    catch(Exception e)
	{
    }
}

@Override
public void start()
{
	if(thread_This == null)
	{
		thread_This = new Thread(this);
	}
	thread_This.start();
}

@Override
public void stop()
{
	thread_This = null;
}

@Override
public void destroy()
{
	offscreenG.dispose();
}

private boolean ServerTimeOut(URL url_Img)
{
	BufferedReader input;
	String string_FileLine;

	try
	{
		input = new BufferedReader(new InputStreamReader(url_Img.openStream()));
		if((string_FileLine = input.readLine()) != null)
		{
			if(string_FileLine.indexOf("404 -") != -1)
			{
				input.close();
				label_Status.setVisible(true);
				label_Status.setBounds(0,0,450,14);
				label_Status.setText("===> Tempo de conexão expirado!!! Pressione 'atualizar' no browser. <===");
				return true;
			}
		}
		input.close();
		return false;
	}
	catch (Exception e)
	{
	}
	return false;
}

public void run()
{
	Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

	try
	{
		if(isFirstTime)
		{
			imageAppArea1.flush();
			
                            mediaTracker_track1.waitForID(0);
                            		
                            isFirstTime = false;
		}
	}
	catch (InterruptedException e) {}

	while(Thread.currentThread()  == thread_This)
	{
		try
		{ // aqui
			if(isImage)
			{
				imageAppArea1.flush();
			     mediaTracker_track1.waitForID(0);
                                  
                                    
			}

		}
		catch (InterruptedException e)
		{
		}


		repaint();

		try
		{
			Thread.sleep(THREAD_MILLISENCONDS);
		} catch (InterruptedException e) { break; }
	}
}

private void SaveSnapshot()
{
	String strName = "";
    Image imgToSend = null;

	if(!isImage)
		return;
	else
    {
        imgToSend = imageAppArea1.getScaledInstance(320,240,Image.SCALE_FAST);
		strName = choice_image.getSelectedItem();
    }

    try
    {
        Date currentDate;
        SimpleDateFormat formatter;
        String strLastDate, strFrameTitle, strFileName;
        formatter = new SimpleDateFormat (" dd-MMM-yyyy hh:mm:ss", Locale.getDefault());
        currentDate = new Date();
        strLastDate = formatter.format(currentDate);
        strFrameTitle = "[" + strName + "]" + " " + strLastDate;

        formatter = new SimpleDateFormat ("dd_MMM_yyyy_hh_mm_ss", Locale.getDefault());
        strLastDate = formatter.format(currentDate);

        strFileName = (String) choice_cam.getItem(choice_image.getSelectedIndex());
        strFileName = strFileName.substring(0, strFileName.lastIndexOf('.'));
        strFileName += "_" + strLastDate + ".jpg";

        Snapshot cf = new Snapshot();
        cf.show(imgToSend, strFrameTitle, strFileName);

    }
    catch(Exception e) {}
    repaint();
}

}

GR

1 Resposta

neohacker

Use as tags Code plzzz …

:?

Criado 21 de dezembro de 2007
Ultima resposta 26 de dez. de 2007
Respostas 1
Participantes 2