Crop the Image
Learn to crop the image and update the scale values on cropping it.
We'll cover the following
Cropping the image
Next, add code for when the “Crop” tool button is clicked.
- In
initGUI()
, add an action listener tocropButton
to callcrop()
when the button is clicked. (Use JButton’saddActionListener()
method, with a newActionListener
object as the parameter value. In theActionListener
, add a public method calledactionPerformed()
. TheactionPerformed()
method should have one parameter, an ActionEvent, and return nothing. InactionPerformed()
, callcrop()
.
Note: Do not jump into execution yet. The code will have a syntax error because crop()
does not exist yet.
...
public void initGUI() {
...
// crop options
JButton cropButton = new JButton(cropIcon);
cropButton.setToolTipText("Crop Image");
cropButton.addActionListener(__________________ {
_______________ actionPerformed(_____________) {
___________();
}
});
toolbar.add(cropButton);
...
Get hands-on with 1200+ tech skills courses.