这个AdjustmentListener怎么有问题啊
程序如下,但总是说hListener,vListener should be identifier,我不知道为什么,大家帮个忙,谢谢了:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Ajustment extends JFrame {
Icon icon = new ImageIcon("ZY023.JPG","java 2 exam notes");
JButton b = new JButton(icon);
JScrollPane pane = new JScrollPane(b);
AdjustmentListener hListener = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.println("Horizontal: ");
dumpInfo(e);
}
};
JScrollBar hBar = pane.getHorizontalScrollBar();
hBar.addAdjustmentListener(hListener);
AdjustmentListener vListener = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.println("Vertical: ");
dumpInfo(e);
}
};
JScrollBar vBar = pane.getHorizontalScrollBar();
vBar.addAdjustmentListener(vListener);
public Ajustment() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private static void dumpInfo(AdjustmentEvent e) {
System.out.println("\tValue: " + e.getValue());
String type = null;
switch (e.getAdjustmentType()) {
case AdjustmentEvent.TRACK:
type = "Track";
break;
case AdjustmentEvent.BLOCK_DECREMENT:
type = "Block Decrement";
break;
case AdjustmentEvent.BLOCK_INCREMENT:
type = "Block Increment";
break;
case AdjustmentEvent.UNIT_DECREMENT:
type = "Unit Decrement";
break;
case AdjustmentEvent.UNIT_INCREMENT:
type = "Unit Increment";
break;
}
System.out.println("\tType: " + type);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(600,400);
pane.setDebugGraphicsOptions(0);
pane.setBounds(new Rectangle(57, 65, 354, 260));
this.getContentPane().add(pane);
}
}