1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| package com.progiciel.visual;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
public class VisualVisualisation extends JPanel {
private JLabel label;
public VisualVisualisation(){
super(true);
label=new JLabel();
setLayout(new BorderLayout());
JScrollBar hbar = new JScrollBar(
JScrollBar.HORIZONTAL, 30, 20, 0, 500);
JScrollBar vbar = new JScrollBar(
JScrollBar.VERTICAL, 30, 40, 0, 500);
hbar.setUnitIncrement(2);
hbar.setBlockIncrement(1);
hbar.addAdjustmentListener(new MyAdjustmentListener());
vbar.addAdjustmentListener(new MyAdjustmentListener());
add(hbar, BorderLayout.SOUTH);
add(vbar, BorderLayout.EAST);
add(getLabel(), BorderLayout.CENTER);
add(getLabel2(),BorderLayout.CENTER);
}
JLabel getLabel(){
label.setText("ok");
return label;
}
JLabel getLabel2(){
JLabel lab =new JLabel("salut");
lab.setLocation(10, 10);
return lab;
}
class MyAdjustmentListener implements AdjustmentListener {
public void adjustmentValueChanged(AdjustmentEvent e) {
label.setText(" New Value is " + e.getValue() + " ");
repaint();
}
}
public static void main(String s[]) {
JFrame frame = new JFrame("Scroll Bar Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new VisualVisualisation());
frame.setSize(200,200);
frame.setVisible(true);
}
} |
Partager