Move text on the frame


 

Move text on the frame

In this section, you will learn how to move text on the frame.

In this section, you will learn how to move text on the frame.

Move text on the frame using Java Program

In this section, you will learn how to move text on the frame. As you have already learned about the html marquee tag. Here we are going to do the same thing in Swing. We have used Timer class to move the specified string.

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
 
public class MovingText extends JFrame implements ActionListener{
  JLabel label;
  JLabel label2;
 
  public MovingText()  {
    label = new JLabel"Hello World,Where there is will there is& nbsp;a way");
    getContentPane().add(label, BorderLayout.NORTH);
     javax.swing.Timer timer = new javax.swing.Timer(100this);
    timer.start();
  }
   public void actionPerformed(ActionEvent e)  {
    String oldText = label.getText();
    String newText = oldText.substring(1+ oldText.substring(01);
     label.setTextnewText );
  }
   public static void main(String[] args)  {
    MovingText frame = new MovingText();
    frame.setDefaultCloseOperationEXIT_ON_CLOSE );
    frame.setSize(300,100);
    frame.setVisible(true);
  }
}

Ads