Rotating the graphics context in Swing

Use AffineTransform or call the method rotate directly on the graphics context.

Main.java:

import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame {
   private int degrees = 0;
 
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(1);
         }
      });
 
      JButton button = new JButton("Rotate 10 degrees");
      button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            degrees += 10;
            degrees %= 360;
            repaint();
         }
      });
 
      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(BorderLayout.SOUTH, button);
   }
 
   public void paint(Graphics g) {
      super.paint(g); 
 
      Graphics2D g2d = (Graphics2D) g;
 
      double radians = degrees * (Math.PI / 180); 
      g2d.rotate(radians, getWidth()/2, getHeight()/2);
 
      BasicStroke bs = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                                       10, null, 0);
      g2d.setStroke(bs);
      QuadCurve2D.Float qc = new QuadCurve2D.Float(20, 50, 100, 50, 100, 170);
      g2d.draw(qc);
 
      bs = new BasicStroke(5, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                           10, null, 0);
      g2d.setStroke(bs);
      Ellipse2D.Float e = new Ellipse2D.Float(140, 50, 80, 120);
      g2d.draw(e);
 
      bs = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                           10, null, 0);
      g2d.setStroke(bs);
      g2d.drawRect(260, 50, 80, 120);
 
      GradientPaint gp = new GradientPaint(380, 50, Color.red, 460, 170, Color.blue);
      g2d.setPaint(gp);
      bs = new BasicStroke(15, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                           10, null, 0);
      g2d.setStroke(bs);
      g2d.drawRect(380, 50, 80, 120); 
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(480, 250);
      main.setVisible(true);
   }
}