//Toby Hsieh //Chapter 6, Exercise 3 //Control (x, y) of message import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class ch6ex3 extends Applet implements AdjustmentListener { private Scrollbar bar1, bar2; private int xValue=50; private int yValue=100; public void init() { Label title1, title2; title1=new Label("X Value:"); add(title1); bar1=new Scrollbar(Scrollbar.HORIZONTAL, 50, 1, 1, 201); add(bar1); bar1.addAdjustmentListener(this); title2=new Label(" Y Value:"); add(title2); bar2=new Scrollbar(Scrollbar.HORIZONTAL, 100, 1, 1, 201); add(bar2); bar2.addAdjustmentListener(this); } public void paint(Graphics g) { g.drawString("Now I'm at "+xValue+", "+yValue, xValue, yValue); } public void adjustmentValueChanged(AdjustmentEvent e) { xValue=bar1.getValue(); yValue=bar2.getValue(); repaint(); } }