I am a beginner to java. I have ImageFrame class as follows:
public class ImageFrame extends JFrame {
private static final long serialVersionUID = 1L;
public static final int DEFAULT_WIDTH = 1365;
public static final int DEFAULT_HEIGHT = 730;
GettingImage getimg = new GettingImage();
private BufferedImage image = getimg.getImage();
final ImageProcessing operation = new ImageProcessing(image);
public ImageFrame(){
setTitle("ImageTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
JMenu process = new JMenu("Process");
JMenuItem greyscale = new JMenuItem("greyscale");
process.add(greyscale);
//adding action listener to menu items
greyscale.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
image = operation.greyscale();
System.out.println("greyscale is pressed");
}
}
);
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(process);
setSize(1365, 730);
setVisible(true);
ImageComponent component = new ImageComponent(image);
add(component);
}
}
But the image is not converted into greyscale when I press the greyscale submenu but when I minimized the window and maximize it then the image is changed into greyscale. I think it is due to the fact that the window is not refreshed. How do I refresh it?
Call repaint on the ImageComponent in your action listener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With