Wednesday, November 5, 2014

Java Checkbox pro



Change Checkbox Font

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.Font;
public class ChangeCheckboxFontExample extends Applet
{
public void init()
{
Checkbox checkbox1 = new Checkbox("Checkbox 1");
Checkbox checkbox2 = new Checkbox("Checkbox 2");         
Font myFont = new Font("Courier", Font.Italic,12);
checkbox1.setFont(myFont);
add(checkbox1);
add(checkbox2);
  }
}

Change Checkbox Foreground Color

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.Color;
public class ChangeCheckboxForegroundExample extends Applet
{
public void init()
{
Checkbox checkBox1 = new Checkbox("Checkbox 1");
Checkbox checkBox2 = new Checkbox("Checkbox 2");       
checkBox1.setForeground(Color.magenta);
checkBox2.setForeground(Color.blue);
add(checkBox1);
add(checkBox2);
  }
}

Create AWT Checkbox

import java.applet.Applet;
import java.awt.Checkbox;
public class CreateCheckBox extends Applet
public void init()
{
Checkbox checkBox1 = new Checkbox();checkBox1.setLabel("My Checkbox 1");Checkbox checkbox2 = new Checkbox("My Checkbox 2");
add(checkBox1);
add(checkbox2);
  }
}

Create Checked Checkbox

import java.applet.Applet;
import java.awt.Checkbox;
public class CreateCheckedCheckBox extends Applet
{
public void init()
{
Checkbox checkBox1 = new Checkbox("My Checkbox 1"); Checkbox checkbox2 = new Checkbox("My Checkbox 2", true);
add(checkBox1);
add(checkbox2);
   }
}

Determine If The Checkbox Is Enabled

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Checkbox;
public class DetermineIfCheckboxEnabled extends Applet
{   
boolean isCheckbox1Enabled;
boolean isCheckbox2Enabled;
public void init()
{
Checkbox Checkbox1 = new Checkbox("Checkbox 1");
Checkbox Checkbox2 = new Checkbox("Checkbox 2");
add(Checkbox1);
add(Checkbox2);
Checkbox1.setEnabled(false);
isCheckbox1Enabled = Checkbox1.isEnabled();
isCheckbox2Enabled = Checkbox2.isEnabled();               
}
public void paint(Graphics g)
{
g.drawString("Is Checkbox 1 enabled? " + isCheckbox1Enabled, 10,50);
g.drawString("Is Checkbox 2 enabled? " + isCheckbox2Enabled, 10,70);
  }
}

Determine If The Checkbox Is Visible

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Checkbox;
public class DetermineIfCheckboxVisible extends Applet
{
boolean isCheckbox1Visible;
boolean isCheckbox2Visible;
public void init()
{
Checkbox Checkbox1 = new Checkbox("Checkbox 1");
Checkbox Checkbox2 = new Checkbox("Checkbox 2");
add(Checkbox1);
add(Checkbox2);
Checkbox2.setVisible(false);
isCheckbox1Visible = Checkbox1.isVisible();
isCheckbox2Visible = Checkbox2.isVisible();
}
public void paint(Graphics g)
{
g.drawString("Is Checkbox 1 visible? " + isCheckbox1Visible, 10,50);
g.drawString("Is Checkbox 2 visible? " + isCheckbox2Visible, 10,70);
   }
}

Disable Checkbox

import java.applet.Applet;
import java.awt.Checkbox;
public class DisableCheckboxExample extends Applet
{
public void init()
{
Checkbox Checkbox1 = new Checkbox("Checkbox 1");
Checkbox Checkbox2 = new Checkbox("Checkbox 2");
add(Checkbox1);
add(Checkbox2);
Checkbox2.setEnabled(false);
   }
}

No comments:

Post a Comment