Thursday, November 6, 2014

Java combobox pro



Insert Item At Specified Index In AWT Choice Or Combo box

import java.applet.Applet;
import java.awt.Choice;
public class InsertItemExample extends Applet
{
Choice language = null;
public void init()
{
language = new Choice();
language.add("Java");
language.add("C++");
language.add("VB");
language.add("Perl");
add(language);
language.insert("PHP",2);
 }
}

Remove All Items From AWT Choice Or Combo box

import java.applet.Applet;
import java.awt.Choice;
public class RemoveAllItemsExample extends Applet
{
Choice language = null;       
public void init()
{
language = new Choice();
language.add("Java");
language.add("C++");
language.add("VB");
language.add("Perl");
add(language);
language.removeAll();
   }
}

Remove Particular Item from AWT Choice Or Combo box

import java.applet.Applet;
import java.awt.Choice;
public class RemoveItemExample extends Applet
{
Choice language = null;     
public void init()
{
language = new Choice();
language.add("Java");
language.add("C++");
language.add("VB");
language.add("Perl");
add(language);  language.remove(1);
   }
}

Select Particular Item Of AWT Choice Or Combo box

import java.applet.Applet;
import java.awt.Choice;
public class SelectItemExample extends Applet
{
Choice language = null;
public void init()
{
language = new Choice();
language.add("Java");
language.add("C++");
language.add("VB");
language.add("Perl");
add(language); language.select(1);
   }
}

Colored Hello World Applet

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class ColoredHelloWorldExample extends Applet
{
public void paint(Graphics g)
{
      g.setColor(Color.blue);               
g.drawString("Hello World...",30,180);
   }
}

Convert HSB to RGB Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class ConvertHSBToRGBColor extends Applet
{
public void paint(Graphics g)
{
int rgb = Color.HSBtoRGB(0.6f,0.5f,0.8f);                
Color color = new Color(rgb);         
this.setForeground(color);       
g.drawString("Color converted from HSB to RGB",10,50);
   }
}

Convert RGB to HSB Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class ConvertRGBToHSBColor extends Applet
{
public void paint(Graphics g)
{
float[] hsbValues = new float[3];    
hsbValues = Color.RGBtoHSB(255,10,10,hsbValues);       
float hue, saturation, brightness;
hue = hsbValues[0];
saturation = hsbValues[1];
brightness = hsbValues[2];         
g.drawString("Hue: " + hue + ", Saturation:" + saturation
+ ", Brightness:" + brightness,10,50);
   }
}

No comments:

Post a Comment