Java After Hours: 10 Projects Youll Never Do at Work
When the user selects the File menu's Undo menu item, Graphicizer is supposed to undo the most recent operation. For example, if you blurred an image and then selected Undo, the original version of the image would appear. In order to undo an operation, Graphicizer makes a backup copy of each image before performing an operation, as shown here, where the backup copy, bufferedImageBackup, is made when the user clicks a button: if(event.getSource() == button1){ bufferedImageBackup = bufferedImage; . . .
Later, if the user selects the Undo menu item, all you need to do is to copy the backup image to bufferedImage and then display the newly restored image, resizing the main window if needed: if(event.getSource() == menuitem3){ if (bufferedImageBackup != null){ bufferedImage = bufferedImageBackup; setSize(getInsets().left + getInsets().right + Math.max (400, bufferedImage.getWidth() + 60), getInsets().top + getInsets().bottom + Math.max(340, bufferedImage.getHeight() + 60)); button1.setBounds(30, getHeight() - 30, 60, 20); button2.setBounds(100, getHeight() - 30, 60, 20); button3.setBounds(170, getHeight() - 30, 60, 20); button4.setBounds(240, getHeight() - 30, 60, 20); button5.setBounds(310, getHeight() - 30, 60, 20); repaint(); }
And that's itthat completes the Graphicizer application. Now you can load in images, convert them to other formats, write them out, emboss them, sharpen them up, blur them out, and more. You can run this project just as you ran the two previous projectsjust compile them with the javac tool and run them with the java tool. NOTE You can download the complete source code for the Graphicizer applicationGraphicizer.javaat the Sams website. Also included is a sample image, image.gif.
|