Hi Everyone. I Really Need Urgent Help To Create A Paint Application In Java Using Applets Or The Swing. Its Really Urgent. I Have Been Trying To Code This For Like Week Now And I Am Just Left With Five Days To Submit It. Thsi Application Should Be Able To Draw Lines, Rectangles,polygons,circles And Ellipses. Its Interface Should Be Very Simple. Please I Really Need Help With This. Thank You Very Much.

Recommended Answers

All 11 Replies

Post your code then and describe what problems you are having. Be sure to place code tags around the code you include.

the thing is i dont have any code.i have been on it. reading books to help me startr
but to no avail. th e problem is i have to submit it. any help? please? my email is <snipped email>

Well, the easiest place to start is the Java 2D graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html

Start with just getting a couple of shapes to draw on a JPanel. Pehaps add buttons to draw a circle, square, etc. They can be of fixed size to begin with. Then go on to add mouse listeners that let the user click and drag to stretch the size of whatever shape they selected. Approach it by steps and you shouldn't have too much difficulty.

thanks again. i do appreciate it. do have a code like that. so i can look on tht and develop mine? i just got five days. please. please my email is <snipped email> u can add me so tht we chat now. thank u very much

thanks again. i do appreciate it. do have a code like that. so i can look on tht and develop mine? i just got five days. please. please my email is <snipped email> u can add me so tht we chat now. thank u very much

No, I do not have any code for that in particular. Just go through the tutorial and perhaps this one too http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html.

Here's a tiny bit of code to get you started

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PaintPanel extends JPanel{
    public PaintPanel() {

    protected void paintComponent(Graphics g) {
        Graphics2D g2D = (Graphics2D)g;
        // paint background
        g2D.clearRect(0,0,getWidth(), getHeight());
        // paint shape
    private void drawEllipse(Graphics2D g2D){
        int shapeWidth = 150;
        int shapwHeight = 75;
        Ellipse2D.Double ellipse = new Ellipse2D.Double( (getWidth()-shapeWidth)/2, (getHeight()-shapwHeight)/2, shapeWidth, shapwHeight);
    public static void main(String[] args) {
        PaintPanel panel = new PaintPanel();
        JFrame frame = new JFrame("Paint");

I Have Been Trying To Code This For Like Week Now And I Am Just Left With Five Days To Submit It.

If you been working so hard you should show us the code what you did so far, explain what is your problems whit it and what you have problem to implement.
Being urgent to you it is not urgent to us.
You should read forum post rules specialy the one about coursework and also forum rules section "Keep It On The Site"
Consider your self lucky that Ezzaral gave you link to very helpful tutorial which you should already read it and not demanded to do your coursework for you

hi peter_budo well i want o thank you for the advice. i spent the whole night going through the site ezzaral showed me. i got some new information and i have started to use the info i got. its just that. when i look at how little time i have left i wish someone will help me out. anyway i owe Ezzaral a lot for all the help he is giving me. thank you too for your concern.

Hi Ezzaral thank you very much for the time and info. i owe you a lot. well i i know some people may be thinking i am just being lazy. but if only they know how we those who are trying to learn IT in the conditions we find ourselves in over here in ghana, they will bear me out. even before you access to the internet and spend all the time going through tutorials u might have spent alot. anyway. thank you once again for all the help and i am ready to accept any further help you wish to give me.

*Write a program in JFC which has shape menu with 3 munu item inside it.
*Circle Rectangle and Line.
*When user clik on circle it will draw a circle on Frame, 
*Same for Rectangle and Line.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class DrawE extends JFrame implements ActionListener
    Container c;
    JMenuBar menubar;
    JMenu shape, color;
    JMenuItem circle, rectangle, line;
    JMenuItem red, green, blue, yellow;
    int col=0;
    Graphics g;

    DrawE ()
        c=getContentPane ();

        menubar=new JMenuBar ();
        shape=new JMenu ("Shape");
        color=new JMenu ("Color");
        circle=new JMenuItem ("Circle");
        rectangle=new JMenuItem ("Rectangle");
        line=new JMenuItem ("Line");
        red=new JMenuItem ("Red");
        green=new JMenuItem ("Green");
        blue=new JMenuItem ("Blue");
        yellow=new JMenuItem ("Yellow");

        shape.add (circle);
        shape.add (rectangle);
        shape.add (line);
        color.add (red);
        color.add (green);
        color.add (blue);
        color.add (yellow);
        menubar.add (shape);
        menubar.add (color);        

        setJMenuBar (menubar);

        c.setLayout (new FlowLayout (0) );
        setSize (600, 600);
        setTitle ("Draw Shape");
        setVisible (true);

        circle.addActionListener (this);
        rectangle.addActionListener (this);
        line.addActionListener (this);

        red.addActionListener (this);
        green.addActionListener (this);
        blue.addActionListener (this);
        yellow.addActionListener (this);


    public void actionPerformed (ActionEvent ae)
        g=getGraphics ();
        if (col==1)
            g.setColor (Color.red);
        if (col==2)
            g.setColor (Color.green);
        if (col==3)
            g.setColor (Color.blue);
        if (col==4)
            g.setColor (Color.yellow);

        if (ae.getSource () == red)
        if (ae.getSource () == green)
        if (ae.getSource () == blue)
        if (ae.getSource () == yellow)

        if (ae.getSource() == circle)
            g.clearRect (0, 20, 600, 600);
            g.fillOval (150, 150, 400, 400);
        if (ae.getSource() == rectangle)
            g.clearRect (0, 20, 600, 600);
            g.fillRect (150, 150, 400, 400);
        if (ae.getSource() == line)
            g.clearRect (0, 20, 600, 600);
            g.drawLine (150, 150, 400, 400);


    public static void main (String args [] )
        new DrawE ();

but what the code for paint application in web application in java??

Harshit686 : did you happen to notice that this thread is 6 years old and far from active? don't disturb the dead. read their headstones (the previous posts) for some info but don't let a number of zombie threads take over the forum.

that been said: if you want code, either write it, or hire someone to do it for you. don't just come here and ask for it.

if you come into trouble during the writing, not a problem, post your question with the relevant code and error messages or behaviour issues here (in a new thread, not this one) and tons of good developers will spend their spare time trying to solve it with you, so what do you have to loose by trying?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.