如何解决图像不会加载 JButton
我正在尝试制作一个主菜单,我现在正在处理播放按钮。除了不加载图像外,一切正常。图像在源文件夹中,这是代码:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GameFrame extends JFrame implements ActionListener{
JButton play;
GameFrame() {
ImageIcon icon = new ImageIcon("playButton.png");
play = new JButton();
play.setBounds(500,100,250,100);
play.addActionListener(this);
play.setText("hi");
play.setFocusable(false);
play.setIcon(icon);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(1000,700);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setUndecorated(false);
this.setVisible(true);
this.add(play);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==play) {
System.out.println("hi");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。