Results 1 to 6 of 6
  1. #1
    AmpedNavy is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Confused About How To Approach Java

    I have tried to learn by reading instructions, but I can't seem to understand any of anything I find. So I followed random tutorials and pieced together how some things work(most I don't understand). That seemed to be working for me up until now... I've just been trying to learn to make a simple 2D game, http://justinandjava.vacau.com/Gamez.html, but I want to make the code more oragnized and efficient; like to make multiple mobs by calling a method of a different class and have seperate variables(but the same titles) for each mob/object and maybe have the circles stop when they touch each other... But I can't seem to figure anything out. How should I approach learning more about programming? I'm just so confused with where I'm at atm, google doesn't ever provide me with what I'm looking for and I feel stupid asking random stuff on here. Anyone have any tips for a 16 year old wanna be game designer/programmer?

  2. #2
    Join Date
    Mar 2012
    Posts
    10
    Rep Power
    0

    Default Re: Confused About How To Approach Java

    Hey i'm 15 and I am right about where you are in Java knowledge. I want to make a simple 2d game just like you but all the tutorials i've done are no help to me. Where did you learn to make the game in the link?

  3. #3
    Keegan is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Confused About How To Approach Java

    Sorry, this is kinda bumping an old thread but my advice, don't start by making a game. Learn all the basics first otherwise its really hard to do anything with java. Do you know what classes and objects are? Or even what functions and methods are? Parameters? Learn about these things first. Write programs that don't have an interface but just process and compute things using the console as input and output. Look up some exchange rates for money and make a program that converts USD to various currencies. I did that when I was first learning java.

    Also java documentation will save your ass often. It is a great tool.

    Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

    Here are some of the basics. It may be a little hard to get into at first but once you have the basics, you'll start picking up things faster and faster.
    Last edited by Keegan; 06-14-2012 at 01:16 AM.

  4. #4
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default examples

    I know how you feel guys, I just dragged though like you guys did but here are some examples I came up with:


    a basic JFrame. You just scribble on it but it uses Actions that are easy to implement and a nice way of painting

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class test extends JFrame {
    	public static void main(String[] args) {
    		new test();
    	}
    	
    	public test() {
    		this.setTitle("Scribble!");
    		panel.setPreferredSize(new Dimension(400,400));
    		
    		this.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {System.exit(0);}
    		});
    		
    		panel.addMouseListener(new MouseAdapter(){
    			public void mousePressed(MouseEvent e) {
    				last_x = e.getX();
    				last_y = e.getY();
    				requestFocus();
    			}
    		});
    		
    		panel.addMouseMotionListener(new MouseMotionAdapter() {
    			public void mouseDragged(MouseEvent e) {
    				x = e.getX();
    				y = e.getY();
    				draw();
    				last_x=x;
    				last_y=y;
    			}
    		});
    		
    		this.addKeyListener(new KeyAdapter() {
    			public void keyPressed(KeyEvent e) {
    				//System.out.print(((int)('a')+32)+" "+(e.getKeyCode()-32)+" ");
    				if(e.getKeyCode()==65)clear();
    			}
    		});
    		
    		this.add(panel);
    		
    		this.pack();
    		this.setVisible(true);
    	}
    	
    	public void init() {
    		clear();
    	}
    	
    	public int x, y;
    	public int last_x, last_y;
    	public JPanel panel = new JPanel();
    	
    	public void draw() {
    		Graphics g = panel.getGraphics();
    		g.setColor(Color.black);
    		g.drawLine(last_x,last_y,x,y);
    	}
    	
    	public void clear() {
    		Graphics g = panel.getGraphics();
    		g.setColor(Color.white);
    		g.fillRect(0,0,400,400);
    	}
    }

    and here is a slightly more complex example with a thread. I whipped it up pretty quick out of this other example.

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class test2 extends JFrame implements Runnable {
    	public static void main(String[] args) {
    		new test2();
    	}
    	
    	public void run() {
    		while(!pleaseStop) {
    			try{animator.sleep(wait);}
    			catch(Exception e){}
    			paint(panel.getGraphics());
    		}
    	}
    	
    	public test2() {
    		this.setTitle("thing... yea!");
    		panel.setPreferredSize(new Dimension(400,400));
    		
    		this.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {System.exit(0);}
    		});
    		
    		panel.addMouseListener(new MouseAdapter(){
    			public void mousePressed(MouseEvent e) {
    			}
    		});
    		
    		panel.addMouseMotionListener(new MouseMotionAdapter() {
    			public void mouseDragged(MouseEvent e) {
    			}
    		});
    		
    		this.addKeyListener(new KeyAdapter() {
    			public void keyPressed(KeyEvent e) {
    				//System.out.print(e.getKeyCode());
    				switch(e.getKeyCode()){
    					case 37://left
    						xv--;
    					break;
    					case 39://right
    						xv++;
    					break;
    					case 38://up
    						yv--;
    					break;
    					case 40://down
    						yv++;
    					break;
    				}
    			}
    		});
    		
    		this.add(panel);
    		
    		this.pack();
    		this.setVisible(true);
    		
    		animator = new Thread(this);
    		animator.start();
    		pleaseStop = false;
    	}
    	
    	public void init() {
    	}
    	
    	public int x=100,y=100; //position
    	public int xv,yv; //velocity
    	public JPanel panel = new JPanel();
    	
    	public volatile boolean pleaseStop;
    	public Thread animator;
    	public int wait = 10;  //milliseconds
    	
    	public void doStuff(){
    		x+=xv;
    		y+=yv;
    	}
    	
    	public void paint(Graphics g) {
    		g.setColor(Color.white);
    		g.fillRect(0,0,400,400);
    		doStuff();
    		g.setColor(Color.black);
    		g.drawRect(x,y,10,10);
    	}
    }
    and btw, Im 14.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,415
    Rep Power
    20

    Default Re: Confused About How To Approach Java

    Never use getGraphics() of a Component, and don't override paint(...) of a top level window. Learn the correct approach to Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Also, respect Swing's single threaded rule. Learn about Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: Confused About How To Approach Java

    Yea, I probably should but it works. I will adjust further programs accordingly.

Similar Threads

  1. New to Java looking for a strategic approach..for a prototype
    By andydowthwaite in forum New To Java
    Replies: 1
    Last Post: 03-14-2012, 09:43 AM
  2. Replies: 1
    Last Post: 07-28-2011, 07:43 AM
  3. New to Java and very confused.
    By larson1118 in forum New To Java
    Replies: 1
    Last Post: 04-08-2011, 06:27 PM
  4. Replies: 5
    Last Post: 12-15-2010, 02:22 AM
  5. New to java a little confused.
    By Dometic in forum New To Java
    Replies: 10
    Last Post: 12-07-2008, 11:56 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
  •