Results 1 to 3 of 3
- 05-02-2012, 06:24 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 20
- Rep Power
- 0
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)
Sorry for my bad english. and if there is anything thats unclear i will try to explain it in a better wayJava 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(); } }
Driiper
- 05-02-2012, 06:55 PM #2
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) ?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-02-2012, 07:27 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
paint error, with a simple boolean
By PRW56 in forum New To JavaReplies: 16Last Post: 04-05-2012, 09:08 AM -
Trying to create a simple web app
By xhunter in forum New To JavaReplies: 1Last Post: 02-11-2011, 08:25 PM -
New simple application using a simple database
By webbusiness23 in forum New To JavaReplies: 9Last Post: 08-03-2009, 02:55 AM -
Simple Paint program question
By StressaJune in forum New To JavaReplies: 1Last Post: 03-30-2009, 08:46 PM -
How to create Animation: Paint and thread
By Java Tip in forum java.awtReplies: 0Last Post: 06-21-2008, 08:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks