ackage FinalData;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class JButtonTest extends JFrame{
public JButtonTest() {
URL url=MyImageIcon.class.getResource("/imageButtoo.jpg");
Icon icon=newImageIcon(url);
Container c=getContentPane();
for(int i=0;i<5;i++) {
JButton J=new JButton("button"+i,icon);
c.add(J);
if(i%2==0) {
J.setEnabled(false);
}
}
JButton jb=new JButton();
jb.setMaximumSize(new Dimension(90,30));
jb.setIcon(icon);
jb.setHideActionText(true);
jb.setToolTipText("图片按钮");
jb.setBorderPainted(false);
jb.addActionListener((ActionListener) new ActionListener() {
public void actonPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "弹出对话框");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
});
}
private Icon newImageIcon(URL url) {
// TODO Auto-generated method stub
return null;
}
public static void main(String[] args) {
}
}
这个程序里的MyImageIcon一直报错