Я на самом деле создаю программу, используя кнопки, при попытке вставить изображение в кнопку, я получаю сообщение об ошибке, говорящее «значок не может быть преобразован в тип»
public class gui extends JFrame {
private JButton reg;
private JButton custom;
public gui(){
super("the title");
setLayout(new FlowLayout());//this sets a default layout
reg =new JButton("reg button");
add(reg);
.....
//the error here says icon cannot be resolved to a type
//icon is highlighted for the error
Icon b = new ImageIcon(getClass().getResource("b.png"));
Icon x = new ImageIcon(getClass().getResource("x.jpeg"));
....
custom =new JButton("custom",b);
custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent eve){
JOptionPane.showMessageDialog(null,"this works");
JOptionPane.showMessageDialog(null,String.format("%S",eve.getActionCommand()));
}
}
}