Иллюстрированный самоучитель по Java


         

class ApplyColor implements ActionListener


Label Middle = new Label("127", Label.RIGHT); 
lmiddle.setBounds(0, 120, 30, 30); p.add(Imiddle); 
Label Iroax = new Label("255", Label.RIGHT); 
Imax.setBoundsfO, 200, 30, 30); p.add(lraax);
sbRed.setBackground(Color.red); 
sbRed.setBounds(40, 30, 20, 200); p.add(sbRed); 
sbRed.addAdjustmentListener(new ChColorO);
sbGreen.setBackground(Color.green); 
sbGreen.setBounds(70, 30, 20, 200); p.add(sbGreen); 
sbGreen.addAdjustmentListener(new ChColor());
sbBlue.setBackground(Color.blue); 
sbBlue.setBoundsds (100, 30, 20, 200); p.add(sbBlue); 
sbBlue.addAdjustmentListener(new ChColor());
Label Ip = new Label("Образец:"); 
lp.setBoundS(250, 50, 120, 30); add(lp);
1m.setBackground(new Color(127, 127, 127)); 
Im.setBounds(220, 80, 120, 80); add(lm);
bl.setBounds(240, 200, 100, 30); add(bl); 
bl.addActionListener(new ApplyColor());
b2.setBounds(240, 240, 100, 30); add(b2); 
b2.addActionListener(new CancelColor());
setSize(400, 300); setVisible(true); )
class ChColor implements AdjustmentListener{
public void adjustmentValueChanged(AdjustmentEvent e){
int red = с.getRed(), green = с.getGreen(), blue = с.getBlue(); 
if (e.getAdjustable() == sbRed) red = e.getValue(); 
else if (e.getAdjustablet) == sbGreen) green = e.getValue(); 
else if (e.getAdjustable() == sbBlue) blue = e.getValue(); 
с = new Color(red, green, blue); 
lm.setBackground(c); 


class ApplyColor implements ActionListener {
public void actionPerformed(ActionEvent ae){
setBackground(c); 

}
class CancelColor implements ActionListener {
public void actionPerformed(ActionEvent ae){ 
с = new Color(127, 127, 127);
sbRed.setValue(127); 
sbGreen.setValue(127); 
sbBlue.setValue(127); 
lm.setBackground(c); 
setBackground(Color.white); 


public static void main(String[] args){
Frame f = new ScrollTestl(" Выбор цвета"); 
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent ev){ 
System.exit(0);
}
});
}
}

Содержание  Назад  Вперед