Results 1 to 8 of 8
Like Tree3Likes
  • 1 Post By Tolls
  • 2 Post By Fubarable

Thread: How to run another .class?

  1. #1
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default How to run another .class?

    Hello,

    I want to make my code run another (class) file in the same source folder(jar file). How would I do that?
    thanks for any help, its greatly appreciated!

    Aidan

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to run another .class?

    You don't run another class; you either run a (static) method from another class or from an object (instantiation) of that class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: How to run another .class?

    Classes aren't run. Classes are loaded, their instances are constructed, their methods are invoked and their fields are assigned and accessed. None of that constitutes 'running' a class.

    Programs are run. For a Java program, the entry point is the public static void main(String[] args) method of a class.

    Post code that illustrates what exactly you are trying to accomplish.

    db

    edit Looks like it's my turn to be the slow old sod
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Re: How to run another .class?

    Quote Originally Posted by DarrylBurke View Post
    Classes aren't run. Classes are loaded, their instances are constructed, their methods are invoked and their fields are assigned and accessed. None of that constitutes 'running' a class.

    Programs are run. For a Java program, the entry point is the public static void main(String[] args) method of a class.

    Post code that illustrates what exactly you are trying to accomplish.

    db

    edit Looks like it's my turn to be the slow old sod
    Ok, basically I want to execute the code from another class file, like when you run it directly. I'm trying to get a screen to display, so previously I was passing the frame variable (That wasn't working well). heres my code: http://www.ganhaar.com.au/Aidan/Aido...he%20rails.zip

    Sorry if its messy.
    (also yes, I do need help with getting the username XD, and dont bother with my site, I just used it as an upload server :P)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: How to run another .class?

    People here generally won't download random files, for what should be obvious reasons.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: How to run another .class?

    here's his code..guys, no one is trying to kill you with a file

    Java Code:
    import java.awt.EventQueue;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.Logger;
    
    import javax.swing.JFrame;
    
    import Utils.Logging.Logging;
    
    import GUI.Screen.ScreenMain;
    
    public class Along_The_Rails extends JFrame {
    	public Along_The_Rails(){
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 450, 300);
    	}
    	
    	public static void main(String[] args) {
    		
    		Logger Log = Logging.Log;
    		
    		String startString = "Along The Rails Started on: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " (" + System.getProperty("os.arch") + ")";
    		Log.info(startString);
    		
    	}
    }
    anyway, you should make a specific method in the other class, make an object for it and simply call it...

  7. #7
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Re: How to run another .class?

    Quote Originally Posted by Tolls View Post
    People here generally won't download random files, for what should be obvious reasons.
    I use a mac so I dont generally worry, unless the site is really dodgy. (I forgot that viruses actually exist XD)

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: How to run another .class?

    Most of us worry and for good reason, but this is getting off topic. The bottom line is, if you want folks to evaluate your code on a forum, post the code to the forum. If the code is too big to post to the forum, then you're asking volunteers to review too much code and you'll need to refactor and reduce it.
    DarrylBurke and JosAH like this.

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2012, 04:06 AM
  2. Replies: 1
    Last Post: 11-29-2012, 10:46 AM
  3. Replies: 0
    Last Post: 12-07-2011, 12:55 PM
  4. Replies: 0
    Last Post: 03-27-2011, 06:49 AM
  5. Replies: 5
    Last Post: 01-26-2011, 07:38 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
  •