I wanted to make clicking on an icon possible to open a screen, perform any action and so on.
I wanted to put different formats, so I do not use a JButton
. For by passing the image to him, he continued "rectangular". More, if there is any component that can take the form of an image or even do with the JButton, it is also valid.
Example click on a small circle:
packagepacote01;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;publicclassNovoClassextendsJFrame{privateJPanelpainel=newJPanel();publicNovoClass(){setSize(200,150);ImageIconimage=newImageIcon(getClass().getResource("/imagens/icone.png"));
JLabel imagelabel = new JLabel(image);
painel.add(imagelabel);
add(painel);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
NovoClass novo = new NovoClass();
}
}