In: Computer Science
Design the following GUI by using swing components:
Can you think of changing the Hi positions in an horizontal line every two seconds? Write a program that will allow you to change the sentence position horizontally for every 2 seconds. That is, after another 2 seconds, the Hi position should be changed to the following:
This is JAVA please.
the program is the word HI that automatically scrolls accros the screen until the end and then comes back on the left the next line down. and keeps scrolling like that..
Hi
this question I will cancel because I dont need it now Thanks for your response. I will be posting the actual question in about 20 minutes
package Animation;
import java.applet.*;
import java.awt.*;
// Defines class BannerText extends from super class
Applet
// and implements Runnable interface
public class BannerText extends Applet implements Runnable
{
// Assigns a string
String message = "Pyari Mohan Sahu ";
// Creates a font class object
Font f = new Font("Arial", Font.BOLD, 25);
// Creates a Thread class object
Thread myThread;
// Overrides init() method to set the background
// color and applet size
public void init()
{
setForeground(Color.BLUE);
setSize(230, 200);
}
// Overrides start() method to create and start the
thread
public void start()
{
myThread = new Thread(this);
myThread.start();
}
// Overrides run() method to move text
public void run ()
{
char currentChar;
// Loops infinite times
for( ; ; )
{
try
{
// Calls the method to repaint() applet
area
repaint();
// Sleeps for 2 second
Thread.sleep(2000);
// Extracts the character at 0th index
position
currentChar = message.charAt(0);
// Extracts the sub string from 1st index
position to last
message = message.substring(1,
message.length());
// Concatenate the current character at the end
of the message
message += currentChar;
}
catch(InterruptedException e) {}
}
}
// Overrides paint() method to display the text
public void paint(Graphics g)
{
// Creates a rectangle
g.fillRect(1,1,230,200);
// Sets the color of the text to
yellow
g.setColor(Color.YELLOW);
// Sets the font of the text
g.setFont(f);
// Displays the message
g.drawString(message, 1,
100);
}
}
Sample Output: