the the the Master Cheater
Reputation: 46
Joined: 15 Jun 2008 Posts: 429
|
Posted: Sun Feb 06, 2011 2:59 pm Post subject: java bgcolor help |
|
|
these dont change the color of the background
| Code: | import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class dcmall extends Applet implements ActionListener
{
// Variables
int height = 200;
int width = 200;
Checkbox redBG, blueBG, greenBG, cyanBG, magentaBG, whiteBG, orangeBG, yellowBG, blackBG, grayBG; // background color
CheckboxGroup cbgBGColor;
Label BGColor;
public void init()
{
resize(width, height);
setLayout(new FlowLayout(FlowLayout.CENTER));
cbgBGColor = new CheckboxGroup();
redBG = new Checkbox("RedBG", cbgBGColor, false);
blueBG = new Checkbox("BlueBG", cbgBGColor, false);
greenBG = new Checkbox("GreenBG", cbgBGColor, false);
cyanBG = new Checkbox("CyanBG", cbgBGColor, false);
magentaBG = new Checkbox("MagentaBG", cbgBGColor, false);
whiteBG = new Checkbox("WhiteBG", cbgBGColor, true);
orangeBG = new Checkbox("OrangeBG", cbgBGColor, false);
yellowBG = new Checkbox("YellowBG", cbgBGColor, false);
blackBG = new Checkbox("BlackBG", cbgBGColor, false);
grayBG = new Checkbox("GrayBG", cbgBGColor, false);
BGColor = new Label("Background Color:");
add(BGColor);
add(redBG);
add(blueBG);
add(greenBG);
add(cyanBG);
add(magentaBG);
add(whiteBG);
add(orangeBG);
add(yellowBG);
add(blackBG);
add(grayBG);
}
public boolean action(Event e, Object arg)
{
if(e.target instanceof Checkbox)
{
repaint();
return true;
}
Checkbox currentCheckbox=(Checkbox)e.target;
boolean checkboxState = currentCheckbox.getState();
if (currentCheckbox.getLabel() == "RedBG")
if (checkboxState)
{
setBackground(Color.red);
}
if (currentCheckbox.getLabel() == "BlueBG")
if (checkboxState)
{
setBackground(Color.blue);
}
if (currentCheckbox.getLabel() == "GreenBG")
if (checkboxState)
{
setBackground(Color.green);
}
if (currentCheckbox.getLabel() == "CyanBG")
if (checkboxState)
{
setBackground(Color.cyan);
}
if (currentCheckbox.getLabel() == "MagentaBG")
if (checkboxState)
{
setBackground(Color.magenta);
}
if (currentCheckbox.getLabel() == "WhiteBG")
if (checkboxState)
{
setBackground(Color.white);
}
if (currentCheckbox.getLabel() == "OrangeBG")
if (checkboxState)
{
setBackground(Color.orange);
}
if (currentCheckbox.getLabel() == "YellowBG")
if (checkboxState)
{
setBackground(Color.yellow);
}
if (currentCheckbox.getLabel() == "BlackBG")
if (checkboxState)
{
setBackground(Color.black);
}
if (currentCheckbox.getLabel() == "GrayBG")
if (checkboxState)
{
setBackground(Color.gray);
}
repaint();
return true;
}
}
|
|
|