    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    
    class myComponent extends JComponent {
        private static final int N = 300;
    
        public Dimension getPreferredSize() {
            return new Dimension(N, N);
        }
    
        public void paint(Graphics g) {
            Graphics2D g2d = (Graphics2D)g;
    
            AffineTransform aft = AffineTransform.
                getRotateInstance(Math.PI/2, N / 2, N / 2);
            g2d.setTransform(aft);
    
            Font f = new Font("monospaced", Font.BOLD, 24);
            g2d.setFont(f);
            String s = "testing";
            g2d.drawString(s, 100, 100);
            FontMetrics fm = getFontMetrics(f);
            int h = fm.getHeight();
            int w = fm.stringWidth(s);
            g2d.drawLine(100, 100 + h, 100 + w, 100 + h);
        }
    }
    
    public class graph2d {
        public static void main(String args[]) {
            JFrame f = new JFrame("testing");
            f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
    
            JPanel p = new JPanel();
            p.add(new myComponent());
            f.getContentPane().add(p);
    
            f.pack();
            f.setVisible(true);
        }
    }
