1

I knows that this subject has been breached a few times, but I ran into an error when fixing it the way that it was said to be fixed in the others ones.

public static class FlowAp extends JFrame{
    String one = "One";
    String two = "Two";
    String three = "Three";
    String four = "Four";
    String five = "Five";

public static void main(String argv[]){
    FlowAp fa=new FlowAp();
    //Change from BorderLayout default
    fa.getContentPane().setLayout(new FlowLayout());
    fa.setSize(200,200);
    fa.setVisible(true);
}
FlowAp(){

    JButton one = new JButton("One");
    getContentPane().add(one);
    JButton two = new JButton("Two");
    getContentPane().add(two);
    JButton three = new JButton("Three");
    getContentPane().add(three);
    JButton four = new JButton("four");
    getContentPane().add(four);
    JButton five = new JButton("five");
    getContentPane().add(five);

}
}

When I actually put in the parenthesis where they look as though they should be, another error shows up with the flowap."invalid method declaration"

5
  • Where is the invalid method declaration, exactly? And is this a nested class inside another? Please give all the details of the errors you're seeing. Commented Oct 4, 2011 at 14:57
  • How do you try to start the program? Commented Oct 4, 2011 at 14:58
  • 1
    Question title does not seem to match body. Commented Oct 4, 2011 at 14:59
  • If you actually had a decent compiler, you'd get the following error - "Illegal modifier for the class FlowAp; only public, abstract & final are permitted" Commented Oct 4, 2011 at 15:01
  • a) It says the erro on "FlowAp fa=new FlowAp(); b) That is the start of the program. c) That is the error, I simply stated that the fix that the others gave in another thread wouldn't work because of a different error. d) I'm using NetBeans 7.0.1 Commented Oct 4, 2011 at 17:22

4 Answers 4

2

Try removing "static":

public class FlowAp extends JFrame{
Sign up to request clarification or add additional context in comments.

1 Comment

When I remove the static from class, it states that I cannot reference a non-static variable in a static context.
2

please there are basic stuff, there are lots of mistakes and I can't comment something, then

enter image description here

from code

import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class FlowAp extends JFrame {

    private static final long serialVersionUID = 1L;
    private String one = "One";
    private String two = "Two";
    private String three = "Three";
    private String four = "Four";
    private String five = "Five";

    public FlowAp() {
        JButton oneButton = new JButton(one);
        JButton twoButton = new JButton(two);
        JButton threeButton = new JButton(three);
        JButton fourButton = new JButton(four);
        JButton fiveButton = new JButton(five);

        setTitle("FlowAp");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
        add(oneButton);
        add(twoButton);
        add(threeButton);
        add(fourButton);
        add(fiveButton);
        setLocation(100, 100);
        pack();
        setVisible(true);
    }

    public static void main(String argv[]) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                FlowAp fa = new FlowAp();
            }
        });
    }
}

Comments

2

The modifier "static" for your class is not allowed in your case - remove it and it will work. If you want to access your variables you have to make them static so that you can reference them from the main method.

2 Comments

I didn't think so, but it was saying that there was no way that this would work without the static. It was giving a separate error message, about how you cannot reference a non-static variable in a static context.
Then you ought to make your variables static, not your class
1

Should be:

public static void main(String[] argv){

Post the error which occurs when you write this.

Note:
- A class cannot be static.

2 Comments

Doesn't make any difference. The []s are generally preferred your way around, but the C-compatibility way works.
In java it doesn't really matter where [] are String[] blah is the same as String blah[];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.