初级FlowLayout问题,耽误你们一分钟,谢谢啦。
import java.awt.*;
import javax.swing.*;
public class FlowLayout{
public static void main(String args[]){
JFrame frame=new JFrame("welcome");
Container con=frame.getContentPane();
frame.setLayout(new FlowLayout());
JButton button[]=new JButton[5];
for(int i=0;i<5;i++){
button[i]=new JButton("第"+(i+1)+"个按钮");
con.add(button[i]);
}
frame.pack();
frame.setVisible(true);
}
}
显示Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method setLayout(LayoutManager) in the type JFrame is not applicable for the arguments (FlowLayout)
at FlowLayout.main(FlowLayout.java:7)
为什么这样设置有错吗setLayout,我看书本上是这样呀,晕死
[解决办法]
你把你 的 类名重命名FlowLayoutDemo
或
frame.setLayout(new java.awt.FlowLayout());
就可以了
[解决办法]
如三楼 类名换了就OK