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