text animation/ text move on JFrame in java swing

In this tutorial show, you how to create simple text animation/ text move on JFrame in java swing application using graphics 2d.

Do you need help to remotely set up my any project on your machine or customize any project with your requirement please contact  syntech1994@gmail.com

Source code of text animation/ text move on JFrame in java swing application


package text_animation;

import java.awt.Color;
import java.awt.Font;
import static java.awt.Font.BOLD;
import static java.awt.Font.ITALIC;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.text.StyledEditorKit;

/**
 *
 * @author ccs
 */
public class Text_Animation extends JPanel{

    int x=0;
    int y=100;
    int a=400;
    int b=200;
     public void paint(Graphics gp)
    {
        super.paint(gp);
        Graphics2D g2d= (Graphics2D) gp;
        g2d.setColor(Color.red);
        g2d.setFont(new Font("BOLD", BOLD, 35));
             
        g2d.drawString("Welcome TO", x, y);
        g2d.drawString("CodeGuid.Com", a, b);
       g2d.drawString("THANKS ", x, 300);
                try {
            Thread.sleep(200);
            x+=20;
            a-=20;
            
            if(x>getWidth())
        {
        
            x=0;
        }
            if(a<0)
        {
        
            a=500;
        }
        repaint();
                      
        } catch (InterruptedException ex) {
            JOptionPane.showMessageDialog(this, ex);
        }
    
        
        
    }
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        JFrame jf = new JFrame();
        jf.setSize(500, 500);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.add(new Text_Animation());
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
    }
    
}

More examples for graphics 2d>>

Be the first to comment

Leave a Reply

Your email address will not be published.


*