Re: static vs. non-static
You must make an instance of the class to use a static method.
Code:
userGUI gui = new userGUI();
gui.setUp();
Re: static vs. non-static
Don't respond to a "Cannot make a static reference to the non-static method setUp() from the type userGUI" message by making things static.
Usually only the few line main() method that launches your application will be static, and possibly the odd "static final" variable that is acting as a constant.
There's not really enough in your post to see what the problem is. If you can't correct the code post a small example that shows the compiler's message when an attempt is made to compile it.
Re: static vs. non-static
Quote:
Originally Posted by
arielb
You must make an instance of the class to use a static method.
Code:
userGUI gui = new userGUI();
gui.setUp();
Do You have to create instance of class, when using static method?
Or You create instance of class when using non static method?
Re: static vs. non-static
the error says:
Quote:
Cannot make a static reference to the non-static method setUp() from the type userGUI
Code:
public static void m1(){
//is not allowed.
m2();
}
public void m2(){
//If allowed.
m1();
}
Re: static vs. non-static
alright. along the same lines, i am having an issue with this:
i declare textArea in gui.java:
Code:
JTextArea textArea;
i start up the gui end...
Code:
public void startGUI() {
// These are all essential GUI pieces
JLabel jLabInstruction, jLaberror;
JLabel copyright = new JLabel("");
JTextField uI = new JTextField("");
JTextArea textArea = new JTextArea("");
JButton jbtnSubmit;
final JFrame jfrm = new JFrame("app name!");
jfrm.setLayout(new FlowLayout());
jfrm.setSize(300, 300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textArea = new JTextArea(5, 20);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
jLabInstruction = new JLabel("SYSTEM: Please type in a command: ");
jbtnSubmit = new JButton("Submit");
jLaberror = new JLabel("");
textArea.setMargin(new Insets(10,10,10,10));
jfrm.add(jLaberror);
jfrm.add(textArea);
jfrm.add(jLabInstruction);
jfrm.add(uI);
jfrm.add(jbtnSubmit);
jfrm.add(new JSeparator(SwingConstants.HORIZONTAL));
jfrm.add(copyright);
jfrm.setVisible(true);
// printToTextArea("hello");
}
and i have a method that writes to the textArea above:
Code:
public void writeToTextArea(String userInputText) {
textArea.append("\nSYSTEM: "
+ userInputText);
}
also, in tasks.java, i am able to call on this last method:
Code:
gui.writeToTextArea("PROGRAM STARTED!");
my problem is that the text area field is not updating. nothing is being inputted.
any and all help is appreciated!
and thanks for the fast previous responses! they were helpful!