updateing applets

N

nialltimpson

It is a bit hard to describe what im trying to do but here goes,
Im writeing an applet that display 6 pictures, (easy enough) I have this
this done and it displays the 6 pictures in the init(), but what I want to
do is update the pictures, dynamicially, I tried just reassing the initial
pictures that i have displayed to the ones I want to display, but the
applet isnt geting refreshed to update the pictures. here is the code.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import java.applet.AppletContext;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JApplet;
import java.awt.Graphics;
import java.math.BigInteger;

public class ScratchCardV24 extends JApplet implements Runnable{

private Socket connection;
private ObjectInputStream input;
private ObjectOutputStream output;
private Thread thread;

String message;

ImageIcon imageL1 = null;
ImageIcon imageL2 = null;
ImageIcon imageL3 = null;
ImageIcon imageR1 = null;
ImageIcon imageR2 = null;
ImageIcon imageR3 = null;

String strL1 = null;
String strL2 = null;
String strL3 = null;
String strR1 = null;
String strR2 = null;
String strR3 = null;

Image L1 = null;
Image L2 = null;
Image L3 = null;
Image R1 = null;
Image R2 = null;
Image R3 = null;

JLabel labelL1;
JLabel labelL2;
JLabel labelL3;
JLabel labelR1;
JLabel labelR2;
JLabel labelR3;

URL where;
//----------------------------------------------------------------------------\\

public void init(){

where = getDocumentBase();

// initial picturs, blank == picture.
L1 = getImage (where, "blank");
L2 = getImage (where, "blank");
L3 = getImage (where, "blank");
R1 = getImage (where, "blank");
R2 = getImage (where, "blank");
R3 = getImage (where, "blank");

new JLabel(imageL1);
imageL1 = new ImageIcon(L1);
labelL1 = new JLabel(imageL1);

new JLabel(imageL2);
imageL2 = new ImageIcon(L2);
labelL2 = new JLabel(imageL2);

new JLabel(imageL3);
imageL3 = new ImageIcon(L3);
labelL3 = new JLabel(imageL3);

new JLabel(imageR1);
imageR1 = new ImageIcon(R1);
labelR1 = new JLabel(imageR1);

new JLabel(imageR2);
imageR2 = new ImageIcon(R2);
labelR2 = new JLabel(imageR2);

new JLabel(imageR3);
imageR3 = new ImageIcon(R3);
labelR3 = new JLabel(imageR3);

Container pane = getContentPane();
pane.setLayout(new GridLayout (3,2));

add(labelL1);
add(labelL2);
add(labelL3);
add(labelR1);
add(labelR2);
add(labelR3);

setVisible(true);

}
//----------------------------------------------------------------------------\\

public void run(){

try{
output.writeObject("~request-card~");
output.flush();
while (message == null){
message = (String)input.readObject();
if (message.equals("~attached~")){
strL1 = (String)input.readObject();
strL2 = (String)input.readObject();
strL3 = (String)input.readObject();
strR1 = (String)input.readObject();
strR2 = (String)input.readObject();
strR3 = (String)input.readObject();

L1 = getImage (where, strL1);
L2 = getImage (where, strL2);
L3 = getImage (where, strL3);
R1 = getImage (where, strR1);
R2 = getImage (where, strR2);
R3 = getImage (where, strR3);

}


message = null;
}
}
catch (ClassNotFoundException cnfe) {}
catch ( IOException ioException ) {}
}
//------------------------------------------------------------------------------

public void start() {
try {
connection = new Socket( getCodeBase().getHost(), 2001, true );

input = new ObjectInputStream(connection.getInputStream() );
output = new ObjectOutputStream(connection.getOutputStream() );
output.flush();
thread = new Thread(this);
thread.start();
}

catch ( IOException ioException ) {
ioException.printStackTrace();
}

}

}

I understand its a bad description of what I want done but any idea would
really be greatly received.

Thanking you
niall
 
S

sanjay manohar

After calling
L1 = getImage (where, strL1);
add
labelL1.setIcon(new ImageIcon(L1));
that should do it

But
Why not use arrays with for loops instead of 5 repeated lines?
 
N

nialltimpson

Thank youvery musch, problem solved and your right im now in the procees of
initiating arrays with loops, thanks again

Niall
 
N

nialltimpson

Thank youvery musch, problem solved and your right im now in the procees of
initiating arrays with loops, thanks again

Niall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top