package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; /** peldaprogram a konturok kezelesere. @link.forrásfájl {@docRoot}/../data/java2d/src Kontur.java @link.letöltés {@docRoot}/../data/java2d Kontur.jar @since Java 2 Útikalauz programozóknak */ class Kontur extends Canvas implements ActionListener { /** Verziószám */ private final static long serialVersionUID = 15L; Button gomb1 = new Button ("JOIN_MITER"); Button gomb2 = new Button ("CAP_SQUARE"); Button gomb3 = new Button ("Minta Ki"); int joinStyle = BasicStroke.JOIN_MITER, endcapStyle = BasicStroke.CAP_BUTT; boolean mintaKell = true; public void initScreen () { Frame f = new Frame (); Panel p = new Panel (); p.setLayout (new FlowLayout ()); p.add (gomb1); p.add (gomb2); p.add (gomb3); f.add (this); f.add ("South", p); gomb1.addActionListener (this); gomb2.addActionListener (this); gomb3.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; float minta[] = {8.0f}; BasicStroke bs; if (mintaKell == true) bs = new BasicStroke (5.0f, endcapStyle, joinStyle, 10.0f, minta, 0.0f); else bs = new BasicStroke (5.0f, endcapStyle, joinStyle); g2.setStroke (bs); g2.setColor (Color.blue); GeneralPath vBetu = new GeneralPath (); vBetu.append (new Line2D.Float (10.0f, 10.0f, 100.0f, 200.0f), true); vBetu.append (new Line2D.Float (100.0f, 200.0f, 190.0f, 10.0f), true); g2.draw (vBetu); } public static void main (String[] args) { Kontur k = new Kontur (); k.initScreen (); } public void actionPerformed (ActionEvent e) { if (e.getActionCommand ().compareTo ("JOIN_MITER") == 0) { joinStyle = BasicStroke.JOIN_ROUND; gomb1.setLabel ("JOIN_ROUND"); } else if (e.getActionCommand ().compareTo ("JOIN_ROUND") == 0) { joinStyle = BasicStroke.JOIN_BEVEL; gomb1.setLabel ("JOIN_BEVEL"); } else if (e.getActionCommand ().compareTo ("JOIN_BEVEL") == 0) { joinStyle = BasicStroke.JOIN_MITER; gomb1.setLabel ("JOIN_MITER"); } else if (e.getActionCommand ().compareTo ("Minta Ki") == 0) { mintaKell = false; gomb3.setLabel ("Minta Be"); } else if (e.getActionCommand ().compareTo ("Minta Be") == 0) { mintaKell = true; gomb3.setLabel ("Minta Ki"); } else if (e.getActionCommand ().compareTo ("CAP_BUTT") == 0) { endcapStyle = BasicStroke.CAP_ROUND; gomb2.setLabel ("CAP_ROUND"); } else if (e.getActionCommand ().compareTo ("CAP_ROUND") == 0) { endcapStyle = BasicStroke.CAP_SQUARE; gomb2.setLabel ("CAP_SQUARE"); } else { endcapStyle = BasicStroke.CAP_BUTT; gomb2.setLabel ("CAP_BUTT"); } repaint (); } }