package worry;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import exceise.MyImageIcon;
public class JButtonTest extends JFrame{
public JButtonTest() {
URL url=MyImageIcon.class.getResource("di1shenmo.jpg");
Icon icon=new ImageIcon(url);
setLayout(new GridLayout(3,2,5,5));
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(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "弹出对话框");
}
});
c.add(jb);
}
public static void main(String args[]) {
}
}