将图标图片添加到Java

时间:2017-04-08 14:03:23

标签: java radio-button icons

我想用这个简单的单选按钮窗格替换标准的Java咖啡杯图片。 (我正在使用Mac)。

我在对话框中使用了url方法,但是在这个方法中无法弄明白。 final ImageIcon MyImageName = new ImageIcon(new URL(... etc.))

    package TestEnvironment;

    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;

    import FinalProject_PizzaHub.RadioButtonActionListener;

    public class RadioButtonTest 
    {
        static String Size;
        final JPanel panelSize = new JPanel();
final JRadioButton radioButtonSmall = new JRadioButton("Small");
final JRadioButton radioButtonMedium = new JRadioButton("Medium");
final JRadioButton radioButtonLarge = new JRadioButton("Large");

    public static void main(String[] args)
    {
        new RadioButtonTest();
    }

    public RadioButtonTest()
    {
panelSize.add(radioButtonSmall);
panelSize.add(radioButtonMedium);
panelSize.add(radioButtonLarge);

RadioButtonActionListener actionListener = new RadioButtonActionListener();
    radioButtonSmall.addActionListener(actionListener);
    radioButtonMedium.addActionListener(actionListener);
    radioButtonLarge.addActionListener(actionListener);

JOptionPane.showMessageDialog(null, panelSize);

if (radioButtonSmall.isSelected())
    {Size = "Small";
    System.out.println("Size is small");}
if (radioButtonMedium.isSelected())
    {Size = "Medium";
    System.out.println("Size is medium");}
if (radioButtonLarge.isSelected())
    {Size = "Large";
    System.out.println("Size is Large");} 
    }

0 个答案:

没有答案