Pages

How to draw rotate string in java ???

*********************************************************************
COMPLETE SOURCE CODE FOR : DrawRotateText.java
*********************************************************************


import java.awt.Frame;
import java.awt.Panel;

import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import java.awt.geom.AffineTransform;

public class DrawRotateText extends Panel
{
public DrawRotateText()
{
Frame a=new Frame("Draw Rotate Text");
WindowListener wl=new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
};

a.addWindowListener(wl);
a.add(this);
a.setSize(400,400);
a.setVisible(true);
}

public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
AffineTransform at=new AffineTransform();
at.setToRotation(-Math.PI/4);//SET ROTATION HERE IN radians
g2d.setTransform(at);

g2d.drawString("HI EVERYONE !!",100,200);
}

public static void main(String[]args)
{
DrawRotateText drt=new DrawRotateText();
}
}


*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************
Related Posts Plugin for WordPress, Blogger...