Why is it saying I have made an illegal expression?
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);
}
}
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
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
Re: Why is it saying I have made an illegal expression?
Quote:
Originally Posted by
DarrylBurke
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?
Code:
public static void main(String[] args) {
JTextField input = new JTextField(10);
JTextField output = new JTextField(6, 10);
JButton exit = new JButton();
}
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