Results 1 to 4 of 4
  1. #1
    Ampzor is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Why is it saying I have made an illegal expression?

    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    
    public class Genetics extends JFrame {
    
    	public static void main(String[] args) {
    		private JTextField input = new JTextField(10);
    		private JTextField output = new JTextField(6, 10);
    		private JButton exit = new JButton();
    	}
    
    
    	public static void addListener() {
    		JTextFieldListener tfListener = new JTextFieldListener();
    		input.addActionListener(tfListener);
    		boolean output = false;
    		out.setEditable(output);
    	}
    
    	public static void Buttons() {
    		EnterButtonHandler ebhandler = new EnterButtonHandler();
    		input.addActionListener(ebhandler);
    		boolean click = true;
    	}
    
    	public static void Display() {
    		Pane.add(input);
    		Pane.add(input);
    		Pane.add(input);
    		Pane.add(input);
    		Pane.add(output);
    		Pane.add(exit);
    
    	}
    
    	private class JTextFieldListener implements ActionListener {
    		public void Action(ActionEvent evt) {
    			String inputString = input.getText();
    			String outputString = output.setText();
    		}
    	}
    
    	public static void Exit() {
    		System.exit(0);
    	}
    }
    Java Code:
    C:\Documents and Settings\Marshall781\My Documents\Genetics.java:10: illegal start of expression
    		private JTextField input = new JTextField(10);
                    ^
    C:\Documents and Settings\Marshall781\My Documents\Genetics.java:11: illegal start of expression
    		private JTextField output = new JTextField(6, 10);
                    ^
    C:\Documents and Settings\Marshall781\My Documents\Genetics.java:12: illegal start of expression
    		private JButton exit = new JButton();
                    ^
    3 errors
    
    Tool completed with exit code 1

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Why is it saying I have made an illegal expression?

    The private/protected/public keywords aren't valid modifiers for a local variable -- one declared inside a method.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Ampzor is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Why is it saying I have made an illegal expression?

    Quote Originally Posted by DarrylBurke View Post
    The private/protected/public keywords aren't valid modifiers for a local variable -- one declared inside a method.

    db
    Remove the private keywords? Or do I need to relocate them?

    EDIT:
    Now it's saying that it cannot find the keywords input/output.

    Is it not defined right here?
    Java Code:
    	public static void main(String[] args) {
    		 JTextField input = new JTextField(10);
    		 JTextField output = new JTextField(6, 10);
    		 JButton exit = new JButton();
    	}
    Last edited by Ampzor; 02-08-2012 at 03:14 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Why is it saying I have made an illegal expression?

    Since the variables are declared inside the main(...) method, they are accessible only from within the method.

    Did you want to declare them as instance fields instead? Fields are declared in the body of the class, outside of any methods.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 02:50 PM
  2. Illegal start of expression
    By Nigel in forum New To Java
    Replies: 5
    Last Post: 03-11-2011, 12:42 PM
  3. Illegal start of expression
    By Tekila in forum New To Java
    Replies: 10
    Last Post: 03-04-2011, 12:23 AM
  4. Illegal expression
    By Thumper in forum New To Java
    Replies: 82
    Last Post: 12-11-2009, 08:34 AM
  5. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM

Posting Permissions

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