Results 1 to 3 of 3
  1. #1
    MaxMonic is offline Member
    Join Date
    Dec 2010
    Rep Power

    Lightbulb Move from console to GUI

    Hi, I got have assignment to convert Java program from console to GUI.

    I need to write these line at command prompt to run the program:

    java JavaFile data.txt -0

    -data.txt contains database (flat file). I think it supposed to pass data from the text file into java program.
    - somehow I don't really understand the function of -0. Error occurs if I don't put the -0.

    Since the program require me to put the database filename and attribute -0 to run the program, I have no idea how to turn it into GUI and make user don't need to type those thing to execute the program.


  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    maybe you could use reflection API to load that class and invoke the main() method with these parameters.

    Java Code:
    	 * Invokes the main method of a specified class.
    	 * @param className
    	 * @param parameters
    	 * @throws ClassNotFoundException 
    	 * @throws NoSuchMethodException 
    	 * @throws SecurityException 
    	 * @throws InvocationTargetException 
    	 * @throws IllegalAccessException 
    	 * @throws IllegalArgumentException 
    	public void invokeMain(String className, List<String> parameters) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    		Class<?> theClass = Class.forName(className);
    		Method mainMethod = theClass.getMethod("main", String[].class);
    		if (parameters != null && parameters.size() > 0) {
    			mainMethod.invoke(null, (Object) parameters.toArray(new String[0]));
    		else {
    			mainMethod.invoke(null, (Object) new String[0]);
    For example,

    invokeMain("JavaFile", Arrays.asList("data.txt", "-0") );

  3. #3
    MaxMonic is offline Member
    Join Date
    Dec 2010
    Rep Power


    Thanks for the reply.
    I am still new to Java thus Java reflection is something out of my league.

    I will try to learn more about your java reflection before applying this.

    Thanks again.
    Last edited by MaxMonic; 01-01-2011 at 07:38 AM.

Similar Threads

  1. Help with Move Shape
    By romina in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2010, 04:25 AM
  2. setSelectedIndex (How to move between tabs)
    By lolshooter in forum New To Java
    Replies: 4
    Last Post: 02-02-2010, 04:15 PM
  3. How do you move a picture?
    By Addez in forum New To Java
    Replies: 6
    Last Post: 11-03-2009, 09:44 PM
  4. how can i move from Frame to another
    By the swan in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 05:24 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