Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a stand along Javaapp, and need help with Graphics rotation

Status
Not open for further replies.

coderGirl

Programmer
Oct 21, 2003
22
AU
Hi there;

I am making a stand alone JAVA application, and i need to work out how to have just say a oval on the screen and have it that the user can press a key on the keyboard and it will rotate so many degrees..

can someone please help me : )

I have done this before, but it's been a while and i can't quite remmeber who it's done

kind regards
 
Thanx Mate......

i had a look....

I still can't seme to figure it out....

call me stupid or it could be just the late hour..

if anyone could help me furthur i would appreciate it

kind regards
 
Sorry
What i meant is i can get the gey lsitener to work and create the shapes

but the rotation is behond me.... i can't seem to get it to work

kind regards
 
Use the class AffineTransform to transpose the shape's coordinate space matrix.

--------------------------------------------------
Free Database Connection Pooling Software
 
yeah i was looking at AffineTransform to transpose the shape's

but how do you alter thecoordinate space matrix??

kind
regards


 
- Create a transform matrix
- Create an AffineTransform & set the translation
- transform the shape

Eg, something along the lines of :

Code:
// Create transform from 6 matrix values
double m00=1.0d;
double m01=0.0d;
double m02=labelAreaWidth*0.5;
double m10=0.0d;
double m11=1.0d;
double m12=labelAreaHeight*0.5;
double m02Multiplier=0.0d;
double m12Multiplier=0.0d;


//AffineTransform at = new AffineTransform(m00, m10, m01, m11, m02, m12);
// Or use method
AffineTransform at = new AffineTransform();
at.setToTranslation(m02,m12);

// translate feature
yourShape.transform(at);



--------------------------------------------------
Free Database Connection Pooling Software
 
Fantastic Mate : )

thanx for the help

: )

best regards
 
:) ah just quickly.. this is gonna sound really stupid.. but the yourShape.... what sort of opject is that....
 
Hi ther

ok i Think i've lost my brain...

I can;t seem to get this to work...

i have no idea where to start

 
// try using rotate
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.AffineTransform;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.util.*;
class WholeFrame3 extends JFrame implements ActionListener
      {
       CenterCanvas3 cc;
       JButton jb,jb2;
       JPanel ccPanel,jbPanel;
       double dividedBy = 36.0;
       public WholeFrame3()
              {
               //getContentPane().setBackground(Color.green);
               getContentPane().setLayout(null);
               ccPanel = new JPanel();
               ccPanel.setBounds(0,0,500,500);
               cc = new CenterCanvas3();
               cc.setBounds(0,0,500,500);
               getContentPane().add(ccPanel);
               ccPanel.add(cc);

               jbPanel = new JPanel();
               jbPanel.setBackground(Color.blue);
               jbPanel.setBounds(0,600,500,100);
               getContentPane().add(jbPanel);

               jb = new JButton("click");
               jb.addActionListener(this);
               jbPanel.add(jb);
              }
       public static void main(String args[])
              {
               WholeFrame3 wf = new WholeFrame3();
               wf.setSize(600,700);
               wf.setVisible(true);
              }
       public void actionPerformed(ActionEvent e)
              {       
               if(e.getSource()==jb)
                 {
                     dividedBy-=1.0;

                  cc.setRadian(Math.PI*dividedBy/36.0);
                 }
              }
}

class CenterCanvas3 extends Canvas
      {

       double rad = Math.PI*36.0/36.0;
       public void setRadian(double tempRad)
              {
               rad = tempRad;
               repaint();
              }
       public double getRadian()
              {
               System.out.println(rad);
               return rad;
              }
       public void update()
              {}

       public void paint(Graphics g)
              {
    Graphics2D g2 = (Graphics2D)g;
setBackground(Color.green);
    //Update transform to provide rotation and display, 
    // the transform values.    
g2.rotate(getRadian(),250.0,250.0);
g2.setColor(Color.black);
g2.drawRect(120, 120, 20, 200);
g2.drawString ("Material", 30, 220);
g2.drawString ("Ratings", 30, 240);
g2.drawString ("+5", 102, 130);
g2.drawString ("0", 107, 220);
g2.drawString ("-5", 102, 315);
               }  
}
 
FANTASTIC MATE :)

Your brilliant, Thnx a million..
Don't know why i couldn't get that to work :)

I realy Appreciate you taking the time to help me :)

kind Regards

coderGirl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top