0
何が起こっているのか分かりませんが、これを修正するために多くのことを試しました。私はそれが愚かな間違いであると思うが、それはすでに私に時間がかかりました。以下はコードです。もし誰かが何をすべきか分かっていれば教えてください。プログラム実行時にJLabelが表示されない
public class Window extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private static Toolkit toolkit = Toolkit.getDefaultToolkit();
public static final int WIDTH = (int) toolkit.getScreenSize().getWidth();
public static final int HEIGHT = (int) toolkit.getScreenSize().getHeight();
public Dimension windowDimension = new Dimension(WIDTH, HEIGHT);
JButton buttonStartGame = new JButton();
JButton buttonTechTreeOverview = new JButton();
JButton buttonOptions = new JButton();
JButton buttonExit = new JButton();
ImageIcon buttonStartGameIcon = new ImageIcon(getClass().getResource("buttonStartGameIcon.png"));
ImageIcon buttonTechTreeOverviewIcon = new ImageIcon(getClass().getResource("buttonTechTreeOverviewIcon.png"));
ImageIcon buttonOptionsIcon = new ImageIcon(getClass().getResource("buttonOptionsIcon.png"));
ImageIcon buttonExitIcon = new ImageIcon(getClass().getResource("buttonExitIcon.png"));
JLabel backLabel = new JLabel();
public Window(String name) {
setLayout(null);
setSize(windowDimension);
setUndecorated(true);
setTitle(name);
setVisible(true);
setResizable(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
modifyCompontes();
startMenu();
System.out.println("Thread is ok");
}
public void startMenu() {
backLabel.add(buttonExit);
backLabel.add(buttonStartGame);
backLabel.add(buttonTechTreeOverview);
backLabel.add(buttonOptions);
add(backLabel);
}
public void StartGame() {
}
public void TechTreeOverviewStart() {
}
public void gameOptions() {
}
private void modifyCompontes() {
try {
backLabel.setIcon(new ImageIcon(
imageResizer(ImageIO.read(getClass().getResourceAsStream("fundo.png")), WIDTH, HEIGHT)));
} catch (IOException e) {
e.printStackTrace();
}
backLabel.setBounds(0, 0, WIDTH, HEIGHT);
buttonStartGame.setIcon(buttonStartGameIcon);
buttonStartGame.setBounds(100, 100, 200, 100);
buttonStartGame.addActionListener(this);
buttonTechTreeOverview.setIcon(buttonTechTreeOverviewIcon);
buttonTechTreeOverview.setBounds(100, 250, 200, 100);
buttonTechTreeOverview.addActionListener(this);
buttonOptions.setIcon(buttonOptionsIcon);
buttonOptions.setBounds(100, 400, 200, 100);
buttonOptions.addActionListener(this);
buttonExit.setIcon(buttonExitIcon);
buttonExit.setBounds(100, 550, 200, 100);
buttonExit.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonStartGame) {
StartGame();
}
if (e.getSource() == buttonTechTreeOverview) {
TechTreeOverviewStart();
}
if (e.getSource() == buttonOptions) {
gameOptions();
}
if (e.getSource() == buttonExit) {
System.exit(0);
}
}
public Image imageResizer(Image image, int width, int height) {
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = resizedImage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(image, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}
}