Share & learn

Through Innovative Digital Library

How to rotate a string on screen in Java?

Write a code in Java to rotate the String on a screen.
 



Answers

Posted by Paul on April 23rd 2018 07:40 AM

Here you can use applet to rotate string on a screen. Here is the code :

// Java program to rotate string on screen

import java.awt.*;
import java.applet.*;

public class 
MovingContent extends Applet implements Runnable {

    
// string to be rotated
    
String str " WELCOME TO ITSPRINGS             ";
    
char ch;
    
boolean stopFlag true;
    
Thread thread null;

    public 
void init() {

        
// set graphics for frame
        
setBackground(Color.black);
        
setForeground(Color.white);
        
setSize(300300);

    }

    
// start applet
    
public void start() {
        
thread = new Thread(this);
        
stopFlag false;
        
thread.start();
    }

    
// run the applet
    
public void run() {

        
// display text reapeated times.
        
for (;;) {
            try {
                
repaint();
                
Thread.sleep(250);
                
ch str.charAt(0);
                
str str.substring(1str.length());
                
str str ch;
                if (
stopFlag)
                    break;
            } catch (
InterruptedException e) {
            }
        }
    }

    
// pause the text.
    
public void stop() {
        
stopFlag true;
        
thread null;
    }

    
// display the text
    
public void paint(Graphics graphics) {
        
graphics.drawString(str6030);

    }
}
Answer Question

Your email address will not be published. Required fields are marked *

  • Minimum 20 character
SV2O

related questions

Most liked questions

Most answered questions

Login
SV2O Refresh
Register
SV2O Refresh
Forgot password
Ask a Question
Minimum 20 character
Minimum 20 character
Reply
Minimum 20 character
SV2O Refresh