الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود يطبع الالوان بالجافا

مغلق
بدأه دون سيلفاتور في 21 أبريل 2004 · 2 رد · 568 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

كود لطباعة الالوان

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);
          }
       	 
	}

وشكرا

abo_alzobaer@hotmail.com

#2

mgazif

it is an Interesting code ...

i have 2 comments

One …

There should be some documentation …

Two ..

It will be nice if we click button that the sliding bar will adjust to that color ..

Also if you can increase the size of the GUI

Other than that the code is wonderful

#3

من هذه الناحيه على الاعضاء المشاركه وتطوير البرنامج

abo_alzobaer@hotmail.com

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…