java如何制作图片一样形状的按钮

package Button按钮;


import java.awt.Cursor;
import java.awt.FlowLayout;
import java.net.URL;


import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class anniu extends JFrame {
public static void main(String args[]) {
new anniu().setVisible(true);
}


public anniu() {
super();
this.getContentPane().setLayout(null);
setBounds(100, 100, 257, 160);
final JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(0, 0, 249, 126);
getContentPane().add(panel);
final JButton button = new JButton();
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));


button.setContentAreaFilled(false);
button.setBorder(null);
URL url = getClass().getResource("A.png");
button.setText("你好");
ImageIcon icon = new ImageIcon(url);
button.setIcon(icon);
button.setBounds(50, 48, 70, 80);
panel.add(button);
}
}

你可能感兴趣的:(Java)