我是java的初学者。我有 ImageFrame 类如下:
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);
}
}
但是当我按下灰度子菜单时图像不会转换为灰度,但是当我最小化窗口并最大化它时,图像会变成灰度。我认为这是由于窗口没有刷新。我该如何刷新它?