Skip to main content
GameDev.net gamedev.net
🔒 Locked

Java: Graphics on the server

Started by Cult Hero Oct 15, 2005 at 11:03 AM 6 replies 600+ views
Original Post
Cult Hero
Cult Hero
I have a program in java that uses RMI with a server and a client, the client calls a server's method and the server should draw an apropiate image according to the method called but nothing happends. here's the method: public void derecha () throws RemoteException{ i = 1; repaint(); System.out.println ("Moving to the right... "); } Here's the paint method: public void paint( Graphics g ) { g.translate(this.getInsets().left,this.getInsets().top); switch(i){ case 0: g.drawImage(imgIzq.getImage(), 0, 0, this); break; case 1: g.drawImage(imgDer.getImage(), 0, 0, this); break; } } What's the problem? Thanks in advance.
hplus0603
hplus0603
Where is the image supposed to be presented?
enum Bool { True, False, FileNotFound };
Cult Hero
Cult Hero
On a Frame:

public class Barco extends Frame implements IBarco
{
...
public Barco () throws RemoteException
{
super();
imgIzq = new ImageIcon("Imagenes/izquierda.gif");
imgDer = new ImageIcon("Imagenes/derecha.gif");
resize(200, 200);
show();
}
...
Cult Hero
Cult Hero
There's no problem with that, even the first image is show since I initialize i=0;

I have done this:
I put this statement on the server remote method derecha:

System.out.println ("Moving to the right... " + i);

Then I put this on the paint method:

g.drawString("i: " + i, 80, 100);

This way I can see what's going on with the i's value

For some reason the system.out.println message is displayed on the client window console and it shows me that the i value has been change but in the
server Frame shows me that the i value hasn't been changed at all even if i repaint the window manually by minimizing and maximizing the window frame.

My head hurts.





Cult Hero
Cult Hero
Yeah, that could be the problem, I did the program fist using only text and the message was show in the server window.

In that text only program I used extends UnicastRemoteObject for the server class but since I needed graphics on the server I used extends Frame and then the problem started.

Since I don't use extends UnicastRemoteObject anymore I use this code on the main() function.

UnicastRemoteObject.exportObject(b);
Cult Hero
Cult Hero
Well, I found the problem, like someone said before, the client wasn't really connected to the server since my server class is not extending from UnicastRemoteObject.

Anyway, I found the way to make an RMI server without extending from UnicastRemoteObject, here's the link:

http://java.sun.com/developer/JDCTechTips/2001/tt0227.html

I hope it ca be useful for someone else too.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.