Add to Favorites    Make Home Page 447 Online  
 Language Categories  
 Our Services  

Home » Java Home » Beginners / Lab Assignments Home » set the foreground and background color to the text area

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title set the foreground and background color to the text area
Author Bharathi
Author Email bharathi_tr [at] yahoo.com
Description this program demonstrates the awt chechbox control and the layouts
Category Java » Beginners / Lab Assignments
Hits 365480
Code Select and Copy the Code
import java.awt.*; import java.awt.event.*; import java.applet.*; class colopat extends Frame { Checkbox r,g,b; Checkbox m,y,gr,p,w,bl,c; TextArea ta; Checkbox r1,g1,b1; Checkbox m1,y1,gr1,p1,w1,bl1,c1; Label ba,fo; Panel pa1,p2,p3; colopat() { setSize(800,600); setLayout(new BorderLayout()); pa1=new Panel(new GridLayout(5,2,10,10)); p2=new Panel(new GridLayout(5,2,10,10)); CheckboxGroup cbg=new CheckboxGroup(); r=new Checkbox("red",cbg,false); g=new Checkbox("green",cbg,false); b=new Checkbox("blue",cbg,false); m=new Checkbox("megenta",cbg,false); y=new Checkbox("yellow",cbg,false); gr=new Checkbox("grey",cbg,false); p=new Checkbox("pink",cbg,false); w=new Checkbox("white",cbg,false); bl=new Checkbox("black",cbg,true); c=new Checkbox("cyan",cbg,false); ba=new Label("BACKGROUND COLORS",Label.CENTER); ba.setBackground(Color.pink); pa1.add(ba); pa1.add(r); pa1.add(b); pa1.add(m); pa1.add(y); pa1.add(gr); pa1.add(p); pa1.add(w); pa1.add(bl); pa1.add(c); add("West",pa1); ta=new TextArea(5,25); p3=new Panel(new GridLayout(3,1)); p3.add(new Label("Text Area",1)); p3.add(ta); add("Center",p3); r.addItemListener(new CheckBoxHandler(this)); g.addItemListener(new CheckBoxHandler(this)); b.addItemListener(new CheckBoxHandler(this)); m.addItemListener(new CheckBoxHandler(this)); y.addItemListener(new CheckBoxHandler(this)); gr.addItemListener(new CheckBoxHandler(this)); p.addItemListener(new CheckBoxHandler(this)); w.addItemListener(new CheckBoxHandler(this)); c.addItemListener(new CheckBoxHandler(this)); bl.addItemListener(new CheckBoxHandler(this)); CheckboxGroup cbg1=new CheckboxGroup(); r1=new Checkbox("red",cbg1,false); g1=new Checkbox("green",cbg1,false); b1=new Checkbox("blue",cbg1,false); m1=new Checkbox("megenta",cbg1,false); y1=new Checkbox("yellow",cbg1,false); gr1=new Checkbox("grey",cbg1,false); p1=new Checkbox("pink",cbg1,false); w1=new Checkbox("white",cbg1,false); bl1=new Checkbox("black",cbg1,true); c1=new Checkbox("cyan",cbg1,false); fo=new Label("FOREGROUND COLORS"); fo.setBackground(Color.pink); p2.add(fo); p2.add(c1); p2.add(g1); p2.add(b1); p2.add(m1); p2.add(y1); p2.add(gr1); p2.add(p1); p2.add(w1); p2.add(bl1); p2.add(c1); add("East",p2); r1.addItemListener(new CheckBoxHandler(this)); g1.addItemListener(new CheckBoxHandler(this)); b1.addItemListener(new CheckBoxHandler(this)); m1.addItemListener(new CheckBoxHandler(this)); y1.addItemListener(new CheckBoxHandler(this)); gr1.addItemListener(new CheckBoxHandler(this)); p1.addItemListener(new CheckBoxHandler(this)); w1.addItemListener(new CheckBoxHandler(this)); c1.addItemListener(new CheckBoxHandler(this)); bl1.addItemListener(new CheckBoxHandler(this)); c1.addItemListener(new CheckBoxHandler(this)); addWindowListener(new mywindowAdapter(this)); setVisible(true); } public static void main(String args[]) { new colopat(); } } class CheckBoxHandler implements ItemListener { colopat cp; CheckBoxHandler(colopat cp) { this.cp=cp; } public void itemStateChanged(ItemEvent ie) { if(cp.r.getState()) cp.ta.setBackground(Color.red); else if(cp.g.getState()) cp.ta.setBackground(Color.green); else if(cp.b.getState()) cp.ta.setBackground(Color.blue); else if(cp.m.getState()) cp.ta.setBackground(Color.magenta); else if(cp.y.getState()) cp.ta.setBackground(Color.yellow); else if(cp.gr.getState()) cp.ta.setBackground(Color.lightGray); else if(cp.bl.getState()) cp.ta.setBackground(Color.black); else if(cp.w.getState()) cp.ta.setBackground(Color.white); else if(cp.p.getState()) cp.ta.setBackground(Color.pink); else cp.ta.setBackground(Color.cyan); if(cp.r1.getState()) cp.ta.setForeground(Color.red); else if(cp.g1.getState()) cp.ta.setForeground(Color.green); else if(cp.b1.getState()) cp.ta.setForeground(Color.blue); else if(cp.m1.getState()) cp.ta.setForeground(Color.magenta); else if(cp.y1.getState()) cp.ta.setForeground(Color.yellow); else if(cp.gr1.getState()) cp.ta.setForeground(Color.lightGray); else if(cp.bl1.getState()) cp.ta.setForeground(Color.black); else if(cp.w1.getState()) cp.ta.setForeground(Color.white); else if(cp.p1.getState()) cp.ta.setForeground(Color.pink); else cp.ta.setForeground(Color.cyan); } } class mywindowAdapter extends WindowAdapter { colopat cp; mywindowAdapter(colopat cp) { this.cp=cp; } public void windowClosing(WindowEvent e) { System.exit(0); } }

Related Source Codes

Script Name Author
Sending mail Using JavaMail to Yahoo and Gmail accounts sai prasad
Simple Program in Java to Implement Multithreading Satish.K
Simple Calculator in Java Using Remote Method Invocation Satish.K
Guest Book Application Using Servlets Satish.K
String Manipulation Using Stringification Satish.K
String Manipulation Using Stringification Satish.K
Moving Ball Application Using Java Beans Satish.K
Rapid Roll game subrahmanyeswararao
student mgm arpan
Sourav Datta
Download Manager Sagar
Address Book in Java Rahul Chouhan
address book using java database connectivity(jdbc-msaccess) shekhar bansal
sun Steganography B.Rajavel
Connecting Java with MS-Access - Inserting data in Aseem

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=612


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review