Java-主要方法在
中找不到,我知道这个主题已经被破坏了几次,但是我在修复它的时候遇到了一个错误,这个错误被认为是在其他错误中修复的。Java-主要方法在
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);
}
}
当我居然把括号,他们看起来好像他们是应该的,另一个错误显示了与flowap“无效的方法声明”
应该是:
public static void main(String[] argv){
发布当你写这个时发生的错误。
注意:
- 一个类不能是静态的。
没有什么区别,'[]'s通常首选你的方式,但C兼容的方式。 –
在java中它并不重要[]是String []等于是相同的作为字符串等等[]; – LordDoskias
我不明白在这里upvotes ... – mre
在你的情况下不允许你的类的修饰符“static” - 删除它,它将起作用。如果你想访问你的变量,你必须使它们成为静态的,以便你可以从主要方法中引用它们。
我不这么认为,但它是说,没有静态,这是没有办法,它给出了一个单独的错误信息,关于你如何不能引用一个非静态变量可以在静态环境中使用。 –
然后,你应该让你的变量是静态的,而不是你的类 – LordDoskias
感谢您的提示。 –
尝试删除 “静态”:
public class FlowAp extends JFrame{
当我从类中移除静态时,它声明我不能在静态上下文中引用非静态变量。 –
请there是基本的东西,也有很多错误,我不能评论什么的,然后
从代码
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();
}
});
}
}
感谢您的帮助。 –
*其中*是无效的方法声明,完全是?这是另一个嵌套类吗?请给*所有*你看到的错误的细节。 –
你如何尝试启动程序? – ShiDoiSi
问题标题似乎不匹配身体。 –