[Guide]Making A Cool Java Program![Guide]

Discussion in 'Archives' started by Morphis, Sep 6, 2008.

[Guide]Making A Cool Java Program![Guide]
  1. Unread #1 - Sep 6, 2008 at 6:03 PM
  2. Morphis
    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0

    Morphis Apprentice
    Banned

    [Guide]Making A Cool Java Program![Guide]

    Cool Java Program Guide



    This is a cool program that you can send to your friends and enemies as well to have fun.


    Essentially this is a pretty useless program but it helps you familiarize yourself with java, and just have fun with java. This program will tell a person if they are cool or not and how cool they are based on their name.

    Ok now before you begin I suggest you download Notepad++ as it is a very good free java editor and it is what I use.
    NOTEPAD++ DOWNLOAD

    The next thing you need to do is to configure Notepad++ to edit java code. So open up notepad++ and click on "Languages" on the top toolbar and go down to java and select that and you are all set!

    You will also need to download and setup the java jdk to be able to compile your scripts. Look in the java section of sythe to find a guide on setting it up.



    O.K. now that you have everything you need to write your own programs in java we will need to create a new project so do that.

    IMPORTS - O.K. this basically tells java what classes it needs to import for the program to be able to run. Importing all of the classes will make java be a memory hog. Copy and paste these imports onto notepad++ this is the first part of your code.

    Code:
    import java.awt.*; 
    import javax.swing.*; 
    import java.awt.event.*; 
    import java.util.Random;
    If you want to know what each of those imports are just google them =).


    O.K. so you have your imports now you need to setup your class name and other variables buttons and what not. Here is the things I used for my program. So copy and paste this into your notepad++ project.
    Code:
    public class CoolLevel extends JFrame implements ActionListener, Runnable  { 
         Thread go; 
         JTextField name = new JTextField(30); 
         JButton solve = new JButton("Go");
    	 JButton clear = new JButton("Clear");
    	 JTextArea awesomeness = new JTextArea(8,30);
    	 int awesome = 80;
    	 Random r = new Random();
    	 String names;
    
    the public class is just the name of the class which is "CoolLevel" extends JFrame means that it will be a window that appears when you run it. Implements ActionListener, Runnable. ActionListener is exactly what the name states it is, it listens for user input. Runnable means that the java program will have a thread in it which means that it will be a lot more efficient.
    Thread go;, means I'm making a new thread named "go". JTextField is I'm making a new one same as the rest, I'm just creating buttons and strings and randoms for the program.


    The next part is actually setting up the window and how things will be organized in it.
    Copy and paste this into your notepad++ project.

    Code:
        AwesomeLevel() { 
            super("YOUR PROGRAM NAME"); 
             setSize(430, 200); 
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
             Container content = getContentPane(); 
             BorderLayout bord = new BorderLayout(); 
             content.setLayout(bord);
    		 awesomeness.setEditable(false); 
             awesomeness.setLineWrap(true); 
             JScrollPane textPane = new JScrollPane(awesomeness); 
    		 solve.addActionListener(this); 
             clear.addActionListener(this);		
    		 JPanel centerPanel = new JPanel();
             JPanel topPanel = new JPanel(); 
    		 JPanel bottomPanel = new JPanel();
    		 bottomPanel.add(solve);
    		 bottomPanel.add(clear);
    		 centerPanel.add(awesomeness);
             topPanel.add(name);
    	     name.setText("Enter your name here.");
             content.add(topPanel, BorderLayout.NORTH);  	
    		 content.add(centerPanel, BorderLayout.CENTER);
    		 content.add(bottomPanel, BorderLayout.SOUTH); 
             setVisible(true); 
         } 
    The only thing you need to edit in here is the second line where it says PROGRAM NAME HERE, put the name you want the program to have. This all just sets up the window that will open when this java program is ran.

    This next part sets up what happens when each button is clicked, we have two buttons in this program solve and clear.

    Code:
        public void actionPerformed(ActionEvent evt) { 
             Object source = evt.getSource();
    		 
    		 
             if(source == solve) {
             names = name.getText();
    		 name.setEnabled(false);
    		 if (go == null) { 
    		 go = new Thread(this); 
    		 go.start(); 
    }		 
    		
        }else if(source == clear){
        go = null;
    	solve.setEnabled(true);
    	name.setEnabled(true);
    	name.setText("Enter your name here.");
    	awesomeness.setText(null);
    	awesome -= awesome;
    	awesome += 80;
    				}
    	   }


    Ok we are now almost done. Next we need to setup what will happen when the user presses the button "Go". And we will make it happen within a thread.

    So copy and paste this once again into notepad++.

    Code:
       public void run() {
       if(names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName")){
       awesome += r.nextInt(20);
       awesomeness.setText("Congradulations you have an awesome level of " + awesome + "!");
       }else if(names.equalsIgnoreCase("BESTFRIENDNAME")){
        awesomeness.setText("BESTFRIENDMESSAGE");
       
       }else if(names.equalsIgnoreCase("EnemyName#1")){
       awesomeness.setText("EnemyMessage#1");
       }else if(names.equalsIgnoreCase("EnemyName#2")){
    
        awesomeness.setText("EnemyMessage#2");
         }else{
    	 awesomeness.setText("Sorry you are not awesome, try again when you get a life.");
    	 }
    
        } 
    Now fill in the things above that have a label of, "FriendName", "BESTFRIENDNAME", "EnemyName#1", "EnemyName#2", "BESTFRIENDMESSAGE", "EnemyMessage#1", "EnemyMessage#2" Fill it in with what the name states IE. for friend name fill in a friends name, for Enemy name fill in the name of an enemy, for the ones that have message in them fill in what you want the message to say respectively. So for an enemy something bad, for you best friend something good.


    Ok now the last part. To just create the window and close off the program with a bracket. So copy and paste this last part.

    Code:
          public static void main(String[] arguments) { 
          CoolLevel frame = new CoolLevel();
         } 
    	 
    	 
     }




    You whole code should look something along the lines of this

    Code:
    import java.awt.*; 
    import javax.swing.*; 
    import java.awt.event.*; 
    import java.util.Random;
    
    public class CoolLevel extends JFrame implements ActionListener, Runnable  { 
         Thread go; 
         JTextField name = new JTextField(30); 
         JButton solve = new JButton("Go");
    	 JButton clear = new JButton("Clear");
    	 JTextArea awesomeness = new JTextArea(8,30);
    	 int awesome = 80;
    	 Random r = new Random();
    	 String names;
         
    	  
        CoolLevel() { 
            super("YOUR PROGRAM NAME"); 
             setSize(430, 200); 
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
             Container content = getContentPane(); 
             BorderLayout bord = new BorderLayout(); 
             content.setLayout(bord);
    		 awesomeness.setEditable(false); 
             awesomeness.setLineWrap(true); 
             JScrollPane textPane = new JScrollPane(awesomeness); 
    		 solve.addActionListener(this); 
             clear.addActionListener(this);		
    		 JPanel centerPanel = new JPanel();
             JPanel topPanel = new JPanel(); 
    		 JPanel bottomPanel = new JPanel();
    		 bottomPanel.add(solve);
    		 bottomPanel.add(clear);
    		 centerPanel.add(awesomeness);
             topPanel.add(name);
    	     name.setText("Enter your name here.");
             content.add(topPanel, BorderLayout.NORTH);  	
    		 content.add(centerPanel, BorderLayout.CENTER);
    		 content.add(bottomPanel, BorderLayout.SOUTH); 
             setVisible(true); 
         } 
     
        public void actionPerformed(ActionEvent evt) { 
             Object source = evt.getSource();
    		 
    		 
             if(source == solve) {
             names = name.getText();
    		 name.setEnabled(false);
    		 if (go == null) { 
    		 go = new Thread(this); 
    		 go.start(); 
    }		 
    		
        }else if(source == clear){
        go = null;
    	solve.setEnabled(true);
    	name.setEnabled(true);
    	name.setText("Enter your name here.");
    	awesomeness.setText(null);
    	awesome -= awesome;
    	awesome += 80;
    				}
    	   }
    	
    	
    	
    	
    
    
       public void run() {
       if(names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName") || names.equalsIgnoreCase("FriendName")){
       awesome += r.nextInt(20);
       awesomeness.setText("Congradulations you have an awesome level of " + awesome + "!");
       }else if(names.equalsIgnoreCase("BESTFRIENDNAME")){
        awesomeness.setText("");
       
       }else if(names.equalsIgnoreCase("EnemyName#1")){
       awesomeness.setText("EnemyMessage#1");
       }else if(names.equalsIgnoreCase("EnemyName#2")){
    
        awesomeness.setText("EnemyMessage#2");
         }else{
    	 awesomeness.setText("Sorry you are not awesome, try again when you get a life.");
    	 }
    
        } 
    
    	
    	
    	
    	
          public static void main(String[] arguments) { 
          CoolLevel frame = new CoolLevel();
         } 
    	 
    	 
     }
     
    Now save it as CoolLevel.java and compile it. Find your CoolLevel.class file and drag it onto the desktop. And open up notepad++ again and create a new file. And paste this into it.
    Code:
    @ECHO off
    java CoolLevel
    save it as run.bat and save it on your desktop.

    Now make a new folder and name it whatever you want. Place CoolLevel.java and run.bat into it and to run the program just double click run.bat . Check it out and redistribute it.

    Guide is property of Morphis.​
     
  3. Unread #2 - Sep 6, 2008 at 10:55 PM
  4. Rawr
    Joined:
    Jul 18, 2008
    Posts:
    2,442
    Referrals:
    10
    Sythe Gold:
    13
    Pokémon Trainer

    Rawr Addict.
    Retired Sectional Moderator $100 USD Donor

    [Guide]Making A Cool Java Program![Guide]

    Take a picture of what it does? Also add colour, bold stuff etc. to make it look nicer. Good start though, nice use of detail.
     
  5. Unread #3 - Sep 6, 2008 at 11:00 PM
  6. Morphis
    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0

    Morphis Apprentice
    Banned

    [Guide]Making A Cool Java Program![Guide]

    ya i got lazy towards the end. Ill add pictures and formatting soon.
     
  7. Unread #4 - Sep 7, 2008 at 1:14 AM
  8. Sitono
    Joined:
    Aug 9, 2008
    Posts:
    228
    Referrals:
    1
    Sythe Gold:
    0

    Sitono Active Member

    [Guide]Making A Cool Java Program![Guide]

    good guide. need pictures and when i did all the steps when i run "run.bat"

    it get this

    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: CoolLevel
    Caused by: java.lang.ClassNotFoundException: CoolLevel
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    
    any help please?
     
  9. Unread #5 - Sep 7, 2008 at 1:16 AM
  10. idkaboutthis
    Joined:
    Jan 29, 2007
    Posts:
    1,164
    Referrals:
    0
    Sythe Gold:
    0

    idkaboutthis Guru
    Banned

    [Guide]Making A Cool Java Program![Guide]

    looks nice i might try later.
     
  11. Unread #6 - Sep 7, 2008 at 6:56 AM
  12. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,211
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [Guide]Making A Cool Java Program![Guide]

    is the bat file in the same folder as the java file?


    and i hate guides with copy and paste coding so no comment.
     
  13. Unread #7 - Sep 7, 2008 at 11:45 AM
  14. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [Guide]Making A Cool Java Program![Guide]

    You need to compile it first using "javac".

    The file name has to be CoolLevel.java exactly. It will not work otherwise (without modifying the class name of course)

    Then run "javac CoolLevel.java". In a few seconds, you should see "CoolLevel.class" in the same directory. Save the batch file in that directory and you should be set.

    [​IMG]
    ):
     
  15. Unread #8 - Sep 7, 2008 at 12:28 PM
  16. draggin pure
    Joined:
    Apr 7, 2008
    Posts:
    1,429
    Referrals:
    0
    Sythe Gold:
    0

    draggin pure Guru
    Banned

    [Guide]Making A Cool Java Program![Guide]

    cp is on a laptop :)

    anywho good guide.. but we need pics..
     
  17. Unread #9 - Sep 7, 2008 at 3:32 PM
  18. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [Guide]Making A Cool Java Program![Guide]

    The screenshot is a picture of what the program does/is. o_O
     
  19. Unread #10 - Sep 7, 2008 at 4:30 PM
  20. Morphis
    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0

    Morphis Apprentice
    Banned

    [Guide]Making A Cool Java Program![Guide]

    thank you cp, anyways. Ill post pictures soon, but I mean all I can do is take a picture of the program and thats about it.
     
  21. Unread #11 - Sep 7, 2008 at 6:17 PM
  22. Sitono
    Joined:
    Aug 9, 2008
    Posts:
    228
    Referrals:
    1
    Sythe Gold:
    0

    Sitono Active Member

    [Guide]Making A Cool Java Program![Guide]

    Im really confused now, i think someone should make a guide on how to compile javac files.
     
  23. Unread #12 - Sep 7, 2008 at 8:42 PM
  24. insanosky
    Joined:
    Jul 4, 2008
    Posts:
    1,505
    Referrals:
    1
    Sythe Gold:
    0

    insanosky Guru
    Banned

    [Guide]Making A Cool Java Program![Guide]

    LOL looks hard to do... try to upload pics..
     
< borrowing ags 95k for a hour, u must get ur own junk | rsclegends.net >

Users viewing this thread
1 guest


 
 
Adblock breaks this site