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 14 of 14

Thread: why my code does not work ?? ://

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default why my code does not work ?? ://

    //this program must draw line in a panel using mouse events .. 
     
     
    import java.awt.*;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.geom.Line2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class MouseTest {
    	public static void main(String [] args)
    	{
    		MouseFrame frame = new MouseFrame() ;
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    		frame.show() ;
    	}
     
    }
    	 class MouseFrame extends JFrame
    	{
    		MouseFrame()
    		{
    		  setTitle("Mouse"	) ;
    		  setSize(DEFAULT_WIDTH , DEFAULT_lENGTH) ;
    		  MousePanel panel = new MousePanel() ;
    		  Container contentPane = getContentPane() ;
    		  contentPane.add(panel) ;
    		}
    		public static final int DEFAULT_WIDTH = 350 ;
    		public static final int DEFAULT_lENGTH = 350 ;
    	}
     
     
     
    	 class MousePanel extends JPanel
    	 {
    		 Line2D line ;
     
    		 public MousePanel()
    		 {
     
    			addMouseListener(new MouseHandler()) ;
     
    		 }
     
     
    		 public void paintComponent(Graphics g)
    		 {
     
     
    			 super.paintComponent(g);
    			 Graphics2D g1 =(Graphics2D) g ;
    			 if(line!=null)
    			 {
    			 g1.draw(line) ;
    			 }
     
     
    		 }
     
    		 private class MouseHandler extends MouseAdapter
    		 {
    			 public void MousePressed( MouseEvent event)
    			 {
    				 line = new Line2D.Double(0 , 0 , event.getX() , event.getY()) ;
    				 repaint() ;
     
    			 } 
    		 }
    	 }
    Last edited by without name; May 6th, 2014 at 02:14 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: why my code does not work ?? ://

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What happens when the code is compiled and executed?
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    without name (May 6th, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    gyna.jpg

    this photo will show you what happened ..
    just screen without any lines ..
    when i click on the mouse .. nothing happened ..

  5. #4
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    any help ?? please .. ://

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: why my code does not work ?? ://

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #6
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    excuse me .. how can i make it ?

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: why my code does not work ?? ://

    1) edit the post
    2) put
    [code]
    in front of the code
    2) put
    [/code]
    after the code
    2) Press save
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    without name (May 6th, 2014)

  10. #8
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    thaaanks .. done
    waiting your help .. ^_^

  11. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: why my code does not work ?? ://

    Java - as with just about any programming language - is case sensitive. In other words, do all your methods that inherit from a parent class actually override the parent method signature?

  12. The Following User Says Thank You to copeg For This Useful Post:

    without name (May 6th, 2014)

  13. #10
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    yes .. i think that ..
    there is no errors in the code ..
    it just doesn't work well ..

  14. #11
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: why my code does not work ?? ://

    Add some print line to debug - does the method you think should get called actually get called? If not, why might this be (see post #9)?

  15. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: why my code does not work ?? ://

    Also it is important to add the @Override annotation before any method you override so the compiler can verify that the override is valid.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #13
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: why my code does not work ?? ://

    i can't understand what you say ..
    can you speak arabic ??
    my language is arabic ..
    i can speak and understand english but not very good :/ !

  17. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: why my code does not work ?? ://

    From Google translate:
    أيضا من المهم لإضافة الشرح @ قبل أي تجاوز الأسلوب الذي تجاوز حتى المترجم يمكن أن تحقق من أن التجاوز غير صالحة.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Why does this code now work?
    By Tuidog in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 6th, 2014, 08:06 AM
  2. Code doesn't work
    By Nicken99 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2014, 04:24 AM
  3. Help me I am trying to get this code to work.
    By Leonardo1143 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 26th, 2013, 07:41 PM
  4. 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
  5. 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