Results 1 to 3 of 3
  1. #1
    driiper is offline Member
    Join Date
    Apr 2012
    Posts
    25
    Rep Power
    0

    Default Trying to create a simple Paint application

    Hello.

    Im currently fiddling around with some drawing functions in Java, but i'm having some problems getting it to work.


    So as the title states, im trying create a application which lets you paint inside the window. and atm i'm using the "fillOval" to draw on the screen.

    I have managed to draw the Oval on the screen, but the OLD position which i already have drawed wont "save " itself.

    I know that is because i have no function to handle the old drawings on the screen and it seems like its just getting overwrited.

    Now my question is, how would i proceed in save the old oval position so its possible to actually draw stuff.

    Variables:
    Java Code:
     private int Start_posY = 0;
    	 private int Start_posX = 0;
    	 private int End_posY = 0;
    	 private int End_posX = 0;
    	 
    	 
    	 private int boldness = 10; //Tykkelsen


    My paint component looks like this (Yeh i know, im new to drawing in java)
    Java Code:
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    	
    		g.setColor(Color.BLUE);
    		g.fillOval(Start_posX, Start_posY, boldness, boldness); 
    		
    
    	}

    and the Mouse(Event)(MotionEvent)
    Java Code:
    public void mouseDragged(MouseEvent arg0) {
    		//System.out.println("Lol");	
    		Start_posY = arg0.getY() - boldness /2;
    		Start_posX = arg0.getX() - boldness /2;
    		this.repaint();
    	
    
    public void mousePressed(MouseEvent e) {
    		System.out.println("Lol");	
    		Start_posY = e.getY() - boldness /2;
    		Start_posX = e.getX() - boldness /2;
    		repaint();
    	}
    }
    Sorry for my bad english. and if there is anything thats unclear i will try to explain it in a better way

    Driiper

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Trying to create a simple Paint application

    Use a List<Shape> populated with Ellipse2D. You'll need to cast the Graphics reference to Graphics2D in your paintComponent(..) override, then iterate over the List drawing/filling each Shape.

    Have you gone through the tutorial Trail: 2D Graphics (The Java™ Tutorials) ?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    driiper is offline Member
    Join Date
    Apr 2012
    Posts
    25
    Rep Power
    0

    Default Re: Trying to create a simple Paint application

    Have you gone through the tutorial Trail: 2D Graphics (The Java™ Tutorials) ?
    I have not looked at these tutorials, but i will be going through them now. Also thanks for the answer regarding List<Shape> etc. ill try this! thanks!

Similar Threads

  1. paint error, with a simple boolean
    By PRW56 in forum New To Java
    Replies: 16
    Last Post: 04-05-2012, 10:08 AM
  2. Trying to create a simple web app
    By xhunter in forum New To Java
    Replies: 1
    Last Post: 02-11-2011, 09:25 PM
  3. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 03:55 AM
  4. Simple Paint program question
    By StressaJune in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 09:46 PM
  5. How to create Animation: Paint and thread
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •