1. Write a java program to scroll the text from left to right and vice versa continuously.
import [Link];
import [Link].*;
public class Slip1A extends Applet implements Runnable {
int x, y, z;
Thread t;
public void init() {
x = 50;
y = 50;
z = 1;
t = new Thread(this);
[Link]();
}
public void mpostion() {
x = x + 10 * z;
if (x > [Link]())
z = -1;
if (x < 0)
z = 1;
}
public void run() {
while (true) {
repaint();
mpostion();
try {
[Link](100);
} catch (Exception e) {
}
}
}
public void paint(Graphics g) {
[Link]("SVPM", x, y);
}
}
/*
* <applet code="[Link]" width="300" height="300">
* </applet>
*/
2. Write a java program in multithreading using applet for
drawing flag.
import [Link].*;
public class Slip2B extends Frame{
int f = 0;
public Slip2B(){
Signal s = new Signal();
[Link]();
setSize(500,500);
setVisible(true);
}
public void paint (Graphics g){
switch (f){
case 0 :
[Link](150, 50, 150, 300);
case 1 :
[Link](150, 50, 100, 90);
}
}
class Signal extends Thread{
public void run(){
while(true){
f = (f+1)%2;
repaint();
try{
[Link](1000);
}catch(Exception e){
}
}
}
}
public static void main(String args[]){
new Slip2B();
}
}
3. Write a java program using applet for bouncing ball, for each
bounce color of ball
should change randomly.
import [Link].*;
import [Link].*;
public class Slip3B extends Frame implements Runnable {
private int x, y, w, h, f;
private Color c = [Link];
public Slip3B() {
setTitle("Bouncing Boll");
setSize(400, 400);
setVisible(true);
w = getWidth();
h = getHeight();
x = (int) ([Link]() * getWidth());
y = (int) ([Link]() * getHeight());
Thread t = new Thread(this);
[Link]();
}
public void run() {
while (true) {
switch (f) {
case 0:
y++;
if (y > h - 50) {
c = new Color((int) ([Link]() * 256), (int) ([Link]() * 256),
(int) ([Link]() * 256));
f = 1;
}
break;
case 1:
y--;
if (y < 0) {
c = new Color((int) ([Link]() * 256), (int) ([Link]() * 256),
(int) ([Link]() * 256));
f = 0;
}
}
repaint();
try {
[Link](10);
} catch (Exception e) {
}
}
}
public void paint(Graphics g) {
[Link](g);
[Link](c);
[Link](x, y, 20, 20);
}
public static void main(String args[]) {
new Slip3B();
}
}
3. Write a java program in multithreading using applet for Traffic signal.
import [Link].*;
public class Slip5B extends Frame {
int f = 0;
public Slip5B() {
Signal s = new Signal();
[Link]();
setSize(500, 500);
setVisible(true);
}
public void paint(Graphics g) {
switch (f) {
case 0:
[Link]([Link]);
[Link](60, 60, 50, 50);
[Link]([Link]);
[Link](60, 120, 50, 50);
[Link](60, 180, 50, 50);
break;
case 1:
[Link]([Link]);
[Link](60, 120, 50, 50);
[Link]([Link]);
[Link](60, 60, 50, 50);
[Link](60, 180, 50, 50);
break;
case 2:
[Link]([Link]);
[Link](60, 180, 50, 50);
[Link]([Link]);
[Link](60, 120, 50, 50);
[Link](60, 60, 50, 50);
break;
}
}
class Signal extends Thread {
public void run() {
while (true) {
f = (f + 1) % 3;
repaint();
try {
[Link](1000);
} catch (Exception e) {
}
}
}
}
public static void main(String args[]) {
new Slip5B();
}
}