Skip to content
Snippets Groups Projects
Commit 5fc735fe authored by Hai HoDac's avatar Hai HoDac
Browse files

Merged with Ryan's code

parent 9888279f
No related branches found
No related tags found
No related merge requests found
...@@ -52,9 +52,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -52,9 +52,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
setBackground(Color.WHITE); // Set Background color setBackground(Color.WHITE); // Set Background color
setDoubleBuffered(false); // Non-buffered drawing setDoubleBuffered(false); // Non-buffered drawing
image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB); image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) image.getGraphics();
/// Antialiasing the graphic for smoothness ///
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
shapeColor = new Color(0, 0, 0); shapeColor = new Color(0, 0, 0);
currentMode = Mode.FREEHAND; currentMode = Mode.FREEHAND;
strokeSize = 3; strokeSize = 3;
...@@ -97,8 +94,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -97,8 +94,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
public void clear() { public void clear() {
image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB); image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
repaint(); repaint();
} }
...@@ -144,22 +139,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -144,22 +139,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
} }
} }
// public void saveFile() {
// try {
// ImageIO.write(image, "PNG", new File("Saved_White_Board.png"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
public void saveAsFile(File file) {
try {
ImageIO.write(image, "PNG", file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void openFile(File file) { public void openFile(File file) {
try { try {
image = ImageIO.read(file); image = ImageIO.read(file);
...@@ -243,6 +222,8 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -243,6 +222,8 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
startPoint = previousPoint = e.getPoint(); startPoint = previousPoint = e.getPoint();
/// Instantiate object based on current mode /// /// Instantiate object based on current mode ///
...@@ -299,9 +280,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -299,9 +280,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
default: default:
break; break;
} }
g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(shapeColor); g2.setColor(shapeColor);
/// This repaint is needed if we want to fill the drawing shape with color /// This repaint is needed if we want to fill the drawing shape with color
...@@ -357,7 +335,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -357,7 +335,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
/// Eraser is continuously drawing "small white circle" from current point to previous point /// /// Eraser is continuously drawing "small white circle" from current point to previous point ///
case ERASE: case ERASE:
((Ellipse2D) drawing).setFrame(currentPoint.getX(), currentPoint.getY(), eraserSize, eraserSize); ((Ellipse2D) drawing).setFrame((currentPoint.getX() - (eraserSize / 2)), (currentPoint.getY() - (eraserSize / 2)), eraserSize, eraserSize);
g2.setColor(Color.WHITE); g2.setColor(Color.WHITE);
g2.fill(drawing); g2.fill(drawing);
g2.draw(drawing); g2.draw(drawing);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment