Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 6 months ago

A Programmer's question about net beans's graphic reflection ! Why it doesn't reflect it like a mirror ? i tried everything!?.?

public void paintComponent(Graphics g){

super.paintComponent(g);

Graphics2D g2=(Graphics2D) g;

{

Font f1 = new Font(Font.SERIF, Font.BOLD, 60);

g2.setFont(f1);

//g2.drawString("Hello TM240", 20, 80);

FontRenderContext frc = g2.getFontRenderContext();

GlyphVector gv = f1.createGlyphVector(frc, "Hello TM240");

Shape glyph = gv.getOutline(20,80);

g2.setClip(glyph);

g2.setColor(Color.blue);

for (int i = 0; i< 2000; i++)

{

Shape shape=new Line2D.Double(Math.random()*500,Math.random()*400,Math.random()*500,Math.random()*400);

g2.draw(shape);

}

AffineTransform transform = new AffineTransform();

transform.setTransform(-1,0,0,1,0,0);

Shape shape1 = transform.createTransformedShape(glyph);

g2.draw(shape1);

}

}

}

1 Answer

Relevance
  • 6 months ago

    I'm not too familiar with java.awt.geom classes, but that transform of yours is pretty clearly broken in that you are completely ignoring the input y coordinate. To tranform the vector (x, y, 1) into (-x, y), you want the matrix to be:

    [ -1 . 0 . 0 ] . . . . x' = (-1)x + (0)y + 0 = -x

    [. 0 . 1 . 0 ] . . . . y' = (0)x + (1)y + 0 = y

    The docs say that constructor call is:

    new AffineTransform(-1, 0, 0, 0, 1, 0);

    You had the arguments (-1, 0, 0, 1, 0, 0), which sets the output x' = -x, y' = x, ignoring the input y value and putting all output on the y' = -x' diagonal line.

    • Amr6 months agoReport

      that wont fix it still not gonna show the reflect , the page will remain white
      it's more like the program doesn't even read it .. even if u changed the constructor to (-1,0,0,0,1,0) same thing nothing
      it's more like the part of the affine is not even there...

    • Login to reply the answers
Still have questions? Get your answers by asking now.