これは私が左側にゲームエリアウィッヒschouldなるサイズ(800600)があり、結果としてJava。ゲームのレイアウト。ウィンドウの右上にラベルを貼る方法は?
を取得するために必要なものです。右のウィンドウの残りの部分にはメニュー/スコアエリアが必要です。
イメージのように、メニュー領域の上部に配置する2つのラベル(scoreLabel; pointsLabel;)があります。私のバージョンでは、私はのGridLayoutを使用していますが、それは私が望むように動作していない:)
import javax.swing.*;
import java.awt.*;
public class PongFrame extends JFrame {
private JLabel scoreLabel;
private JLabel pointsLabel;
public PongFrame() {
this.setTitle("Game");
this.setSize(1100,600);
this.scoreLabel = new JLabel("score");
this.pointsLabel = new JLabel("");
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new GridLayout(1,2));
labelPanel.add(scoreLabel);
labelPanel.add(pointsLabel);
JPanel gameArea = new JPanel();
gameArea.setBackground(Color.orange);
gameArea.setSize(800,600);
Container con = this.getContentPane();
con.setLayout(new GridLayout(1,2));
con.add(gameArea);
con.add(labelPanel);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void setPoints (String labeltext){
this.pointsLabel.setText(labeltext);
}
public static void main (String [] args){
PongFrame window = new PongFrame();
window.pointsLabel.setText("0");
}
}
あなたは今結果として何を得ていますか? – Aurasphere
@Aurasphereああ申し訳ありませんが、私はすでにコードを変更しました。しかし、問題は、テキストがメニュー/スコアエリアの真ん中にあったことです – Diana