import java.applet.Applet;
import java.awt.Graphics;
public class DrawSCB extends Applet {
private String s = "web programming";
private char c[] = {'c','h','a','r','s',' ','8'};
private byte b[] = {'b','y','t','e',1,2,3};
public void paint (Graphics g)
{
// writes the string at position x=100, y=25
g.drawString(s, 100, 25);
// writes characters 1,2,3 [har] at position x=100, y=50
g.drawChars (c, 1, 3, 100, 50);
// writes bytes 0,1,2,3,4 [byte1] at position x=100, y=75
g.drawBytes(b, 0, 5, 100, 75);
}
}
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class ShowColors extends Applet {
private int red, green, blue;
public void init()
{
red = 100;
blue = 255;
green = 125;
}
public void paint (Graphics g)
{
g.setColor (new Color (red, green, blue) );
g.drawString ("Welcome to CS335", 50, 33);
showStatus ("Current RGB: " + g.getColor().toString() );
}
}
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
public class DemoFont extends Applet {
private Font fon;
public void init()
{
fon = new Font ("Courier", Font.ITALIC + Font.BOLD, 24);
}
public void paint (Graphics g)
{
int style, size;
String str, name;
g.setFont (fon);
style = fon.getStyle();
if ( style == Font.PLAIN)
str = "Plain";
else if (style == Font.BOLD)
str = "Bold";
else if (style == Font.ITALIC)
str = "Italic";
else
str = "Bold italic";
size = fon.getSize();
str += size + " point ";
name = fon.getName();
str += name;
g.drawString (str, 20, 40);
g.drawString ("Font family is " + fon.getFamily(), 20, 60);
}
}
import java.applet.Applet;
import java.awt.Graphics;
public class DemoCopyArea extends Applet {
int xValues[] = {20, 40, 50, 30, 20, 15, 20};
int yValues[] = {20, 20, 30, 50, 50, 30, 20};
private Polygon p2;
public void init ()
{
p2 = new Polygon();
p2.addPoint (70, 70);
p2.addPoint (90, 70);
p2.addPoint (100, 80);
p2.addPoint (80, 100);
p2.addPoint (70, 100);
p2.addPoint (65, 80);
p2.addPoint (60, 60);
}
public void paint (Graphics g)
{
g.drawPolygon (xValues, yValues, 7);
g.fillPolygon (p2);
g.copyArea (0, 0, 100, 100, 140, 10 );
}
}
import java.applet.Applet;
import java.awt.*;
public class MyChoice extends Applet {
private Choice choiceButton;
private TextField t;
private Font f;
private Checkbox checkBold, checkItalic;
public void init()
{
choiceButton = new Choice();
t = new TextField( "Sample Text", 16);
t.setEditable(false);
choiceButton.addItem( "TimesRoman");
choiceButton.addItem( "Courier");
choiceButton.addItem( "Helvitica");
add (choiceButton);
checkBold = new Checkbox("Bold");
checkItalic = new Checkbox();
checkItalic.setLabel ("Italic");
add (checkBold);
add (checkItalic);
f = new Font (choiceButton.getItem(0), Font.PLAIN, 14);
t.setFont (f);
add (t);
}
public boolean action (Event e, Object o)
{
String s;
int bo, it;
if (e.target instanceof Choice || e.target instanceof Checkbox)
{
if (checkBold.getState() == true)
bo = Font.BOLD;
else
bo = Font.PLAIN;
if (checkItalic.getState() )
it = Font.ITALIC;
else
it = Font.PLAIN;
f = new Font (choiceButton.getSelectedItem(), bo + it, 14);
t.setFont(f);
s = "Number of items: " + choiceButton.countItems();
s += " Current index: " + choiceButton.getSelectedIndex();
showStatus (s);
}
return true;
}
}
import java.applet.Applet;
import java.awt.*;
public class MyList extends Applet {
private List stateList, copyList;
private Button copy;
public void init()
{
stateList = new List (5, true);
copyList = new List (5, false);
copy = new Button ("Copy >>>");
stateList.addItem("New Mexico");
stateList.addItem("New Jersey");
stateList.addItem("New York");
stateList.addItem("Alaska");
stateList.addItem("Hawaii");
stateList.addItem("Ohio");
stateList.addItem("Iowa");
stateList.addItem("Maine");
stateList.addItem("Texas");
add (stateList);
add (copy);
add (copyList);
}
public boolean action (Event e, Object o)
{
String states[];
if (e.target == copy)
{
states = stateList.getSelectedItems();
for (int i = 0; i < states.length; i++)
copyList.addItem ( states[i] );
}
return true;
}
}
import java.applet.Applet;
import java.awt.*;
public class TwoPanels extends Applet {
private Panel pan1, pan2;
private Label lab1, lab2;
public void init()
{
pan1 = new Panel();
pan2 = new Panel();
lab1 = new Label (" first panel ");
lab2 = new Label (" second panel ");
pan1.setBackground (Color.yellow);
pan2.setBackground (Color.pink);
pan1.add (lab1);
pan2.add (lab2);
add (pan1);
add (pan2);
}
}