import javax.swing.*;
import java.awt.event.*;public class ShowMessageDialog extends JFrame implements ActionListener
{
public ShowMessageDialog(String s)
{
super(s);
}

public static void main(String[] args)
{       JButton jb;
ShowMessageDialog frame=new ShowMessageDialog("Dialog test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                ImageIcon buttonIcon = new ImageIcon("d.jpg");//这种插入图片方式是否正确
                jb = new JButton("click",buttonIcon); jb.addActionListener(frame);
jb.setToolTipText("弹出一个新窗口");
frame.getContentPane().add(jb);
frame.pack();
frame.setVisible(true);
} public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this,"I am a hero.");
}
}

解决方案 »

  1.   

    ImageIcon buttonIcon = new ImageIcon("d.jpg");//这种插入图片方式是否正确
                    jb = new JButton("click",buttonIcon); 
    按钮图片,我图形界面的基本没看,别人问我,但我觉得插入图片肯定有错,插入图片的语句因该是怎么写的?
      

  2.   

    然后用 当前 类 比如 Test.class.getresourceasstrem("相对图片路径");