package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; /** peldaprogram az affin trafok hasznalatara. @link.forrásfájl {@docRoot}/../data/java2d/src Transzformacio.java @link.letöltés {@docRoot}/../data/java2d Transzformacio.jar @since Java 2 Útikalauz programozóknak */ class Transzformacio extends Canvas implements ActionListener { /** Verziószám */ private final static long serialVersionUID = 15L; AffineTransform trafo = new AffineTransform (); Button gomb1 = new Button ("Eltolas"); Button gomb2 = new Button ("Forgatas"); Button gomb3 = new Button ("Leptekezes"); Button gomb4 = new Button ("Nyiras"); public void initScreen () { Frame f = new Frame (); Panel p = new Panel (); p.setLayout (new FlowLayout ()); p.add (gomb1); p.add (gomb2); p.add (gomb3); p.add (gomb4); f.add (this); f.add ("South", p); gomb1.addActionListener (this); gomb2.addActionListener (this); gomb3.addActionListener (this); gomb4.addActionListener (this); f.addWindowListener ( new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } } ); f.setSize (300, 300); f.setVisible (true); } public void paint (Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle2D teglalap = new Rectangle2D.Float (100.0f, 100.0f, 50.0f, 100.0f); g2.setTransform (trafo); g2.setColor (Color.blue); g2.draw (teglalap); } public static void main (String[] args) { Transzformacio t = new Transzformacio (); t.initScreen (); } public void actionPerformed (ActionEvent e) { if (e.getActionCommand ().compareTo ("Eltolas") == 0) trafo.translate (10.0, 10.0); else if (e.getActionCommand ().compareTo ("Forgatas") == 0) trafo.rotate (Math.PI / 4.0, 125.0, 150.0); else if (e.getActionCommand ().compareTo ("Leptekezes") == 0) trafo.scale (2.0, 1.0); else trafo.shear (-0.5, 0.0); repaint (); } }