Results 1 to 16 of 16

Thread: Help me please

  1. #1
    vuquanghoang is offline Member
    Join Date
    Mar 2011
    Location
    Viet Nam
    Posts
    5
    Rep Power
    0

    Default Help me please

    I have written teh following code:
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    class ChuotDemo extends Frame implements MouseListener
    {
    	int x,y;
    	public ChuotDemo()
    	{
    		addMouseListener(this);
    		setSize(500,500);
    		setVisible(true);
    	}
    	public void mouseExited(MouseEvent e){
    	}
    	public void mouseEntered(MouseEvent e){
    	}
    	public void mouseReleased(MouseEvent e){
    	}
    	public void mousePress(MouseEvent e){
    	}
    	public void mouseClicked(MouseEvent e){
    		x=e.getX();
    		y=e.getY();
    		repaint();
    	}
    	public void paint(Graphics g)
    	{
    		g.fillRect(x,y,50,50);
    	}
    	public static void main(String[]args)
    	{
    		new ChuotDemo();
    	}
    }
    When compiling it, Jcreator show this error:

    Please help me explain what this error is and how to resolve. thanks a lot :D

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    public void mousePress(MouseEvent e){} != public void mousePressed(MouseEvent e) {}

    :D

  3. #3
    vuquanghoang is offline Member
    Join Date
    Mar 2011
    Location
    Viet Nam
    Posts
    5
    Rep Power
    0

    Talking help me one more time with another error

    This is my code:
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    class Bamnut extends Frame implements ActionListener
    {
    	Button ok;
    	public Bamnut(String title)
    	{
    		super(title);
    		add(ok=new Button("bam"));
    		ok.addActionListener(this);
    		setSize(500,500);
    		setVisible(true);
    		}
    		public void ActionPerformed(ActionEvent e)
    		{
    			if(e.getSource="bam")
    			{
    				repaint();
    			}}
    			public void paint(Graphics g)
    			{
    				g.setColor(Color.BLUE);
    				g.drawOval(50,50,50,50);
    			}
    			public static void main(String[]args)
    			{
    				new Bamnut(" cua so tinh yeu");
    			}
    		}
    And here is error:

    Thanks a lot. I have learned java for some days, so I don't know much. That's the reason why I post many topic here and I am not spam .:D

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Quote Originally Posted by vuquanghoang View Post
    Thanks a lot. I have learned java for some days, so I don't know much.
    Then you have to learn the basics before you program the UI !

    ActionPerformed != actionPerformed,
    comparison is == or equals , = is an assignment , but read what getSource returns ! (btw thats a method --> getSource() )
    EventObject (Java Platform SE 6)

  5. #5
    vuquanghoang is offline Member
    Join Date
    Mar 2011
    Location
    Viet Nam
    Posts
    5
    Rep Power
    0

    Default

    thanks a lot a lot a lot :), I have fix this but it have a more err. I am studying java fundamental a class. What I want you to help me is something I try before studying at class
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    class Bamnut extends Frame implements ActionListener
    {
    	Button ok;
    	public Bamnut(String title)
    	{
    		super(title);
    		add(ok=new Button("bam nut"),BorderLayout.SOUTH);
    		ok.addActionListener(this);
    		setSize(500,500);
    		setVisible(true);
    		}
    		public void ActionPerformed(ActionEvent e)
    		{
    			if(e.getSource()=="bam nut")
    			{
    				repaint();
    			}}
    			public void paint(Graphics g)
    			{
    				g.setColor(Color.BLUE);
    				g.drawOval(50,50,50,50);
    			}
    			public static void main(String[]args)
    			{
    				new Bamnut(" cua so tinh yeu");
    			}
    		}
    Last edited by vuquanghoang; 03-06-2011 at 11:13 AM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    It's 'actionPerformed' with a lower case 'a', not 'ActionPerformed'.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default

    i want to print the following pattern, please help me

    *******
    ******
    *****
    ****
    Last edited by arunjib; 03-06-2011 at 11:39 AM.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by arunjib View Post
    i want to print the following pattern, please help me

    * * * * * * *
    * * * * * *
    * * *
    *
    Please start your own thread and don't just hijack someone else's thread.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    vuquanghoang is offline Member
    Join Date
    Mar 2011
    Location
    Viet Nam
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    It's 'actionPerformed' with a lower case 'a', not 'ActionPerformed'.

    kind regards,

    Jos
    Thanks, but I fix it into A. This error still appear :((

  10. #10
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Read my post again ... and read the API DOC !!!!!!
    getSource will not return "bam nut" - it will return the button

    ActionPerformed is wrong --> actionPerformed is right!

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    class Bamnut extends Frame implements ActionListener {
    	Button ok;
    
    	public Bamnut(String title) {
    		super(title);
    		add(ok = new Button("bam nut"), BorderLayout.SOUTH);
    		ok.addActionListener(this);
    		setSize(500, 500);
    		setVisible(true);
    	}
    
    	public void actionPerformed(ActionEvent e) { // <--------------
    		if (e.getSource() == ok) {  //<----------
    			repaint();
    		}
    	}
    
    	public void paint(Graphics g) {
    		g.setColor(Color.BLUE);
    		g.drawOval(50, 50, 50, 50);
    	}
    
    	public static void main(String[] args) {
    		new Bamnut(" cua so tinh yeu");
    	}
    }

  11. #11
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default

    sorry! i am very new user here and i dont know how to create a new thread

  12. #12
    vuquanghoang is offline Member
    Join Date
    Mar 2011
    Location
    Viet Nam
    Posts
    5
    Rep Power
    0

    Default

    thanks you, I will do what you said by reading API :D.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by arunjib View Post
    sorry! i am very new user here and i dont know how to create a new thread
    There's a button on top of the thread listing labeled 'New Thread'; guess what it does.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default

    I am really sorry! i cannot find the label 'New Thread'. i would be greatful if u put an screenshoot of that

  15. #15
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

  16. #16
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •