图片按钮
package com.chen.lesson5;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
public class JButtonDemo extends JFrame {
public JButtonDemo(){
Container container = this.getContentPane();
URL resource = JButtonDemo.class.getResource("tx.jpg");
Icon icon = new ImageIcon(resource);
JButton jButton = new JButton("图片按钮");
jButton.setToolTipText("图片按钮");
jButton.setIcon(icon);
container.add(jButton);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setBounds(100,100,200,200);
}
public static void main(String[] args) {
new JButtonDemo();
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201106173014928.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTMyNTkxMg==,size_16,color_FFFFFF,t_70#pic_center)