Results 1 to 8 of 8
  1. #1
    bsarules is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default invalid method declaration error

    I am getting error code
    Mouse Click.java:11: invalid method declaration; retun type required
    What am I doing wrong?

    included below is the code that is producing the error mentioned.

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    public class MouseClick {
    	TextField objTextField1;
    	TextField objTextField2;
    	public static void main(String[] args) {
    		MouseClick MC = newMouseClick();
    	}
    	
    	public MouseClick()
    	{
    	
    
    		Frame f = new Frame("Checking the mouse Click");
    		Button button = new Button("Click Me");
    		button.setBounds(100,150,70,70);
    		button.addMouseListener(new MyMouseListener());
    
    
    		f.add(button);
    		lbl = new Label("Not Clicked");
    		objTextField1 = new TextField("TextField1",100);
    		objTextField2 = new TextField("TextField2",100);
    		objTextField1.setBounds(90,75,70,20);
    		objTextField2.setBounds(90,115,150,20);
    		f.add(objTextField1);
    		f.add(objTextField2);
    		f.addWindowListener(new WindowAdapter(){
    			public void WindowClosing(WindowEvent we){
    				System.exit(0);
    			}
    		});
    		f.setSize(600,600);
    		f.setVisible(true);
    	}
    
    	
    	public class MyMouseListener extends MouseAdapter{
    		public void mouseClicked(MouseEvent me){
    			int S=Integer.parseInt(objTextField1.getText());
    			int i=1,x=0;
    			for(i=1;i<S;i++)
    			{
    			x=x+i;
    			}
    			objTextField2.setText("Some of the values from 1 to "+S+" is "+x);
    		}
    	}
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    MouseClick MC = newMouseClick();

    You're missing a blank

    .. and lbl is not defined

    .. and the method is called windowClosing.
    Last edited by PhHein; 05-25-2010 at 04:44 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Where is the error message? Please post full text of error message, don't edit it.

    Newer versions of java have an @override option that you should put in front of all methods that you override to insure the override is correct. If you misspell or have the wrong signature, java will accept that as a New method.

  4. #4
    bsarules is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    I have worked on the code and resolved most errors here is the code and the error message to the error I still have to work out.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    public class MouseClick {;
    	TextField objTextField1;
    	TextField objTextField2;
    	public static void main(String[] args) {
    		MouseClick MC = new MouseClick();
    	}
    
    	public MouseClick(){
    		Frame f = new Frame("Checking the mouse Click");
    		Button button = new Button("Click Me");
    		button.setBounds(100,150,70,70);
    		button.addMouseListener(new MyMouseListener());
    
    
    		f.add(button);
    		Label1 = new Label("Not Clicked");
    		objTextField1 = new TextField("TextField1",100);
    		objTextField2 = new TextField("TextField2",100);
    		objTextField1.setBounds(90,75,70,20);
    		objTextField2.setBounds(90,115,150,20);
    		f.add(objTextField1);
    		f.add(objTextField2);
    		f.addWindowListener(new WindowAdapter(){
    			public void windowClosing(WindowEvent we){
    				System.exit(0);
    			}
    		});
    		f.setSize(600,600);
    		f.setVisible(true);
    	}
    
    	
    	public class MyMouseListener extends MouseAdapter{
    		public void mouseClicked(MouseEvent me){
    			int S=Integer.parseInt(objTextField1.getText());
    			int i=1,x=0;
    			for(i=1;i<S;i++)
    			{
    			x=x+i;
    			}
    			objTextField2.setText("Some of the values from 1 to "+S+" is "+x);
    		}
    	}
    }
    Last edited by bsarules; 05-25-2010 at 05:46 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I take it you are not able to save the error messages as a file or to copy them to the clipboard. Does your IDE have a log file you can copy the text of the error message from?

    Your posting of a reference to an image failed.
    Last edited by Norm; 05-25-2010 at 05:49 PM.

  6. #6
    bsarules is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    I can only do a screen grab of what I see in my command prompt.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    If that is a Windows Command Prompt, you can copy the contents to the clipboard by clicking in the icon in the upper left corner, Select Edit and then Select All. Then do it again and select Copy. Here's what I get:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Owner.ONBOARD-USE>java -version
    java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

    C:\Documents and Settings\Owner.ONBOARD-USE>

    Where is Label1 defined? Javac says it can't find a definition.

  8. #8
    bsarules is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    I have successfully solved all of the problems in the application, thank you to anyone who helped.

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 08:05 PM
  2. BubbleSorting Problem: invalid method declaration
    By SwEeTAcTioN in forum New To Java
    Replies: 6
    Last Post: 12-02-2009, 03:47 AM
  3. Replies: 3
    Last Post: 08-14-2009, 12:57 PM
  4. Invalid Argument error in IE7
    By Kaviurs in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-01-2008, 09:12 AM
  5. Error: invalid method declaration
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-27-2007, 12:10 PM

Tags for this Thread

Posting Permissions

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