How do I change the background color in an applet?
In this program, we will learn to create a page using an applet and on that page, there will be three buttons to change the color of the background by clicking on that button. The default color of the background will be Black and when If we click on the red button then the background color will change into red, if we click on the yellow button the background color will change into yellow and if we click on the green button then the background color will change into the green.
color changer |
Source Code: Program to set background and foreground color of an Applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Color;
class ColourChange extends Applet implements ActionListener
{
Frame f;
/* public void init()
{
f.setbackground(Color.pink);
}
*/
Button b1,b2,b3;
ColourChange()
{
f=new Frame("Colour");
b1=new Button("red");
b2=new Button("yellow");
b3=new Button("green");
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
f.setBackground(Color.black);
f.add(b1);
f.add(b2);
f.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(b1))
{
f.setBackground(Color.red);
}
if(e.getSource().equals(b2))
{
f.setBackground(Color.yellow);
}
if(e.getSource().equals(b3))
{
f.setBackground(Color.green);
}
}
public static void main(String...aa)
{
new ColourChange();
}
}
COMPLETED PROJECTS:
- How to Create Forgot System Password with PHP & MySQL
- Datatables Editable Add Delete with Ajax, PHP & MySQL-My programming school
- Download Login and Registration form in PHP & MySQL-MPS
- Export Data to Excel in Php Code -My programming school
- Hospital Database Management System with PHP MySQL
- Java projects for beginners | java developer software | UML diagram
- Traffic Light using Applet in Java | algorithm and source code
- Currency converter using java
- Java program to design simple calculator with the use of grid layout
- Simple Notepad Editor using java|Gui application
- Online quiz application using java GUI with complete source code
- How to create color changer mini-project using java applet with source code
- How to make a Calculator using java Swing, GUI
- Canteen food order, generate total bill using java swing
- Currency Convertor java project, swing component
- Python Number Guessing Game mini Project
See my more website
バイアグラ еЂ¤ж®µ – г‚·гѓ«гѓ‡гѓЉгѓ•г‚Јгѓ«йЂљиІ© г‚їгѓЂгѓ©гѓ•г‚Јгѓ«гЃ®иіје…Ґ