Advertisement
Guest User

LOl

a guest
Jan 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.63 KB | None | 0 0
  1. package com.Kolokwium;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.geom.*;
  6. import java.awt.image.BufferedImage;
  7. import java.awt.AlphaComposite;
  8.  
  9. class Plansza extends JPanel
  10. {
  11.     final static BasicStroke wideStroke = new BasicStroke(8.0f);
  12.     Shape figura;
  13.  
  14.     Plansza(Shape figura)
  15.     {
  16.         this.figura=figura;
  17.     }
  18.  
  19.     public void paintComponent(Graphics g)
  20.     {
  21.         super.paintComponent(g);
  22.         Graphics2D g2d=(Graphics2D)g;
  23.  
  24.  
  25.         BasicStroke bs5 = new BasicStroke(8, BasicStroke.CAP_ROUND,
  26.                 BasicStroke.JOIN_BEVEL);
  27.         g2d.setStroke(bs5);
  28.         g2d.draw(figura);
  29.         int xpoints[] = {300, 350, 450, 300};
  30.         int ypoints[] = {300, 350, 300, 300};
  31.         int npoints = 3;
  32.         g2d.drawPolygon(xpoints,ypoints,npoints);
  33.  
  34.  
  35.         BasicStroke bs6 = new BasicStroke(8, BasicStroke.CAP_ROUND,
  36.                 BasicStroke.JOIN_ROUND);
  37.         g2d.setStroke(bs6);
  38.         int xpoints2[] = {280, 330, 420, 280};
  39.         int ypoints2[] = {280, 330, 280, 280};
  40.         g2d.drawPolygon(xpoints2,ypoints2, 3);
  41.         g2d.setPaint(Color.gray);
  42.         g2d.setPaint(Color.red);
  43.         g2d.fill(new Rectangle2D.Double(200, 20, 50, 50));
  44.         g2d.setPaint(Color.black);
  45.  
  46.         GradientPaint redtowhite = new GradientPaint(150, 10, Color.black, 50, 10, Color.green);
  47.         g2d.setPaint(redtowhite);
  48.         g2d.fill(new Ellipse2D.Double(10, 150, 100, 70));
  49.         g2d.setPaint(Color.black);
  50.  
  51.  
  52.         g2d.setPaint(Color.gray);
  53.         int x3 = 150;
  54.         int y3 = 150;
  55.  
  56.         g2d.setStroke(wideStroke);
  57.         g2d.draw(new Arc2D.Double(x3, y3, 100, 70, 80, 260,
  58.                 Arc2D.OPEN));
  59.         //----------------------------------------------------------------------
  60.         float[] dash1 = {2f, 0f, 2f};
  61.         float[] dash2 = {1f, 1f, 1f};
  62.         float[] dash3 = {4f, 0f, 2f};
  63.         float[] dash4 = {4f, 4f, 1f};
  64.  
  65.  
  66.  
  67.         BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
  68.                 BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f);
  69.  
  70.         BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT,
  71.                 BasicStroke.JOIN_ROUND, 1.0f, dash2, 2f);
  72.  
  73.         BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
  74.                 BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);
  75.  
  76.         BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
  77.                 BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);
  78.  
  79.         g2d.setStroke(bs1);
  80.         g2d.drawLine(20, 250, 250, 250);
  81.  
  82.         g2d.setStroke(bs2);
  83.         g2d.drawLine(20, 290, 250, 290);
  84.  
  85.         g2d.setStroke(bs3);
  86.         g2d.drawLine(20, 330, 250, 330);
  87.  
  88.         g2d.setStroke(bs4);
  89.         g2d.drawLine(20, 370, 250, 370);
  90.  
  91.         RenderingHints rh = new RenderingHints(
  92.                 RenderingHints.KEY_ANTIALIASING,
  93.                 RenderingHints.VALUE_ANTIALIAS_ON);
  94.  
  95.         rh.put(RenderingHints.KEY_RENDERING,
  96.                 RenderingHints.VALUE_RENDER_QUALITY);
  97.  
  98.         g2d.setRenderingHints(rh);
  99.  
  100.         bs1 = new BasicStroke(8, BasicStroke.CAP_BUTT,
  101.                 BasicStroke.JOIN_BEVEL);
  102.         g2d.setStroke(bs1);
  103.         g2d.drawLine(300, 30, 400, 30);
  104.  
  105.         bs2 = new BasicStroke(8, BasicStroke.CAP_ROUND,
  106.                 BasicStroke.JOIN_BEVEL);
  107.         g2d.setStroke(bs2);
  108.         g2d.drawLine(300, 80, 400, 80);
  109.  
  110.         bs3 = new BasicStroke(8, BasicStroke.CAP_SQUARE,
  111.                 BasicStroke.JOIN_BEVEL);
  112.         g2d.setStroke(bs3);
  113.         g2d.drawLine(300, 130, 400, 130);
  114.  
  115.         bs4 = new BasicStroke();
  116.         g2d.setStroke(bs4);
  117.  
  118.         int w = 150;
  119.         int h = 150;
  120.         int compositeRule = AlphaComposite.SRC_OVER;
  121.         float alphaValue = 0.5f;
  122.         AlphaComposite ac;
  123.         BufferedImage bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
  124.         Graphics2D big = bi.createGraphics();
  125.  
  126.         ac = AlphaComposite.getInstance(compositeRule, alphaValue);
  127.  
  128.         big.setColor(Color.red);
  129.         big.fill(new Ellipse2D.Double(0, h / 3, 2 * w / 3, h / 3));
  130.         big.setColor(Color.blue);
  131.         big.setComposite(ac);
  132.         big.fill(new Ellipse2D.Double(w / 3, h / 3, 2 * w / 3, h / 3));
  133.  
  134.         g2d.drawImage(bi, null, 0, 0);
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.     }
  145. }
  146.  
  147. class Main
  148. {
  149.     public static void main(String[] args)
  150.     {
  151.         Shape obj1;
  152.         obj1=new Rectangle2D.Float(0,0,0,0);
  153.  
  154.         Plansza p1;
  155.         p1=new Plansza(obj1);
  156.  
  157.         JFrame jf=new JFrame();
  158.  
  159.         jf.add(p1);
  160.         jf.setTitle("Test grafiki");
  161.         jf.setSize(600,600);
  162.         jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  163.         jf.setVisible(true);
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement