Reputation: 2910
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?
Upvotes: 3
Views: 3810
Reputation: 17
Well since when minimize the window and then maximize it, you could try .dispose() it closes the window or you can write your own restart method to set the variables to their starting values.
Upvotes: 0