📄 scrollbar.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/*
<APPLET
CODE=scrollbar.class
WIDTH=300
HEIGHT=200 >
</APPLET>
*/
public class scrollbar extends JApplet
{
private JScrollBar vsb = new JScrollBar(JScrollBar.VERTICAL, 0,
0, 0, 180);
private jpanel j = new jpanel();
public void init()
{
Container contentPane = getContentPane();
contentPane.add(j, BorderLayout.CENTER);
contentPane.add(vsb, BorderLayout.EAST);
vsb.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(
AdjustmentEvent e) {
JScrollBar sb = (JScrollBar)e.getSource();
j.setScrolledPosition(e.getValue());
j.repaint();
}
});
}
}
class jpanel extends JPanel
{
JLabel jlabel = new JLabel("Hello from Swing!");
int y = 0;
jpanel()
{
jlabel = new JLabel("Hello from Swing!");
add(jlabel);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
jlabel.setLocation(0, y);
}
public void setScrolledPosition(int newposition)
{
y = newposition;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -