Results 1 to 5 of 5
  1. #1
    njitram is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default From jar 2 framework

    Hello people,

    At this moment we are building a framework that loads games, we load these games with *.jar files. We have it all working except one thing and that is using commands from out the framework, so what have have is this:

    Loading jar files: (framework)
    Java Code:
    	public loadJars(File file, boolean isCPU){
    		String url = file.toURI().toString().substring(6);
    		JarClassLoader loader = new JarClassLoader(url);
    		Class Mainclass = null;
    		try {
    			Mainclass = loader.loadClass("Main");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		
    		
    		Object Mainobject = null;
    		try {
    			Mainobject = Mainclass.newInstance();
    		} catch (InstantiationException e) {
    			e.printStackTrace();
    		} catch (IllegalAccessException e) {
    			e.printStackTrace();
    		}
    		
    		if(Mainobject instanceof MainFrame){
    			Main = (MainFrame) Mainobject;
    		}
    
    		Framework.subscribeGame(Main.getGameName());
    		Framework_GUI.playerFound();
    		Main.setup(isCPU, Framework.getColor(), this);
    		
    		if(Main.getColor()){
    			playerturn = true;
    		} else {
    			playerturn = false;
    		}
    	}
    What we wanna do now is using a function inside the framework, the function is fired inside the jar file.. The class inside the jar file doesn't know the function in the framework, so how can we manage to get it work?

    Thanks in advance
    Last edited by njitram; 06-09-2010 at 11:50 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    class inside the jar file doesn't know the function in the framework
    What do you mean by "framework"?
    How does a jar know anything? A jar is a file structure that holds other files, like .class files.
    Do you get errors? If so , please copy and paste full text of messages here.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by njitram View Post
    What we wanna do now is using a function inside the framework, the function is fired inside the jar file.. The class inside the jar file doesn't know the function in the framework, so how can we manage to get it work?
    What function, inside which framework? If you have a function in a package there is no limitation to use it from the outside, unless there is no access restriction. Can you bit clear up.

  4. #4
    njitram is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    hmm, we have a some sort of emulator thats what we are calling a framework.
    Inside this framework you can open games, these games are classes inside a jar file.
    But for external play we must make a connection, so the framework has some function for connecting with the server, but the game has to communicate with the functions inside the framework and that part doesn't work. We can communicate from the framework 2 the jar file, it makes a GUI etc. so that part works fine, only not the other way arround.

    What i do have tried now.. is making a function setObject inside the game, so might use the functions inside the framework.

    Main.setLoadJars( this ); //Object obj

    Then im trying to cast the Object inside the right class but it gives a exception:
    java.lang.ClassCastException: Framework.GameEnviroment cannot be cast to GameFramework.GameEnviroment

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    games are classes inside a jar file
    the game has to communicate with the functions inside the framework
    Does the game have a method that you can pass the address of/reference to the "framework" to.
    Then the game can use that to call methods in the "framework"

    java.lang.ClassCastException: Framework.GameEnviroment cannot be cast to GameFramework.GameEnviroment
    What is the relationship between the two packages? Can they be changed to be the same package?

Similar Threads

  1. what is mean by java Framework?
    By makpandian in forum New To Java
    Replies: 4
    Last Post: 03-13-2009, 08:41 AM
  2. NIO Framework 1.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 08-20-2008, 02:28 PM
  3. Echo2 Web Framework 2.1.0.rc4
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-12-2008, 05:16 PM
  4. NIO Framework 0.9.3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-31-2007, 05:29 PM
  5. Aranea framework 1.1-M4
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-02-2007, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •