Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Spiel;
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.RenderingHints;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionAdapter;
- import java.util.ArrayList;
- import javax.swing.JComponent;
- public class DrawAreaRater extends JComponent {
- public Connection con;
- public int radius;
- // Image in which we're going to draw
- private Image image;
- // Graphics2D object ==> used to draw on
- public Graphics2D g2;
- // Mouse coordinates
- public DrawAreaRater() {
- setDoubleBuffered(false);
- }
- public void drawLine(int radius, int oldX, int oldY, int currentX, int currentY,int r ,int g, int b){
- g2.setColor(new Color(r, g, b));
- g2.setStroke(new BasicStroke(radius));
- g2.drawLine(oldX, oldY, currentX, currentY);
- repaint();
- }
- protected void paintComponent(Graphics g) {
- if (image == null) {
- // image to draw null ==> we create
- image = createImage(480, 560);
- g2 = (Graphics2D) image.getGraphics();
- // enable antialiasing
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- // clear draw area
- clear();
- }
- g.drawImage(image, 20, 0, null);
- }
- // now we create exposed methods
- public void clear() {
- g2.setPaint(Color.white);
- // draw white on entire draw area to clear
- g2.fillRect(-20, 0, getSize().width, getSize().height);
- g2.setPaint(Color.black);
- repaint();
- }
- public void setColor(Color c) {
- // apply red color on g2 context
- g2.setPaint(c);
- }
- }
Add Comment
Please, Sign In to add comment