كود لطباعة الالوان
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//start class
class chat extends JFrame{
boolean boldflage;
boolean italicflage;
int green;
int blue;
int red;
JButton b1=new JButton("Red");
JButton b2=new JButton("Green");
JButton b3=new JButton("Blue");
JButton b4=new JButton("Black");
JPanel button=new JPanel(new GridLayout(5,1));
Container c= getContentPane();
JTextArea ta=new JTextArea();
JScrollPane sp=new JScrollPane(ta);
JScrollBar sb1=new JScrollBar(JScrollBar.HORIZONTAL,40,15,0,270);
JScrollBar sb2=new JScrollBar(JScrollBar.HORIZONTAL,40,15,0,270);
JScrollBar sb3=new JScrollBar(JScrollBar.HORIZONTAL,40,15,0,270);
JPanel sbar=new JPanel(new GridLayout(3,1));
JToolBar jtb=new JToolBar();
JPanel toollbar=new JPanel();
chat(){
button.add(b1);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent AE){
ta.setBackground(Color.red);
}
});
button.add(b2);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent AE){
ta.setBackground(Color.green);
}
});
button.add(b3);
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent AE){
ta.setBackground(Color.blue);
}
});
button.add(b4);
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent AE){
ta.setBackground(Color.black);
}
});
sb1.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e){
green=e.getValue();
ta.setBackground(new Color(green,red,blue));
colorChange();
}
});
sb2.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e){
red=e.getValue();
ta.setBackground(new Color(green,red,blue));
colorChange();
}
});
sb3.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e){
blue=e.getValue();
ta.setBackground(new Color(green,red,blue));
colorChange();
}
});
////////////////////////////////////
///////////////////////////////////////
sbar.add(sb1);
sbar.add(sb2);
sbar.add(sb3);
toollbar.add(jtb);
c.add(BorderLayout.SOUTH,sbar);
c.add(BorderLayout.EAST,button);
c.add(BorderLayout.CENTER,sp);
c.add(BorderLayout.NORTH,jtb);
pack();
setVisible(true);
setSize(200,250);
setTitle("Ashraf Elsheikh");
}
public static void main(String[]args){
new chat();
}
public void colorChange(){
if((green+blue+red)>=350)
ta.setForeground(Color.black);
else
ta.setForeground(Color.white);
}
}وشكرا