Java中按钮不能显示图片,图片在scr文件夹下
importjavax.swing.*;publicclassIconsextendsJFrame{JButton[]buttons=newJButton[24];pub...
import javax.swing.*;
public class Icons extends JFrame {
JButton[] buttons = new JButton[24];
public Icons() {
super("Icons");
setSize(900,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
ImageIcon icon = new ImageIcon(Icons.class.getClassLoader().getResource("3.jpg"));
for (int i=0;i<24;i++) {
buttons[i] = new JButton(icon);
pane.add(buttons[i]);
}
setContentPane(pane);
show();
}
public static void main(String[] arguments) {
Icons ike = new Icons();
}
} 展开
public class Icons extends JFrame {
JButton[] buttons = new JButton[24];
public Icons() {
super("Icons");
setSize(900,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
ImageIcon icon = new ImageIcon(Icons.class.getClassLoader().getResource("3.jpg"));
for (int i=0;i<24;i++) {
buttons[i] = new JButton(icon);
pane.add(buttons[i]);
}
setContentPane(pane);
show();
}
public static void main(String[] arguments) {
Icons ike = new Icons();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |