这个AdjustmentListener怎么有问题啊

qinjinhua 2003-11-02 11:00:16
程序如下,但总是说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);
}
}
...全文
23 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,549

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧