Reputation: 11
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"
Upvotes: 1
Views: 1166
Reputation: 3191
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.
Upvotes: 2
Reputation: 109815
please there are basic stuff, there are lots of mistakes and I can't comment something, then
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();
}
});
}
}
Upvotes: 2
Reputation: 9380
Should be:
public static void main(String[] argv){
Post the error which occurs when you write this.
Note:
- A class cannot be static.
Upvotes: 1