Get Available
Font Family Names
import
java.applet.Applet;
import
java.awt.Graphics;
import
java.awt.GraphicsEnvironment;
public class
GetAvailableFonts extends Applet
{
public void
paint(Graphics g)
{
GraphicsEnvironment
graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontNames[] =
graphicsEnvironment.getAvailableFontFamilyNames();
int y = 20;
for(int i=0; i <
fontNames.length; i++)
{
g.drawString(fontNames[i],
10, y);
y += 20;
}
}
}
Get Available Font
Objects
import
java.applet.Applet;
import java.awt.Font;
import
java.awt.Graphics;
import
java.awt.GraphicsEnvironment;
public class
GetAllFontObjectsExample extends Applet
{
public void
paint(Graphics g)
{
GraphicsEnvironment
graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
Font fonts[] =
graphicsEnvironment.getAllFonts();
int y = 20;
for(int i=0; i <
fonts.length; i++)
{
g.drawString(fonts[i].getName(),
10, y);
y += 20;
}
}
}
Get Font Information
import
java.applet.Applet;
import java.awt.Font;
import
java.awt.Graphics;
public class
GetFontInformation extends Applet
{
public void
paint(Graphics g)
{
Font currentFont =
g.getFont();
String fontName =
currentFont.getName();
int size = currentFont.getSize();
int style =
currentFont.getStyle();
String fontStyle =
"";
if( (style &
Font.Bold) == Font.Bold)
fontStyle =
"Bold";
if( (style &
Font.Italic) == Font.Italic)
fontStyle =
"Italic";
if( (style &
Font.Plain) == Font.Plain)
fontStyle =
"Plain";
String family =
currentFont.getFamily();
g.drawString("Font
Name: " + fontName, 10, 30);
g.drawString("Font
size: " + size, 10, 50);
g.drawString("Font
Family: " + family, 10, 70);
g.drawString("Font
Style: " + fontStyle, 10, 90);
}
}
Hide Checkbox
import
java.applet.Applet;
import java.awt.Checkbox;
public class
HideCheckboxExample extends Applet
{
public void init()
{
Checkbox Checkbox1 =
new Checkbox("Checkbox 1");
Checkbox Checkbox2 =
new Checkbox("Checkbox 2");
add(Checkbox1);
add(Checkbox2);
Checkbox2.setVisible(false);
}
}
Remove AWT
Checkbox From Applet or Window Frame
import
java.applet.Applet;
import
java.awt.Checkbox;
public class
RemoveCheckboxExample extends Applet
{
public void init()
{
Checkbox Checkbox1 =
new Checkbox("Checkbox 1");
Checkbox Checkbox2 =
new Checkbox("Checkbox 2");
add(Checkbox1);
add(Checkbox2);
remove(Checkbox1);
}
}
No comments:
Post a Comment