私はペアゲームを作成しようとしています。私は2つのJPanelを作成しました。最初はゲームマップ(100個のボタン)と2番目の統計情報です。問題は、私は左の写真のようにタイマーとカウンターの配置を持っているが、私は右の絵のように(私はペイントで編集)したいと思っている。私はどんなレイアウトを使うべきですか?私は多くの解決策を試しましたが、何も私のために働きました。また、私が設定されている場合はnullマネージャJPanelのは、あなたがお互いに「についての」あなたのオブジェクトを配置することを可能にするさまざまなレイアウトマネージャの全体の様々ながありJpanelのコンポーネントを設定する
public class PairGame extends JFrame implements ActionListener{
JLabel counterLabel, timerLabel;
JMenuBar menuBar;
JMenu file, help;
JMenuItem fileNew, fileExit, helpAbout;
JPanel gamePanel, statisticsPanel;
JToggleButton buttons[];
ArrayList <Integer> values;
int temp=0, counter=0;
void createMenuBar()
{
file = new JMenu("File");
fileNew = new JMenuItem("New");
fileNew.addActionListener(this);
fileNew.setAccelerator(KeyStroke.getKeyStroke("ctrl N"));
fileExit = new JMenuItem("Exit");
fileExit.addActionListener(this);
fileExit.setAccelerator(KeyStroke.getKeyStroke("ctrl Q"));
file.add(fileNew);
file.add(fileExit);
file.setMnemonic('f');
help = new JMenu("Help");
helpAbout = new JMenuItem("About");
helpAbout.addActionListener(this);
helpAbout.setAccelerator(KeyStroke.getKeyStroke("ctrl H"));
help.add(helpAbout);
help.setMnemonic('h');
menuBar = new JMenuBar();
menuBar.add(file);
menuBar.add(help);
setJMenuBar(menuBar);
}
public void createGameMap()
{
gamePanel = new JPanel(new GridLayout(10,10));
values = new ArrayList<Integer>();
for(int i=1; i<=50; i++)
values.add(i);
for(int i=51; i<=100; i++)
values.add(i-50);
Collections.shuffle(values);
buttons = new JToggleButton[100];
for(int i=0; i<100; i++)
{
buttons[i] = new JToggleButton(""+(i+1));
buttons[i].setName(String.valueOf(values.toArray()[i]));
buttons[i].addActionListener(this);
gamePanel.add(buttons[i]);
}
gamePanel.setBounds(0,0,550,400);
add(gamePanel);
}
public void createStatisticsPanel()
{
statisticsPanel = new JPanel();
counterLabel = new JLabel("Counter: "+counter);
timerLabel = new JLabel("Timer: ");
statisticsPanel.add(counterLabel);
statisticsPanel.add(timerLabel);
statisticsPanel.setBounds(0,410,540,400);
add(statisticsPanel);
}
PairGame()
{
setTitle("Pair Game");
setSize(565,600);
setLocation(400,100);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
createMenuBar();
createGameMap();
createStatisticsPanel();
setVisible(true);
}
public static void main(String[] args)
{
new PairGame();
}
'' BoxLayout'(https://docs.oracle.com/javase/tutorial/uiswing/layout/box.html)、['GridLayout'](https://)を使用できる' statisticsPanel'については、 docs.oracle.com/javase/tutorial/uiswing/layout/grid.html)、['GridBagLayout'](https://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html)または[ 'BorderLayout'](https://docs.oracle.com/javase/tutorial/uiswing/layout/border.html)を参照してください。この場合私の個人的な好みによって決定される。 –
投稿することを検討する[MCVE] – c0der
http://stackoverflow.com/help/someone-answersを参照してください – c0der