Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
  1. #21
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    I have already done a bunch of tutorials and I know c++ which seems pretty similar to java. The way I have been running my .class files are just using the applet tag and putting the .class in it. Heres an example of one html code I have used:

    <applet code="BallMover.class" width="300" height="300">
    </applet>

    I just don't understand jar files. I don't know how JVM would know when I want each different .class file to be ran. Is there like a run function that runs a differen't .class file or something?

  2. #22
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    I have made simple 1 class file games, just they only have one level, so I want to do this so I can add levels.

  3. #23
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    Take your working applet class. Put it in a jar file, change the HTML by adding the archive=YOURFILE.jar and try it. Make sure the .class file is not in the folder with the HTML and jar file.

    I don't know how JVM would know
    The JVM always looks on the classpath for the files it needs.

    when I want each different .class
    The when is determined by your code. If you "request" a class, the JVM must find it somewhere. It looks on the classpath for all classes requested by the program.

    I want to do this so I can add levels
    "levels" are an application concept. There is NOTHING in java that is a level. You create "levels" in your code. Its an abstraction.

  4. #24
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    So how do I make that when point in my code that will request the class?

  5. #25
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    When you write a java program you have to use (request) classes to do everything.
    There is no other way, other than a most trivial case.
    Its so natural that I'm having a hard time understanding how you could have written a program in java without using/requesting classes.

  6. #26
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    This was my process of making my program if it helps you: I wrote my code and saved it as a .java file. Then I did the javac thing in command prompt and it made my class file. Then I did the embedding in the html file and it gave me my applet. So in that way I don't know how to request classes like you said I had to do.

  7. #27
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    If you have written any non trival program, you have requested classes in it.
    Any time you use the new operator you request a class and the JVM must search the classpath for its definition.

  8. #28
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    So adding another class would be like having this:

    public class example1 extends Applet {
    //code
    }

    and this:

    public class example2 extends Applet {
    //code
    }

    and it would all be in the same .java file?

  9. #29
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    I think I've said all that I can about it. I suggest you read some tutorials on how to write a java program. Your last question shows a basic ignorance of java coding.

    Change your approach: Write the code, compile it and execute it. When you get errors, copy and paste them here.

  10. #30
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    What ever, none of the tutorials I read said anything about classes.

  11. #31
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    What???? I don't believe it.
    EVERY PROGRAM WRITTEN IN JAVA USES CLASSES

  12. #32
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Scroll down this page a little ways: Java programming dynamics, Part 1: Java classes and class loading

    is that the sort of class thing your meaning?

  13. #33
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default

    See post#29

  14. #34
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    You say you know C++.
    A java class is no different (frankly) to the C++ class concept.
    In Java the JVM does the linking step for you, so long as the JVM knows where the class file is. If all your classes are in the same place (ie jar, equivalent of a C++ library) then it will have no problem.
    So, as with C++, you don't "request a class".

  15. #35
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Well I'm going back over a bunch of java tutorials and I think I'm gunna look over my c++ book again to to try and find what you were talking about, I don't wanna feel like such a noob on these forums.

  16. #36
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

Page 2 of 2 FirstFirst 12

Similar Threads

  1. how to protect java codes from being seen?
    By anthrax in forum Eclipse
    Replies: 5
    Last Post: 10-14-2009, 03:43 PM
  2. Missing 4 ISO 3166-1 codes in java.util.Locale
    By fkeller in forum Advanced Java
    Replies: 1
    Last Post: 01-16-2009, 05:41 PM
  3. java codes
    By Balajee in forum AWT / Swing
    Replies: 1
    Last Post: 09-30-2008, 05:04 PM
  4. Algorithm statement in my Java codes
    By javanewbie in forum New To Java
    Replies: 2
    Last Post: 06-24-2008, 02:52 PM
  5. How to get error codes using java program
    By kasipandian in forum Web Frameworks
    Replies: 10
    Last Post: 05-25-2008, 05:00 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
  •