import javax.swing.ImageIcon;
import java.awt.*;
import java.awt.event.*;
public class MainPanel extends JFrame
{
private JButton button_1;
JPanel JP;
private ImageIcon img_1=new ImageIcon("pink.png");//定义图标
public MainPanel(){
button_1=new JButton("");
JP=new JPanel();
button_1.setIcon(img_1);//加入图标
JP.add(button_1);
button_1.setPreferredSize(new Dimension(350,250));//设置按钮大小
add(JP);
setBounds(200,200,700,500);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
validate();
}
}
这是一个很大的按钮: