Wie schon im Titel erklärt , habe ich ein JPanel programmiert, das erst angezeigt wird, wenn ich in fullscreen gehe und danach bleibt es auch da, auch wenn ich wieder in die normale Fenstergröße zurückgehe. Finde das seltsam, da ich in dem Programm schon einige Panels eingebaut hab, die tadellos funktionieren.
Hier erstmal der Code:
[CODE lang="java" highlight="155-119"]import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Game {
JFrame window;
JPanel titlePanel, startButtonPanel, mainTextPanel, choiceButtonPanel, playerPanel;
JLabel titleText;
Font titleFont = new Font("Times New Roman", Font.PLAIN, 140);
Font normalFont = new Font("Times New Roman", Font.PLAIN, 30);
JButton startButton, choice1, choice2, choice3, choice4;
JTextArea mainTextArea;
TitleScreenHandler tsHandler = new TitleScreenHandler();
public static void main(String[] args)
{
new Game();
}
public Game()
{
window = new JFrame();
window.setSize(800, 600); //window.setSize(width, height)
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null); //deaktiviert das default Layer von Java
window.setVisible(true);
titlePanel = new JPanel();
titlePanel.setBounds(100, 100, 600, 150); //title.setBounds(x, y, width, height)
titlePanel.setBackground(Color.black);
titleText = new JLabel("Adventure");
titleText.setForeground(Color.white);
titleText.setFont(titleFont);
startButtonPanel = new JPanel();
startButtonPanel.setBounds(300, 400, 200, 100);
startButtonPanel.setBackground(Color.black);
startButton = new JButton("START");
startButton.setBackground(Color.black); //Color of button
startButton.setForeground(Color.white); //Color of text in button
startButton.setFont(normalFont);
startButton.addActionListener(tsHandler);
titlePanel.add(titleText);
startButtonPanel.add(startButton);
window.add(titlePanel);
window.add(startButtonPanel);
}
public void createGameScreen()
{
titlePanel.setVisible(false);
startButtonPanel.setVisible(false);
mainTextPanel = new JPanel();
mainTextPanel.setBounds(100, 100, 600, 250);
mainTextPanel.setBackground(Color.black);
window.add(mainTextPanel);
mainTextArea = new JTextArea("This is the main text area.");
mainTextArea.setBounds(100, 100, 600, 250);
mainTextArea.setBackground(Color.black);
mainTextArea.setForeground(Color.white); // color of text
mainTextArea.setFont(normalFont);
mainTextArea.setLineWrap(true); // Zeilenumbruch findet bei zu langem Text automatisch statt
mainTextPanel.add(mainTextArea);
choiceButtonPanel = new JPanel();
choiceButtonPanel.setBounds(250, 350, 300, 150);
choiceButtonPanel.setBackground(Color.black);
choiceButtonPanel.setLayout(new GridLayout(4,1)); //...new GridLayout(Vertikal, Horizontal));
window.add(choiceButtonPanel);
choice1 = new JButton("Choice 1");
choice1.setBackground(Color.black);
choice1.setForeground(Color.white);
choice1.setFont(normalFont);
choiceButtonPanel.add(choice1);
choice2 = new JButton("Choice 2");
choice2.setBackground(Color.black);
choice2.setForeground(Color.white);
choice2.setFont(normalFont);
choiceButtonPanel.add(choice2);
choice3 = new JButton("Choice 3");
choice3.setBackground(Color.black);
choice3.setForeground(Color.white);
choice3.setFont(normalFont);
choiceButtonPanel.add(choice3);
choice4 = new JButton("Choice 4");
choice4.setBackground(Color.black);
choice4.setForeground(Color.white);
choice4.setFont(normalFont);
choiceButtonPanel.add(choice4);
playerPanel = new JPanel();
playerPanel.setBounds(100, 15, 600, 50);
playerPanel.setBackground(Color.blue);
playerPanel.setLayout(new GridLayout(1,4));
window.add(playerPanel);
}
public class TitleScreenHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
createGameScreen();
}
}
}
[/CODE]
Das "playerPanel" wird ist das besagte Panel, was ohne fullscreen nicht angezeigt wird. Ich habe schon playerPanel.setVisible(true) versucht und ich habe auch versucht dem Panel ein JLabel zuzuweisen, beides ohne Erfolg.
Könnte mir hier vielleicht jemand weiterhelfen?
Danke im voraus
Hier erstmal der Code:
[CODE lang="java" highlight="155-119"]import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Game {
JFrame window;
JPanel titlePanel, startButtonPanel, mainTextPanel, choiceButtonPanel, playerPanel;
JLabel titleText;
Font titleFont = new Font("Times New Roman", Font.PLAIN, 140);
Font normalFont = new Font("Times New Roman", Font.PLAIN, 30);
JButton startButton, choice1, choice2, choice3, choice4;
JTextArea mainTextArea;
TitleScreenHandler tsHandler = new TitleScreenHandler();
public static void main(String[] args)
{
new Game();
}
public Game()
{
window = new JFrame();
window.setSize(800, 600); //window.setSize(width, height)
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null); //deaktiviert das default Layer von Java
window.setVisible(true);
titlePanel = new JPanel();
titlePanel.setBounds(100, 100, 600, 150); //title.setBounds(x, y, width, height)
titlePanel.setBackground(Color.black);
titleText = new JLabel("Adventure");
titleText.setForeground(Color.white);
titleText.setFont(titleFont);
startButtonPanel = new JPanel();
startButtonPanel.setBounds(300, 400, 200, 100);
startButtonPanel.setBackground(Color.black);
startButton = new JButton("START");
startButton.setBackground(Color.black); //Color of button
startButton.setForeground(Color.white); //Color of text in button
startButton.setFont(normalFont);
startButton.addActionListener(tsHandler);
titlePanel.add(titleText);
startButtonPanel.add(startButton);
window.add(titlePanel);
window.add(startButtonPanel);
}
public void createGameScreen()
{
titlePanel.setVisible(false);
startButtonPanel.setVisible(false);
mainTextPanel = new JPanel();
mainTextPanel.setBounds(100, 100, 600, 250);
mainTextPanel.setBackground(Color.black);
window.add(mainTextPanel);
mainTextArea = new JTextArea("This is the main text area.");
mainTextArea.setBounds(100, 100, 600, 250);
mainTextArea.setBackground(Color.black);
mainTextArea.setForeground(Color.white); // color of text
mainTextArea.setFont(normalFont);
mainTextArea.setLineWrap(true); // Zeilenumbruch findet bei zu langem Text automatisch statt
mainTextPanel.add(mainTextArea);
choiceButtonPanel = new JPanel();
choiceButtonPanel.setBounds(250, 350, 300, 150);
choiceButtonPanel.setBackground(Color.black);
choiceButtonPanel.setLayout(new GridLayout(4,1)); //...new GridLayout(Vertikal, Horizontal));
window.add(choiceButtonPanel);
choice1 = new JButton("Choice 1");
choice1.setBackground(Color.black);
choice1.setForeground(Color.white);
choice1.setFont(normalFont);
choiceButtonPanel.add(choice1);
choice2 = new JButton("Choice 2");
choice2.setBackground(Color.black);
choice2.setForeground(Color.white);
choice2.setFont(normalFont);
choiceButtonPanel.add(choice2);
choice3 = new JButton("Choice 3");
choice3.setBackground(Color.black);
choice3.setForeground(Color.white);
choice3.setFont(normalFont);
choiceButtonPanel.add(choice3);
choice4 = new JButton("Choice 4");
choice4.setBackground(Color.black);
choice4.setForeground(Color.white);
choice4.setFont(normalFont);
choiceButtonPanel.add(choice4);
playerPanel = new JPanel();
playerPanel.setBounds(100, 15, 600, 50);
playerPanel.setBackground(Color.blue);
playerPanel.setLayout(new GridLayout(1,4));
window.add(playerPanel);
}
public class TitleScreenHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
createGameScreen();
}
}
}
[/CODE]
Das "playerPanel" wird ist das besagte Panel, was ohne fullscreen nicht angezeigt wird. Ich habe schon playerPanel.setVisible(true) versucht und ich habe auch versucht dem Panel ein JLabel zuzuweisen, beides ohne Erfolg.
Könnte mir hier vielleicht jemand weiterhelfen?
Danke im voraus