Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Kolokwium;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.geom.*;
- import java.awt.image.BufferedImage;
- import java.awt.AlphaComposite;
- class Plansza extends JPanel
- {
- final static BasicStroke wideStroke = new BasicStroke(8.0f);
- Shape figura;
- Plansza(Shape figura)
- {
- this.figura=figura;
- }
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- Graphics2D g2d=(Graphics2D)g;
- BasicStroke bs5 = new BasicStroke(8, BasicStroke.CAP_ROUND,
- BasicStroke.JOIN_BEVEL);
- g2d.setStroke(bs5);
- g2d.draw(figura);
- int xpoints[] = {300, 350, 450, 300};
- int ypoints[] = {300, 350, 300, 300};
- int npoints = 3;
- g2d.drawPolygon(xpoints,ypoints,npoints);
- BasicStroke bs6 = new BasicStroke(8, BasicStroke.CAP_ROUND,
- BasicStroke.JOIN_ROUND);
- g2d.setStroke(bs6);
- int xpoints2[] = {280, 330, 420, 280};
- int ypoints2[] = {280, 330, 280, 280};
- g2d.drawPolygon(xpoints2,ypoints2, 3);
- g2d.setPaint(Color.gray);
- g2d.setPaint(Color.red);
- g2d.fill(new Rectangle2D.Double(200, 20, 50, 50));
- g2d.setPaint(Color.black);
- GradientPaint redtowhite = new GradientPaint(150, 10, Color.black, 50, 10, Color.green);
- g2d.setPaint(redtowhite);
- g2d.fill(new Ellipse2D.Double(10, 150, 100, 70));
- g2d.setPaint(Color.black);
- g2d.setPaint(Color.gray);
- int x3 = 150;
- int y3 = 150;
- g2d.setStroke(wideStroke);
- g2d.draw(new Arc2D.Double(x3, y3, 100, 70, 80, 260,
- Arc2D.OPEN));
- //----------------------------------------------------------------------
- float[] dash1 = {2f, 0f, 2f};
- float[] dash2 = {1f, 1f, 1f};
- float[] dash3 = {4f, 0f, 2f};
- float[] dash4 = {4f, 4f, 1f};
- BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f);
- BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 1.0f, dash2, 2f);
- BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);
- BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);
- g2d.setStroke(bs1);
- g2d.drawLine(20, 250, 250, 250);
- g2d.setStroke(bs2);
- g2d.drawLine(20, 290, 250, 290);
- g2d.setStroke(bs3);
- g2d.drawLine(20, 330, 250, 330);
- g2d.setStroke(bs4);
- g2d.drawLine(20, 370, 250, 370);
- RenderingHints rh = new RenderingHints(
- RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- rh.put(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- g2d.setRenderingHints(rh);
- bs1 = new BasicStroke(8, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_BEVEL);
- g2d.setStroke(bs1);
- g2d.drawLine(300, 30, 400, 30);
- bs2 = new BasicStroke(8, BasicStroke.CAP_ROUND,
- BasicStroke.JOIN_BEVEL);
- g2d.setStroke(bs2);
- g2d.drawLine(300, 80, 400, 80);
- bs3 = new BasicStroke(8, BasicStroke.CAP_SQUARE,
- BasicStroke.JOIN_BEVEL);
- g2d.setStroke(bs3);
- g2d.drawLine(300, 130, 400, 130);
- bs4 = new BasicStroke();
- g2d.setStroke(bs4);
- int w = 150;
- int h = 150;
- int compositeRule = AlphaComposite.SRC_OVER;
- float alphaValue = 0.5f;
- AlphaComposite ac;
- BufferedImage bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
- Graphics2D big = bi.createGraphics();
- ac = AlphaComposite.getInstance(compositeRule, alphaValue);
- big.setColor(Color.red);
- big.fill(new Ellipse2D.Double(0, h / 3, 2 * w / 3, h / 3));
- big.setColor(Color.blue);
- big.setComposite(ac);
- big.fill(new Ellipse2D.Double(w / 3, h / 3, 2 * w / 3, h / 3));
- g2d.drawImage(bi, null, 0, 0);
- }
- }
- class Main
- {
- public static void main(String[] args)
- {
- Shape obj1;
- obj1=new Rectangle2D.Float(0,0,0,0);
- Plansza p1;
- p1=new Plansza(obj1);
- JFrame jf=new JFrame();
- jf.add(p1);
- jf.setTitle("Test grafiki");
- jf.setSize(600,600);
- jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jf.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement