ButtonListener -> getIcon()

0

mam klase public class klasa extends JFrame implements ActionListener {
private bufferedimage image;
public Klasa() {
initComponents();
button.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
image = // i tutaj wstawic zeby do zmiennej image przypisywal sie obrazek z buttona po jego kliknieciu (button ma ustawiony setIcon)
}}


Chcialbym aby po kliknieciu na button do zmiennej typu bufferedimage przypisywal sie obrazek jaki ma ustawiony ten button
0
(JButton)(event.getSource()).getIcon();
0

BufferedImage image = (JButton)(e.getSource()).getIcon(); Dostaje błąd ze nie takie same typy ;/

JButton button = (JButton) e.getSource();
        BufferedImage image = (BufferedImage)button.getIcon(); 

Jak przerobic Icon na BufferedImage?

0

google java how to convert image to bufferedimage

1 użytkowników online, w tym zalogowanych: 0, gości: 1