scrollborder.java
来自「java程序设计 清华出版社 孙燮华老师编写的程序源代码」· Java 代码 · 共 72 行
JAVA
72 行
//scrollborder.java
import java.awt.*;
import java.awt.event.*;
public class scrollborder extends Frame implements AdjustmentListener{
Scrollbar hScroll1, hScroll2, vScroll1, vScroll2;
textPanel Panel1;
public scrollborder(){
setLayout(new BorderLayout());
hScroll1 = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 200);
add("North", hScroll1);
hScroll1.addAdjustmentListener(this);
vScroll1 = new Scrollbar(Scrollbar.VERTICAL, 1, 1, 1, 200);
add("West", vScroll1);
vScroll1.addAdjustmentListener(this);
hScroll2 = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 200);
add("South", hScroll2);
hScroll2.addAdjustmentListener(this);
vScroll2 = new Scrollbar(Scrollbar.VERTICAL, 1, 1, 1, 200);
add("East", vScroll2);
vScroll2.addAdjustmentListener(this);
Panel1 = new textPanel();
add("Center", Panel1);
Panel1.Text1.setLocation(0, 0);
setSize(200, 200);
setVisible(true);
}
public void adjustmentValueChanged(AdjustmentEvent e){
if(e.getAdjustable() == hScroll1){
hScroll1.setValue(hScroll1.getValue());
hScroll2.setValue(hScroll1.getValue());
Panel1.Text1.setText("Horizontal location: " +
hScroll1.getValue());
}
if(e.getAdjustable() == vScroll1){
vScroll1.setValue(vScroll1.getValue());
vScroll2.setValue(vScroll1.getValue());
Panel1.Text1.setText("Vertical location: " +
vScroll1.getValue());
}
if(e.getAdjustable() == hScroll2){
hScroll2.setValue(hScroll2.getValue());
hScroll1.setValue(hScroll2.getValue());
Panel1.Text1.setText("Horizontal location: " +
hScroll2.getValue());
}
if(e.getAdjustable() == vScroll2){
vScroll2.setValue(vScroll2.getValue());
vScroll1.setValue(vScroll2.getValue());
Panel1.Text1.setText("Vertical location: " + vScroll2.getValue());
}
}
public static void main(String args[]){
scrollborder scroll=new scrollborder();
}
}
class textPanel extends Panel{
TextField Text1;
textPanel(){
Text1 = new TextField(20);
add(Text1);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?