Thursday, November 6, 2014

Java mode of color pro



Get Transparency Mode of Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class GetTransparencyMode extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(255,10,10);
int transparency = customColor.getTransparency();
g.drawString("Transparency mode : " + transparency, 10,50);
   }
}

Print Hello World in an Applet in different Colors
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class HelloWorldInDifferentColorsExample extends Applet
{
public void paint(Graphics g)
{
Color c[] = {Color.blue,Color.cyan, Color.darkGray, Color.gray,
Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink,
Color.red, Color.white, Color.yellow};
for(int  i = 0; i
{
g.setColor(c[i]);
g.drawString("Hello World...",10,10 + (i*10));
    }
  }
}

Set Drawing Mode to XOR

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class SetXORPaintModeExample extends Applet
{
public void paint(Graphics g)
{
g.setXORMode(Color.Gray);
g.fillRect(10,10,50,50);
g.fillRect(20,30,50,50);
g.setPaintMode();
   }
}

Set Graphics Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class SetGraphicsColorExample extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(10,10,255);
g.setColor(customColor);
g.drawLine(10,10,30,30);
g.setColor(Color.red);
g.fillRect(40,40,40,40);
g.setColor(Color.green);
g.fillRect(80,80,40,40);
g.draw3DRect(81,81,40,40,true);
    }
}
Create Bold Font

import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
public class CreateBoldFontExample extends Applet
{
public void paint(Graphics g)
{
Font myFont = new Font("Courier", Font.Bold,20);
g.setFont(myFont);
g.drawString("Bold Font Example", 10, 50);
   }
}

Create Bold and Italic Font

import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
public class CreateBoldItalicFontExample extends Applet
{
public void paint(Graphics g)
{
Font myFont = new Font("Courier", Font.Bold,  Font.Italic ,20);
g.setFont(myFont);
g.drawString("Bold & Italic Font Example", 10, 50);
    }
}

Create Font Object

import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
public class CreateFontObjectExample extends Applet
{
public void paint(Graphics g)
{
Font myFont = new Font("Courier", Font.Plain,20);
g.setFont(myFont);               
g.drawString("Create Font Example", 10, 50);
   }
}

Create Italic Font

import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
public class CreateItalicFontExample extends Applet
{
public void paint(Graphics g)
{
Font myFont = new Font("Courier", Font.Italic,20);
g.setFont(myFont);
g.drawString("Italic Font Example", 10, 50);
   }
}

No comments:

Post a Comment