Jump to content


Help Needed With The Standard Template


  • Please log in to reply
3 replies to this topic

#1 Arceye

Arceye

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 November 2011 - 09:24 PM

Hi,

I am extremely new to programming of any kind and following instruction from a book called Beginning programming java for dummies,

This book is written using Jcreator for all examples so here I am and asking for help on the first day :( .

My problem is the standard template for the *.java file looks like this (in my opinion a mess)


/**
* @(#)MyFirstJavaClass.java
*
* MyFirstJavaClass application
*
* @author
* @version 1.00 2011/11/4
*/

public class MyFirstJavaClass {
    
    public static void main(String[] args) {
    
     // TODO, add your application code
     System.out.println("Hello World!");
    }
}

But I want it to look like  this

/**
* @(#)MyFirstJavaClass.java
*
* MyFirstJavaClass application
*
* @author
* @version 1.00 2011/11/4
*/

public class MyFirstJavaClass
  {  
      public static void main(String[] args)
         {
             // TODO, add your application code
          System.out.println("Hello World!");
         }

  }

Please notice the changed position of the braces. (in my opinion much better)

Can someone help me make the default template produce what I want so I don't have to edit every file I make in the future?


Edit*
  Ok after posting I see the tabbed formatting doesn't seem to work but i'm sure you get the idea, I don't want the opening brace { to be on the same line as the decloration (or whatever it is called ) I want it to be on he line below
Will I ever understand this stuff?

#2 riley1275

riley1275

    Newbie

  • Members
  • Pip
  • 7 posts
  • Gender:Male
  • Interests:Computing

Posted 05 November 2011 - 10:10 PM

View PostArceye, on 04 November 2011 - 09:24 PM, said:

Hi,

I am extremely new to programming of any kind and following instruction from a book called Beginning programming java for dummies,

This book is written using Jcreator for all examples so here I am and asking for help on the first day :( .

My problem is the standard template for the *.java file looks like this (in my opinion a mess)


/**
* @(#)MyFirstJavaClass.java
*
* MyFirstJavaClass application
*
* @author
* @version 1.00 2011/11/4
*/

public class MyFirstJavaClass {
    
    public static void main(String[] args) {
    
     // TODO, add your application code
     System.out.println("Hello World!");
    }
}

But I want it to look like  this

/**
* @(#)MyFirstJavaClass.java
*
* MyFirstJavaClass application
*
* @author
* @version 1.00 2011/11/4
*/

public class MyFirstJavaClass
  {  
      public static void main(String[] args)
         {
             // TODO, add your application code
          System.out.println("Hello World!");
         }

  }

Please notice the changed position of the braces. (in my opinion much better)

Can someone help me make the default template produce what I want so I don't have to edit every file I make in the future?


Edit*
  Ok after posting I see the tabbed formatting doesn't seem to work but i'm sure you get the idea, I don't want the opening brace { to be on the same line as the decloration (or whatever it is called ) I want it to be on he line below

Just press enter at the end of the line to put the opening brace on the new line.

 public class MyFirstJavaClass // Press enter here!
{

hope this helps

I always write code like that.

#3 Arceye

Arceye

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 06 November 2011 - 01:15 AM

View Postriley1275, on 05 November 2011 - 10:10 PM, said:

Just press enter at the end of the line to put the opening brace on the new line.

 public class MyFirstJavaClass // Press enter here!
{

hope this helps

I always write code like that.


Thanks for trying but not really :),

what I posted is automatically generated when I start a project or a new class file, so I have to manually put the braces on the next line and TAB stuff into the correct alignment, of course by pressing enter as you quite correctly explained, my question was more about how do I change the default template so those braces are where I want them by default so I won't have to hit enter at those points and TAB it into alignment for every auto generated page.
I know its a little fussy of me to want this as it takes only a few seconds to manually edit but after finding that java programming requires more code for the same return as it does in C , I am trying to cut down on all unnecessary work.

System.out.println("blah blah blah");    is quite a lot more than and more difficult to remember than
printf("blah blah blah");     (imagine the difference over 1000's of line of code)

Those are the only commands I know in C or java, but based on those alone I having thoughts of learning java being much more effort for equal return to learning C, so as I said I am trying to reduce the effort required as much as possible before I get bored and give up.
Will I ever understand this stuff?

#4 Scott

Scott

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts
  • Gender:Male
  • Location:England

Posted 06 November 2011 - 03:45 PM

Well if you want to ask a stupid question then expect a stupid answer.

I know nobody reads the manual these days but damn. I found it in about a minute of looking at the help files

Quote

File Templates
One way of extending JCreator is to add your own file templates. Follow these steps to add a new file template:

1. Click File > New > File.

2. In the File Wizard , click File Type and select Java Classes > Java Class.

3. Right-click on the item Java Class and select Open Source. A new file opens in the editor.

4. Right-click on the item Java Class and select Open Properties. A new file opens in the editor as shown in the following image.

5. With both new files open in the editor, click the wizard's close button, the X in the upper right-corner, without creating a new file.

6. Modify the file Java Class.java.jc with the following content:
/**
 * @(#)$[FileBase].java
 *
 *
 * @author
 * @version 1.00 $[Year]/$[Month]/$[Day]
 */

public class $[FileBase] extends Thread {
	
	public $[FileBase](String str) {
		super(str);
	}
	
	public void run() {
	}
}

7. Save the file as Java Thread Class.java.jc and add the following snippet to the file templates.xml.

<template>
	<label>Java Thread Class</label>
	<quickaccess>false</quickaccess>
	<description>Creates a new Java class permitting it to be run as a Thread.</description>
	<type>java</type>
	<source>Java Thread Class.java.jc</source>
</template>

8. Save the file.

I always start with an empty file anyway since the template code doesn't do anything useful. Also compared to the amount of completely new code you'll end up writing the 2 lines or so from the template is nothing.