Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Slow drawing

Reply
Thread Tools

Slow drawing

 
 
AHM
Guest
Posts: n/a
 
      05-12-2004
Hi

I've got a problem with the code below and I'm hoping someone can help
me optimize it. What I want is to draw a horizontal line where the mouse
cursor is located in the panel. Unfortunately the drawing is a bit slow
resulting in the line being a little delayed as to where the mouse
cursor is. Can anyone help me sort this out?

[TestApplet.java]

import java.applet.Applet;
import java.awt.*;

public class TestApplet extends Applet {
TestPanel testPanel = new TestPanel();

public void init() {
this.setLayout(new BorderLayout());
add(testPanel, BorderLayout.CENTER);
}
}

[TestPanel.java]

import java.awt.*;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;

public class TestPanel extends Panel implements MouseMotionListener {
Graphics graphics;
Image image;
Dimension dimension;

int currentMousePositionY;

TestPanel() {
this.addMouseMotionListener(this);
this.setBackground(Color.white);
}

public Dimension getPreferredSize() {
return new Dimension(250, 300);
}
 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      05-12-2004

"AHM" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> Hi
>
> I've got a problem with the code below and I'm hoping someone can help
> me optimize it. What I want is to draw a horizontal line where the mouse
> cursor is located in the panel. Unfortunately the drawing is a bit slow
> resulting in the line being a little delayed as to where the mouse
> cursor is. Can anyone help me sort this out?
>
> [TestApplet.java]
>
> import java.applet.Applet;
> import java.awt.*;
>
> public class TestApplet extends Applet {
> TestPanel testPanel = new TestPanel();
>
> public void init() {
> this.setLayout(new BorderLayout());
> add(testPanel, BorderLayout.CENTER);
> }
> }
>
> [TestPanel.java]
>
> import java.awt.*;
> import java.awt.event.MouseMotionListener;
> import java.awt.event.MouseEvent;
>
> public class TestPanel extends Panel implements MouseMotionListener {
> Graphics graphics;
> Image image;
> Dimension dimension;
>
> int currentMousePositionY;
>
> TestPanel() {
> this.addMouseMotionListener(this);
> this.setBackground(Color.white);
> }
>
> public Dimension getPreferredSize() {
> return new Dimension(250, 300);
> }


optimise it... or write it?
I see no drawing code or listener code.

But you aren't likely to need Graphics as an attribute.

--
Mike W


 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      05-12-2004
AHM wrote:

> Hi
>
> I've got a problem with the code below and I'm hoping someone can help
> me optimize it. What I want is to draw a horizontal line where the mouse
> cursor is located in the panel. Unfortunately the drawing is a bit slow
> resulting in the line being a little delayed as to where the mouse
> cursor is. Can anyone help me sort this out?
>
> [TestApplet.java]
>
> import java.applet.Applet;
> import java.awt.*;
>
> public class TestApplet extends Applet {
> TestPanel testPanel = new TestPanel();
>
> public void init() {
> this.setLayout(new BorderLayout());
> add(testPanel, BorderLayout.CENTER);
> }
> }
>
> [TestPanel.java]
>
> import java.awt.*;
> import java.awt.event.MouseMotionListener;
> import java.awt.event.MouseEvent;
>
> public class TestPanel extends Panel implements MouseMotionListener {
> Graphics graphics;
> Image image;
> Dimension dimension;
>
> int currentMousePositionY;
>
> TestPanel() {
> this.addMouseMotionListener(this);
> this.setBackground(Color.white);
> }
>
> public Dimension getPreferredSize() {
> return new Dimension(250, 300);
> }


Your code was cut off (both times).

If you're subclassing Panel then it makes more sense to hook the
processMouseMotionEvent method to do your drawing than to register
objects as listeners on themselves. You might find it a little faster
(but don't forget to invoke the superclass' version either at the
beginning or at the end). I suspect the real problem is with the actual
drawing code, however, and that didn't make it here.


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: slow slow slow! Expert lino fitter Computer Support 5 12-12-2008 04:00 PM
Re: slow slow slow! Expert lino fitter Computer Support 0 12-10-2008 02:33 PM
Guide to the standard library? Library for drawing in GUIs?drawing inbrowsers? defn noob Java 1 06-28-2008 02:50 AM
funny drawing software:ScreenPen,drawing directly on screen! yyzzbb@sina.com Digital Photography 0 02-04-2006 12:31 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com ASP .Net 1 01-09-2006 09:55 PM



Advertisments