图片按钮
public class JButtonDemo1 extends JFrame { public JButtonDemo1(){ Container container = getContentPane(); URL url = JButtonDemo1.class.getResource("tx.jpeg"); ImageIcon icon = new ImageIcon(url);//把图片变成图片标签 //把这个图标放在按钮上 JButton button = new JButton(); button.setIcon(icon); button.setToolTipText("图片按钮");//提示文本,把图标变成按钮 container.add(button); this.setVisible(true); this.setSize(500,300); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JButtonDemo1(); } }
单选框 public class JButtonDemo2 extends JFrame{ public JButtonDemo2(){ Container container = getContentPane(); URL url = JButtonDemo1.class.getResource("tx.jpeg"); ImageIcon icon = new ImageIcon(url);//把图片变成图片标签 //单选框 JRadioButton radio