Oval size changer

This is a solution to the first exercise in the Events Assignment.

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class OvalSizer extends Applet implements AdjustmentListener
{

int height=50, width=50;
Scrollbar heightScroller, widthScroller;
Label diameter2, diameter1;
public void init()
{

// Instatiate and add the scrollbars
diameter1 = new Label("Adjust height");
add(diameter1);
heightScroller = new Scrollbar(Scrollbar.VERTICAL,0,1,10,100);
add(heightScroller);
diameter2 = new Label("Adjust width");
add(diameter2);
widthScroller = new Scrollbar(Scrollbar.HORIZONTAL,0,1,10,100);
add(widthScroller);
// Listen for the events
widthScroller.addAdjustmentListener(this);
heightScroller.addAdjustmentListener(this);

}
public void paint (Graphics g)
{

// Paint the oval
g.fillOval(100, 100, width, height);

}
public void adjustmentValueChanged(AdjustmentEvent e)
{

// Pass scrollbar changes back to variables and repaint screen
width = widthScroller.getValue();
height = heightScroller.getValue();
repaint();

}

}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License