package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; /** peldaprogram a RenderingHints osztaly hasznalatara. @link.forrásfájl {@docRoot}/../data/java2d/src RajzolasMinosege.java @link.letöltés {@docRoot}/../data/java2d RajzolasMinosege.jar @since Java 2 Útikalauz programozóknak */ class RajzolasMinosege extends Canvas implements ActionListener { /** Verziószám */ private final static long serialVersionUID = 15L; Button gomb = new Button ("Antialiasing Ki"); boolean antialiasing = true; public void initScreen () { Frame f = new Frame (); f.add (this); f.add ("South", gomb); gomb.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; RenderingHints beallitasok; if (antialiasing == true) beallitasok = new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); else beallitasok = new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); beallitasok.put (RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints (beallitasok); BasicStroke bs = new BasicStroke (5.0f); g2.setStroke (bs); Ellipse2D vonal = new Ellipse2D.Float (10.0f, 10.0f, 200.0f, 200.0f); g2.setColor (Color.blue); g2.draw (vonal); } public static void main (String[] args) { RajzolasMinosege r = new RajzolasMinosege (); r.initScreen (); } public void actionPerformed (ActionEvent e) { if (e.getActionCommand ().compareTo ("Antialiasing Ki") == 0) { antialiasing = false; gomb.setLabel ("Antialiasing Be"); } else { antialiasing = true; gomb.setLabel ("Antialiasing Ki"); } repaint (); } }