help with rotate

hi,

im trying to rotate a rectangle,but when im doing so it not appear where the first 1 did here is my code pls tell me what is the problem and how can i rotate it and its center will b where the first one is,

thx.

import java.awt.Graphics;

import java.awt.Graphics2D;

import javax.swing.JFrame;

import javax.swing.JPanel;

publicclass ssextends JPanel{

publicvoid paint(Graphics g){

g.drawRect(100,100,100,100);

g.drawLine(140,90,140,110);

g.drawLine(160,90,160,110);

Graphics2D g2 = (Graphics2D) g;

g2.rotate(30.0 * Math.PI / 180.0);

g.drawRect(100,100,100,100);

// Draw a line (int x1, int y1, int x2, int y2)

g.drawLine(140,90,140,110);

g.drawLine(160,90,160,110);

}

publicstaticvoid main(String[] args){

JFrame frame =new JFrame();

frame.getContentPane().add(new ss());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

frame.setVisible(true);

}

}

[1803 byte] By [barakyesha] at [2007-11-27 10:02:46]
# 1

Custom painting in swing should be done inside paintComponent function and not paint.

You should call super.paintComponent(g) at the beginning of the function when you override paintComponent.

If you want the rectangle to rotate around its center you should set the center for rotation to be the center of the rectangle:

g2.rotate(30.0 * Math.PI / 180.0, 150, 150);

Rodney_McKaya at 2007-7-13 0:37:10 > top of Java-index,Security,Cryptography...
# 2
thx a lot.
barakyesha at 2007-7-13 0:37:10 > top of Java-index,Security,Cryptography...