Results 1 to 6 of 6
- 03-25-2012, 04:05 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
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?
- 03-26-2012, 02:42 AM #2
Member
- Join Date
- Mar 2012
- Posts
- 10
- Rep Power
- 0
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?
- 06-14-2012, 01:13 AM #3
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
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.
- 07-03-2012, 05:17 PM #4
Member
- Join Date
- Jul 2012
- Posts
- 27
- Rep Power
- 0
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.
and btw, Im 14.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); } }
- 07-03-2012, 08:52 PM #5
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)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 07-03-2012, 11:18 PM #6
Member
- Join Date
- Jul 2012
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
New to Java looking for a strategic approach..for a prototype
By andydowthwaite in forum New To JavaReplies: 1Last Post: 03-14-2012, 09:43 AM -
Best approach for learning Java for web development as a programmer
By faze in forum New To JavaReplies: 1Last Post: 07-28-2011, 07:43 AM -
New to Java and very confused.
By larson1118 in forum New To JavaReplies: 1Last Post: 04-08-2011, 06:27 PM -
Is this a good approach for a custom object-relational mapping in Java?
By visual-kinetic in forum JDBCReplies: 5Last Post: 12-15-2010, 02:22 AM -
New to java a little confused.
By Dometic in forum New To JavaReplies: 10Last Post: 12-07-2008, 11:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks