Okay, but when I override paintComponent, it gives me an error...
It works if I don't override paintComponent (as in it doesn't throw any errors, but nothing is painted...)... why's that?
Code (The class that is having problems, the other class calls init and start game)
package server;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import game.*;
import javax.swing.*;
import java.awt.*;
/**
* Write a description of class Linker here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TestGame implements PlugNPlayIMPL{
JPanel gamePanel;
public TestGame(){
init();
}
public void startGame(){
gamePanel = new JPanel();
while(true){
gamePanel.repaint();
}
}
public void endGame(){}
public void testPaint(Graphics g){
if(g==null) {
System.out.println("THESE GRAPHICS HATE YOU AND YOUR FAMILY!!!");
return;
}
g.fillRect(35,35,200,200);
}
public void init(){
gamePanel = new JPanel(){
public void paintComponent(Graphics g){
super.paintComponent(g);
testPaint(g);
}
};
}
public static void main(String[] args){
try{
Runtime.getRuntime().exec("rmiregistry", null, new java.io.File("I:\\RMI_Server"));
PlugNPlayIMPL game = new TestGame();
PlugNPlayIMPL stub = (PlugNPlayIMPL) UnicastRemoteObject.exportObject(game, 0);
Registry reg = LocateRegistry.getRegistry();
reg.rebind("TestGame", stub);
System.out.println("Bound Game Object.");
}catch(Exception e){
e.printStackTrace();
}
}
public void loadSplashScreen(){}
public JPanel getGamePanel() throws RemoteException{ return gamePanel; }
}
Error:
java.lang.ClassCastException: cannot assign instance of $Proxy1 to field server.TestGame$1.this$0 of type server.TestGame in instance of server.TestGame$1
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2032)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1212)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1953)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy1.getGamePanel(Unknown Source)
at client.LoadGame.main(LoadGame.java:32)
at client.__SHELL3.run(__SHELL3.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at bluej.runtime.ExecServer$3.run(ExecServer.java:855)