Focus listeners

A focus listener can listen for when a field comes into focus or goes out of focus. For example, if a program user types a value into the width field, then moves the cursor out of that field, the field will lose focus and a focus listener on the width field can update the height field to an appropriate value.

Adding scale components to the toolbar

ImageResizer can now load and save images pretty well. Next, add code to scale and crop the image. First, set up the user interface.

  1. Add a private double instance variable called ratio, initialized to 1.0.
  2. Add private JTextFields called scaleWField and scaleHField, each with an initial value of "1" and a size of 5.
  3. Add private JTextFields called cropXField, cropYField, cropWField, and cropHField, each with an initial value of “0” and a size of 5.
    ...
 
  private ImagePanel imagePanel = new ImagePanel(this);
  private File file = new File("/usercode/");
  _________ ratio = _________;
  
  _________ scaleWField = _________;
  _________ scaleHField = _________;
  _________ cropXField = _________;
  _________ cropYField = _________;
  _________ cropWField = _________;
  _________ cropHField = _________;
 
    ...

Get hands-on with 1200+ tech skills courses.