package demo03;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollBar;
import java.awt.Font;
import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
public class Gundong {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Gundong window = new Gundong();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Gundong() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
final JLabel lblNewLabel = new JLabel("\u663E\u793A\u989C\u8272");
lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 17));
lblNewLabel.setBounds(157, 54, 121, 32);
frame.getContentPane().add(lblNewLabel);
final JScrollBar scrollBar = new JScrollBar();
scrollBar.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent arg0) {
int n = scrollBar.getValue(); //获取滚动条的值
lblNewLabel.setForeground(new Color(255,0,n));
}
});
scrollBar.setMaximum(255);
scrollBar.setOrientation(JScrollBar.HORIZONTAL);
scrollBar.setBounds(77, 137, 251, 24);
frame.getContentPane().add(scrollBar);
final JScrollBar scrollBar_1 = new JScrollBar();
scrollBar_1.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
int n = scrollBar_1.getValue(); //获取滚动条的值
lblNewLabel.setForeground(new Color(0,255,n));
}
});
scrollBar_1.setOrientation(JScrollBar.HORIZONTAL);
scrollBar_1.setMaximum(255);
scrollBar_1.setBounds(77, 183, 251, 24);
frame.getContentPane().add(scrollBar_1);
final JScrollBar scrollBar_2 = new JScrollBar();
scrollBar_2.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
int n = scrollBar_2.getValue(); //获取滚动条的值
lblNewLabel.setForeground(new Color(0,n,255));
}
});
scrollBar_2.setOrientation(JScrollBar.HORIZONTAL);
scrollBar_2.setMaximum(255);
scrollBar_2.setBounds(77, 227, 251, 24);
frame.getContentPane().add(scrollBar_2);
JLabel lblNewLabel_1 = new JLabel("\u7EA2\u8272");
lblNewLabel_1.setBounds(10, 146, 54, 15);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("\u7EFF\u8272");
lblNewLabel_2.setBounds(10, 192, 54, 15);
frame.getContentPane().add(lblNewLabel_2);
JLabel label = new JLabel("\u84DD\u8272");
label.setBounds(10, 236, 54, 15);
frame.getContentPane().add(label);
}
}
Swing写一个滚动变化颜色
最新推荐文章于 2023-08-02 13:32:50 发布