Paint Applet: A simple Java Swing application for drawing on a canvas. Users can select from three colors (black, red, blue) and draw shapes by clicking and dragging the mouse. The app maintains a history of shapes and displays them as the user interacts with the canvas.
The Paint Applet is a simple drawing application built using Java Swing. It allows users to draw shapes on a canvas by clicking and dragging the mouse, and it includes buttons to change the drawing color. The applet maintains a list of drawn shapes and displays them on the screen.
javac PaintApplet.java
java PaintApplet
PaintApplet
class extends JPanel
and serves as the main panel for drawing.Shape
class is a nested class within PaintApplet
, representing individual shapes drawn on the canvas.Mouse Listeners:
MouseAdapter
for capturing mouse press and release events.MouseMotionAdapter
for capturing mouse drag events.Color Buttons:
Shape Class:
Shape
object is created, and the first point is added.paintComponent
method iterates through the list of shapes and draws each one on the canvas.Adding More Colors:
JButton
instances for each color.ActionListener
to each button to call setCurrentColor
with the desired Color
.Changing Canvas Size:
frame.setSize
method in the main
method to set the desired width and height.This project is licensed under the MIT License.
This project was developed as a part of a Java coursework during my 2nd year of B.Tech.