我使用 Java 构建了一个简单的接口,它说没有错误。但是它不能在按钮上显示 1ImageIcon1 (它只有按钮的名称。)。我该如何解决?
这是代码。
public static void main(String[] args) {
JFrame frame=new JFrame("Hi everyone");
frame.setSize(500,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane=new JPanel();
Font font=new Font(Font.SERIF, Font.BOLD,20);
JLabel label=new JLabel("How about a presidation quote");
label.setFont(font);
pane.add(label);
ImageIcon icon=new ImageIcon("ChenGao.jpg");
JButton ChenGao = new JButton("ChenGao",icon);
ChenGao.setHorizontalTextPosition(SwingConstants.CENTER);
ChenGao.setVerticalTextPosition(SwingConstants.BOTTOM);
pane.add(ChenGao);
JTextArea textArea= new JTextArea(10,40);
textArea.setText("Yes we can");
pane.add(textArea);
frame.setContentPane(pane);
frame.setVisible(true);
}