Home Tutorial Java Swing Move text on the frame

 
 

Move text on the frame
Posted on: October 30, 2009 at 12:00 AM
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);
  }
}

Related Tags for Move text on the frame:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.