Handling Menu Selections
The actionPerformed method handles menu selections, setting the appropriate drawing flags as needed. This method handles the File menu's Open item by using the ImageIO class to open an image file:
public void actionPerformed(ActionEvent e) { if(e.getSource() == openMenuItem){ try{ dialog.setMode(FileDialog.LOAD); dialog.setVisible(true); if(dialog.getFile() != ""){ File inputFile = new File(dialog.getDirectory() + dialog.getFile()); bufferedImage = ImageIO.read(inputFile); if(bufferedImage != null){ image = createImage(bufferedImage.getWidth(), bufferedImage.getHeight()); Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.drawImage(bufferedImage, null, 0, 0); imageWidth = bufferedImage.getWidth(); imageHeight = bufferedImage.getHeight(); ...
Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.