Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: HI, could someone please tell me why my code doesnt work?

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HI, could someone please tell me why my code doesnt work?

    I wanna make the circle move up, heres the code:

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.ImageObserver;
    import java.io.*;
    import java.net.*;
    import java.applet.AudioClip;
    import javax.imageio.ImageIO;
    import sun.audio.*;
     
    public class Hazlo extends JFrame {
    	Point point = new Point(250,250);
     
    	static Rectangle right = new Rectangle(200, 200, 90, 90);
    	public Hazlo()
    	{
    		super("Shapes");
    		setSize(500,500);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
     
     
     
    	}
     
    	public void paint(Graphics g) {
    		super.paint(g);
     
    		g.setColor(Color.PINK);
     
    		g.fillOval(point.x, point.y, 20, 20);
     
     
     
     
    	}
    	public static void main(String[] args) {
    		new Hazlo();
     
    		class Engine extends Thread {
    			int circleDirection = 2;
    			int UP = 5;
    			int DOWN = 5;
    			Point point = new Point(250,250);
    			public void run(){
    				while(true){
    					point.y++;
     
     
     
     
    					try {
    						Thread.sleep(20);
    					} catch (InterruptedException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
     
     
     
    					}
    				}
    			}
    		}
     
    	}


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: HI, could someone please tell me why my code doesnt work?

    First of all if you want to use threads in main class you must run him in special class called Executorservice. or:
    class My thread implements Runnable {your code} (this class must be above yout main class)
    then in your main class(in static method main) you wrire something like this : Thread t = new Thresd(new My());t.start();
    Second: in hazlo you make Point class and use them to change circle position. Then in your main method in thread class , you create another Point class. POint class in thread isn't invoke your circle point. They are different object.

Similar Threads

  1. Scanner code won't work
    By r19ecua in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 21st, 2011, 04:49 PM
  2. Timer code does not work!
    By mariapatrawala in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 10th, 2010, 10:03 AM
  3. WHY this code dont work?
    By sibbe in forum Java Theory & Questions
    Replies: 7
    Last Post: December 9th, 2010, 10:47 AM
  4. please tell me why this code does not work
    By amr in forum Java Theory & Questions
    Replies: 9
    Last Post: December 6th, 2010, 06:46 PM
  5. my menu doesnt work can u tell me whats wrong
    By claymore in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 8th, 2010, 04:16 AM