为什么我的图像不显示?按钮总是在那里,但图像只是没有出现。这可能不是编程问题。我应该把图像放在哪里?
一级档案:
public class start {
public static void main(String args[]){
menu m1 = new menu();
m1.setVisible(true);
}
}
第二类文件:
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;
public class menu extends JFrame{
private static final long serialVersionUID = 1L;
public menu(){
super("Parachute!");
setSize(1000, 800);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel main = new JPanel(new GridBagLayout());
JPanel title = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(15, 15, 15, 15);
JButton play = new JButton("Play!");
JButton help = new JButton("Help");
JButton options = new JButton("Options");
ImageIcon logo = new ImageIcon("parachute.jpg");
JLabel imageLogo = new JLabel(logo);
gbc.gridx = 0;
gbc.gridy = 0;
main.add(play, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
main.add(help, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
main.add(options, gbc);
title.add(imageLogo);
add(title, BorderLayout.NORTH);
add(main, BorderLayout.CENTER);
}
}