我的代码以前可以工作,但现在一个 JButton 占用了整个 JFrame,任何帮助将不胜感激!
我正在使用一个名为 fl 的 FlowLayout 和一个名为 Ken 的类
我有十个按钮(oneButton、twoButton、threeButton 等)
我的代码:
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Ken {
public static void frame(){
JFrame frame = new JFrame("Pow");
frame.setSize(500, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
FlowLayout fl = new FlowLayout(0, 50, 40);
JButton oneButton = new JButton(" 1 ");
oneButton.setPreferredSize(new Dimension(100, 90));
frame.add(oneButton);
JButton twoButton = new JButton(" 2 ");
twoButton.setPreferredSize(new Dimension(100, 90));
frame.add(twoButton);
JButton threeButton = new JButton(" 3 ");
threeButton.setPreferredSize(new Dimension(100, 90));
frame.add(threeButton);
JButton fourButton = new JButton(" 4 ");
fourButton.setPreferredSize(new Dimension(100, 90));
frame.add(fourButton);
JButton fiveButton = new JButton(" 5 ");
fiveButton.setPreferredSize(new Dimension(100, 90));
frame.add(fiveButton);
JButton sixButton = new JButton(" 6 ");
sixButton.setPreferredSize(new Dimension(100, 90));
frame.add(sixButton);
JButton sevenButton = new JButton(" 7 ");
sevenButton.setPreferredSize(new Dimension(100, 90));
frame.add(sevenButton);
JButton eightButton = new JButton(" 8 ");
eightButton.setPreferredSize(new Dimension(100, 90));
frame.add(eightButton);
JButton nineButton = new JButton(" 9 ");
nineButton.setPreferredSize(new Dimension(100, 90));
frame.add(nineButton);
JButton zeroButton = new JButton("
0 ");
zeroButton.setPreferredSize(new Dimension(400, 90));
frame.add(zeroButton);
frame.setComponentOrientation(
ComponentOrientation.LEFT_TO_RIGHT);
}
public static void main(String[] args){
frame();
}
}
有什么我可以尝试的吗?