A Java Program to display diffrent windows Background using an applet class

/*By clicking on the button you can change your windows backgraound as your wish*/

package p1;

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class SetBackground extends Applet implements ActionListener {
	Button b1,b2,b3,b4;
	String s="Please click the button for new Background",s2;
	Font f1,f2,f3;
public void init() {
	f1 = new Font("Arial",Font.BOLD,18);    
    f2 = new Font("Forte",Font.PLAIN,24);    
    f3 = new Font("Elephant",Font.ITALIC,28);
	b1=new Button("Blue");
	b2=new Button("Green");
	b3=new Button("Cyan");
	b4=new Button("Red");
	add(b1);
	add(b2);
	add(b3);
	add(b4);
	b1.addActionListener(this);
	b2.addActionListener(this);
	b3.addActionListener(this);
	b4.addActionListener(this);
}
public void paint(Graphics g) {
	g.setFont(f1);
	g.drawString(s,30,40);
	g.setFont(f3);
	g.drawString(s2,150,250);
}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String k=e.getActionCommand();
		if(k.equals("Blue")) {
			setBackground(Color.blue);
			s2="This is Blue Color Background";
		}
		if(k.equals("Green")) {
			setBackground(Color.green);
			s2="This is Green Color Background";
		}
		if(k.equals("Cyan")) {
			setBackground(Color.cyan);
			s2="This is Cyan Color Background";
		}
		if(k.equals("Red")) {
			setBackground(Color.red);
			s2="This is Red Color Background";
		}
			
		}
		
		
	}
View all posts

Published by temamhashim

This is Temam Hashim certified Software Engineer from top leading University with highest score with full capablity of various top leading programming language as a software Engineer and ability to deal with logic and mathimatical problem.

Leave a comment

Design a site like this with WordPress.com
Get started