3个回答
展开全部
//这个例题帮到你
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class simple extends JFrame implements AdjustmentListener{
public simple(){
setTitle("simple");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Container contentPane = getContentPane();
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2));
p.add(redLabel = new JLabel("Red 0"));
p.add(red = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
red.setBlockIncrement(16);
red.addAdjustmentListener(this);
p.add(greenLabel = new JLabel("Green 0"));
p.add(green = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
green.setBlockIncrement(16);
green.addAdjustmentListener(this);
p.add(blueLabel = new JLabel("Blue 0"));
p.add(blue = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
blue.setBlockIncrement(16);
blue.addAdjustmentListener(this);
contentPane.add(p, "South");
colorPanel = new JPanel();
colorPanel.setBackground(new Color(0, 0, 0));
contentPane.add(colorPanel, "Center");
}
public void adjustmentValueChanged(AdjustmentEvent evt){
redLabel.setText("Red " + red.getValue());
greenLabel.setText("Green " + green.getValue());
blueLabel.setText("Blue " + blue.getValue());
colorPanel.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));
colorPanel.repaint()
}
public static void main(String[] args){
JFrame f = new simple();
f.show();
}
private JLabel redLabel;
private JLabel greenLabel;
private JLabel blueLabel;
private JScrollBar red;
private JScrollBar green;
private JScrollBar blue;
private JPanel colorPanel;
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class simple extends JFrame implements AdjustmentListener{
public simple(){
setTitle("simple");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Container contentPane = getContentPane();
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2));
p.add(redLabel = new JLabel("Red 0"));
p.add(red = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
red.setBlockIncrement(16);
red.addAdjustmentListener(this);
p.add(greenLabel = new JLabel("Green 0"));
p.add(green = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
green.setBlockIncrement(16);
green.addAdjustmentListener(this);
p.add(blueLabel = new JLabel("Blue 0"));
p.add(blue = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
blue.setBlockIncrement(16);
blue.addAdjustmentListener(this);
contentPane.add(p, "South");
colorPanel = new JPanel();
colorPanel.setBackground(new Color(0, 0, 0));
contentPane.add(colorPanel, "Center");
}
public void adjustmentValueChanged(AdjustmentEvent evt){
redLabel.setText("Red " + red.getValue());
greenLabel.setText("Green " + green.getValue());
blueLabel.setText("Blue " + blue.getValue());
colorPanel.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));
colorPanel.repaint()
}
public static void main(String[] args){
JFrame f = new simple();
f.show();
}
private JLabel redLabel;
private JLabel greenLabel;
private JLabel blueLabel;
private JScrollBar red;
private JScrollBar green;
private JScrollBar blue;
private JPanel colorPanel;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询