Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP90015-DSAss2-InfinityMonkeys-remaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RUNZHE WANG
COMP90015-DSAss2-InfinityMonkeys-remaster
Commits
5fc735fe
Commit
5fc735fe
authored
Oct 24, 2019
by
Hai HoDac
Browse files
Options
Downloads
Patches
Plain Diff
Merged with Ryan's code
parent
9888279f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/GUI/DrawingArea.java
+3
-25
3 additions, 25 deletions
src/GUI/DrawingArea.java
with
3 additions
and
25 deletions
src/GUI/DrawingArea.java
+
3
−
25
View file @
5fc735fe
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment