Help me make my painting go faster

Hi!
This is the paint code for my drawingprogram. It is a JPanel which contains everything that users has drawn AND is drawing. When I've drawn alot of objects then it starts getting slower and the painting can't follow up with my mouseDragged event. This is what I need fixed!
First off I paint all the objects that are STORED in a model. Then I start painting the object(only 1 at the time) that the user is CURRENTLY drawing.
All calls are made by invoking repaint().
question: should I override paint() or paintComponent()? What will be the difference.
I need some tips of how I can make this code quicker..I know for example I should use a different call to repaint by specifying only the area needed to paint out again. But do you have more tips?
public void paintComponent(Graphics gx)
        super.paintComponent(gx);
        Graphics2D g = (Graphics2D) gx.create();  //make a copy of the graphics object
        LinkedList listOfDrawingObjects = controller.getListOfDrawingObjects();
        LinkedList currentDrawingObjects = new LinkedList(listOfDrawingObjects); //make a copy to avoid ConcurrentModificationException
        ListIterator it = currentDrawingObjects.listIterator();
/* PAINT OUT ALL OBJECTS IN THE MODEL */
        while(it.hasNext())
            DrawingObject ob = (DrawingObject) it.next();
            if(ob instanceof MyLine)
                MyLine myLine = (MyLine) ob;
                g.setColor(myLine.getColor());
                g.setStroke(stroke.getDrawingStrokeSize(myLine.getStrokeSize()));
                g.drawLine((int)myLine.getX1(), (int)myLine.getY1(), (int)myLine.getX2(), (int)myLine.getY2());
            else if(ob instanceof MyRectangle)
                MyRectangle myRectangle = (MyRectangle) ob;
                g.setColor(myRectangle.getColor());
                g.setStroke(stroke.getDrawingStrokeSize(myRectangle.getStrokeSize()));
                if(myRectangle.getFilled())
                    g.fillRect((int)myRectangle.getX(), (int)myRectangle.getY(), (int)myRectangle.getWidth(), (int)myRectangle.getHeight());
                else
                    g.drawRect((int)myRectangle.getX(), (int)myRectangle.getY(), (int)myRectangle.getWidth(), (int)myRectangle.getHeight());     
            else if(ob instanceof MyOval)
                MyOval myOval = (MyOval) ob;
                g.setColor(myOval.getColor());
                g.setStroke(stroke.getDrawingStrokeSize(myOval.getStrokeSize()));
                if(myOval.getFilled())
                    g.fillOval((int)myOval.getX(), (int)myOval.getY(), (int)myOval.getWidth(), (int)myOval.getHeight());
                else
                    g.drawOval((int)myOval.getX(), (int)myOval.getY(), (int)myOval.getWidth(), (int)myOval.getHeight());
            else if(ob instanceof MyRoundRectangle)
                MyRoundRectangle myRoundRectangle = (MyRoundRectangle) ob;
                g.setColor(myRoundRectangle.getColor());
                 g.setStroke(stroke.getDrawingStrokeSize(myRoundRectangle.getStrokeSize()));
                if(myRoundRectangle.getFilled())
                    g.fillRoundRect((int)myRoundRectangle.getX(), (int)myRoundRectangle.getY(), (int)myRoundRectangle.getWidth(), (int)myRoundRectangle.getHeight(), (int)myRoundRectangle.getArcWidth(), (int)myRoundRectangle.getArcHeight());
                else
                    g.drawRoundRect((int)myRoundRectangle.getX(), (int)myRoundRectangle.getY(), (int)myRoundRectangle.getWidth(), (int)myRoundRectangle.getHeight(), (int)myRoundRectangle.getArcWidth(), (int)myRoundRectangle.getArcHeight());
            else if(ob instanceof MyFreeDraw)
            MyFreeDraw myFreeDraw = (MyFreeDraw) ob;
                g.setColor(myFreeDraw.getColor());
                g.setStroke(stroke.getDrawingStrokeSize(myFreeDraw.getStrokeSize()));
                LinkedList tempPoints = myFreeDraw.getAllPoints();
                LinkedList allPoints = new LinkedList(tempPoints); //avoids ConcurrentException
                if(allPoints.size()>=2)
                    ListIterator it2 = allPoints.listIterator(0);
                    ListIterator it3 = allPoints.listIterator(1); //must be one step ahead since two points are needed to draw
                    while(it2.hasNext() && it3.hasNext())
                        Object ob2 = it2.next();
                        Object ob3 = it3.next();
                        if(ob2 instanceof Point)
                            Point p = (Point) ob2;
                            Point t = (Point) ob3;
                            g.drawLine(p.x, p.y, t.x, t.y);
            else if(ob instanceof MyPolygon)
                MyPolygon myPolygon = (MyPolygon) ob;
                g.setColor(myPolygon.getColor());
                g.setStroke(stroke.getDrawingStrokeSize(myPolygon.getStrokeSize()));
                if(myPolygon.getFilled())
                    g.fillPolygon(myPolygon);
                else
                    g.drawPolygon(myPolygon);
            else if(ob instanceof MyText)
                MyText myText = (MyText) ob;
                g.setColor(myText.getColor());
                g.setFont(myText.getFont());
                g.drawString(myText.getText(), (int)myText.getStart().getX(), (int)myText.getStart().getY());
/* STARTS PAINTING OUT ALL TEMPORARY OBJECTS*/
        if(rectangle!=null && rectangle.getStart()!=null && rectangle.getStop()!=null)
            g.setColor(rectangle.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(rectangle.getStrokeSize()));
            if(rectangle.getFilled())
                g.fillRect((int)rectangle.getX(), (int)rectangle.getY(), (int)rectangle.getWidth(), (int)rectangle.getHeight());
            else
                g.drawRect((int)rectangle.getX(), (int)rectangle.getY(), (int)rectangle.getWidth(), (int)rectangle.getHeight());     
        else if(oval!=null && oval.getStart()!=null && oval.getStop()!=null)
            g.setColor(oval.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(oval.getStrokeSize()));
            if(oval.getFilled())
                g.fillOval((int)oval.getX(), (int)oval.getY(), (int)oval.getWidth(), (int)oval.getHeight());
            else
                g.drawOval((int)oval.getX(), (int)oval.getY(), (int)oval.getWidth(), (int)oval.getHeight());
        else if(line!=null && line.getStart()!=null && line.getStop()!=null)
            g.setColor(line.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(line.getStrokeSize()));
            g.drawLine((int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2());
        else if(roundRectangle!=null && roundRectangle.getStart()!=null && roundRectangle.getStop()!=null)
            g.setColor(roundRectangle.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(roundRectangle.getStrokeSize()));
            if(roundRectangle.getFilled())
                g.fillRoundRect((int)roundRectangle.getX(), (int)roundRectangle.getY(), (int)roundRectangle.getWidth(), (int)roundRectangle.getHeight(), (int)roundRectangle.getArcWidth(), (int)roundRectangle.getArcHeight());
            else
                g.drawRoundRect((int)roundRectangle.getX(), (int)roundRectangle.getY(), (int)roundRectangle.getWidth(), (int)roundRectangle.getHeight(), (int)roundRectangle.getArcWidth(), (int)roundRectangle.getArcHeight());
        else if(freeDraw!=null && freeDraw.getSize()>=2)
            g.setColor(freeDraw.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(freeDraw.getStrokeSize()));
            LinkedList tempPoints = freeDraw.getAllPoints();
            LinkedList allPoints = new LinkedList(tempPoints);
            if(allPoints.size()>=2)
                ListIterator it2 = allPoints.listIterator(0);
                ListIterator it3 = allPoints.listIterator(1); //must be one step ahead since two points are needed to draw
                while(it2.hasNext() && it3.hasNext())
                    Object ob2 = it2.next();
                    Object ob3 = it3.next();
                    if(ob2 instanceof Point)
                        Point p = (Point) ob2;
                        Point t = (Point) ob3;
                        g.drawLine(p.x, p.y, t.x, t.y);
        else if(polygon!=null && polygon.getStart()!=null && polygon.getStop()!=null)
            g.setColor(polygon.getColor());
            g.setStroke(stroke.getDrawingStrokeSize(polygon.getStrokeSize()));
            LinkedList temp = polygon.getAllLines();
            LinkedList linesList = new LinkedList(temp);
            ListIterator it2 = linesList.listIterator();
            while(it2.hasNext())
                MyLine tempLine = (MyLine) it2.next();
                g.drawLine((int)tempLine.getX1(), (int)tempLine.getY1(), (int)tempLine.getX2(), (int)tempLine.getY2());
            MyLine end = (MyLine) linesList.getLast();
            if(end!=null)
                g.drawLine((int)end.getX2(), (int)end.getY2(), (int)polygon.getStop().getX(), (int)polygon.getStop().getY());
        else if(text!=null && text.getStart()!=null)
            g.setColor(text.getColor());
            g.setFont(text.getFont());
            g.drawString(text.getText(), (int)text.getStart().getX(), (int)text.getStart().getY());
        g.dispose(); //release the copy of the graphics object
    }And here comes mouseDragged...(Not much of help maybe)
  public void mouseDragged(MouseEvent e)
        if(geometry==0 || geometry==3)
            freeDraw.mouseDragged(e);
            repaint();
        else if(geometry==1 || geometry==8)
            rectangle.mouseDragged(e);
            repaint();
         //   repaint((int)rectangle.getX(), (int)rectangle.getY(), (int)rectangle.getStop().getX(), (int)rectangle.getStop().getY());
        else if(geometry==2 || geometry==9)
            oval.mouseDragged(e);
            repaint();
        else if(geometry==4)
            line.mouseDragged(e);
            repaint();
        else if(geometry==6 || geometry==11)
            roundRectangle.mouseDragged(e);
            repaint();
    }

thanks!
advice nr.2 was good! good enough for 2 duke stars! :)
Looks better now (any more ways)?:
    public void paintComponent(Graphics gx)
        super.paintComponent(gx);
        Graphics2D g = (Graphics2D) gx.create();  //make a copy of the graphics object
        LinkedList listOfDrawingObjects = controller.getListOfDrawingObjects();
        LinkedList currentDrawingObjects = new LinkedList(listOfDrawingObjects); //make a copy to avoid ConcurrentModificationException
        ListIterator it = currentDrawingObjects.listIterator();
        while(it.hasNext())
            DrawingObject ob = (DrawingObject) it.next();
            ob.paint(g);
        if(rectangle!=null && rectangle.getStart()!=null && rectangle.getStop()!=null)
            rectangle.paint(g);
        else if(oval!=null && oval.getStart()!=null && oval.getStop()!=null)
            oval.paint(g);
        else if(line!=null && line.getStart()!=null && line.getStop()!=null)
            line.paint(g);
        else if(roundRectangle!=null && roundRectangle.getStart()!=null && roundRectangle.getStop()!=null)
            roundRectangle.paint(g);
        else if(freeDraw!=null && freeDraw.getSize()>=2)
            freeDraw.paint(g);
        else if(polygon!=null && polygon.getStart()!=null && polygon.getStop()!=null)
            polygon.paint(g);
        else if(text!=null && text.getStart()!=null)
            text.paint(g);
        g.dispose(); //release the copy of the graphics object
     }Message was edited by:
CbbLe
Message was edited by:
CbbLe

Similar Messages

  • Help needed in optimizing painting logic

    Hi,
    I am working on a Applet where i have to do a lot of painting, the applet is kind of microsoft project, where u can define a activity as a rectangle and then u can select the rectangle and drag it to some other date,
    i am posting a code below, which i am using to draw all the rectangles,
    but some times when there is a lot of data scrolling is really very slow
    Can any one look at the code, and let help me optimize it,
    U can copy the code, compile and run it to see what i mean by slow,
    just in class data , change the value 600 to some thing less like 50 and it works very fast
    //start code
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.ArrayList;
    public class TestDisplaySize extends JFrame
         private     JScrollPane scrollPane ;
         private MyPanel panel ;
         public TestDisplaySize()
              super("layered pane");
              this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              panel = new MyPanel();
              scrollPane = new JScrollPane(panel);
              Container contentPane = this.getContentPane();
              contentPane.add(scrollPane, BorderLayout.CENTER);
              setSize(new Dimension(800,600));
              this.setVisible(true);
              JViewport viewPort = scrollPane.getViewport();
         class MyPanel extends JPanel
              private int height;
              private int last;
              private Data data;
              public MyPanel()
         this.setBackground(Color.white);
         this.setOpaque(true);
         data = new Data();
         int size = data.getSize();
         height = size * 50;     
         last = data.getDataSize(0);
         int last1 = last -1;
         int length = data.getX(0, last1) + 100;
         System.out.println ("Lenght " + length + " height " + height);
         setPreferredSize(new Dimension(length, height) );     
         public void paintComponent(Graphics g)
    super.paintComponent(g);
    setBackground(Color.white);
    Rectangle r = scrollPane.getViewport().getViewRect();
    g.setClip((Shape)r);
    g.setColor(Color.blue);
    int x = 0;
    for(int i = 0; i < last ; i++)
         x +=60;
         g.drawLine(x, 0, x, height);
         g.drawString(String.valueOf(i), x, 10);
    int size = data.getSize();
    int width = 30;
    int height = 20;
    int yAxis = 20;
    g.setColor(Color.cyan);
    for(int i = 0; i < size; i++)
         int dataSize = data.getDataSize(i);
         for(int k = 0; k < dataSize; k++)
              int xAxis = data.getX(i, k);
              g.fill3DRect(xAxis, yAxis, width, height, true);
         yAxis = yAxis + 50;
    private class Data
              private ArrayList totalData = new ArrayList();
              public Data()
                        for(int i = 0; i < 600; i++)
                        ArrayList data = new ArrayList();
                        int l = 50;
                        for(int k = 0; k < 600; k++)
                             data.add(new Integer(l));
                             l = l + 50;
                        totalData.add(data);
              public int getSize()
                   return totalData.size();     
              public int getDataSize(int i)
                   return ((ArrayList)totalData.get(i)).size();     
              public int getX(int x, int y)
                   ArrayList data = (ArrayList)totalData.get(x);
                   Integer i = (Integer)data.get(y);
                   return i.intValue();
         public static void main(String args[])
         new TestDisplaySize();

    You should only paint what is visible. For example if you are presenting a grid of 100 x 100 boxes. And each box is 20 pixels wide and 20 pixels high, then that would create an <image> the size of 2000 x 2000. That is big ;-)
    What you want to do, is calculate what portion of the <image> that is viewable in your scrollpane and then only perform the paint operations on those boxes. For example, if the viewports width is 200 and its hieght is 80, then you should only paint 10 x 4 boxes (40 boxes total, each 20x20 pixels in size) -- The trick is figuring out what boxes need to be painted.!! I'll leave that up to you, but should be able to find code examples on the net doing something of this sort.
    Hope this helps, and makes sense.
    Cory

  • How can I make my adodc connect faster to my SQL Server? It's taking a minute (so long) before I can view thousand of record in my listview.

    How can I make my adodc connect faster to my SQL Server? It's taking a minute (so long) before I can view thousand of record in my listview. Please anyone help me.
    I'm using this code:
    Public Class McheckpaymentNew
    Private cn As New ADODB.Connection
    Private rs As New ADODB.Recordset
    Private Sub McheckpaymentNew_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
    cn.ConnectionString = "DSN=database; UID=user; PWD=password"
    cn.Open()
    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
    rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
    Catch ex As Exception
    MsgBox("Failed to Connect!, Please check your Network Connections, or Contact MIS Dept. for assistance.", vbCritical, "Error while Connecting to Database.."
    End
    End Try
    End Sub
    End Class

    How can I make my adodc connect faster to my SQL Server? It's taking a minute (so long) before I can view thousand of record in my listview. Please anyone help me.
    I'm using this code:
    Public Class McheckpaymentNew
    Private cn As New ADODB.Connection
    Private rs As New ADODB.Recordset
    Private Sub McheckpaymentNew_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
    cn.ConnectionString = "DSN=database; UID=user; PWD=password"
    cn.Open()
    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
    rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
    Catch ex As Exception
    MsgBox("Failed to Connect!, Please check your Network Connections, or Contact MIS Dept. for assistance.", vbCritical, "Error while Connecting to Database.."
    End
    End Try
    End Sub
    End Class

  • How to make a painting

    How to make a painting with Photoshop Touch
    Experiment with different painting styles. Use a variety of brush stroke effects to create different looks.
    1. After selecting the "Make a Painting" tutorial, press "Begin Tutorial" to start. Tap Adjustments > Saturation.
    2. Set the value to 100% to intensify the colors. Tap OK.
    3. Tap Add Layer > Duplicate Layer. You'll create the painting on this layer.
    4. Tap Effects > Artistic > Acrylic Paint
    5. Enter these values: Jitter= 85%, Size= 20%, Length= 0%, Tap OK. This creates a pointillist effect.
    6. Tap the target on this layer to hide it. Tap the bottom layer.
    7. Tap Effects > Artistic > Acrylic Paint
    8. For an abstract brush effect, enter these values: Jitter= 100%, Size= 30%, Length=138%. Tap OK.
    Tip: To enter the percentage by number instead of using the slider, tap the value field to open the keyboard editor.
    9. Tap the target on the top layer to unhide it and decide which effect you like best.
    Tip: To delete an unwanted layer, choose the layer in the layers panel. Tap Layer options > Delete layer to remove the layer.
    10. Tap the back arrow in the top options bar. This will prompt you to save. Press Save to save your project.
    Download the attachment to view the tutorial in PDF format.
    Janelle

    again thank's for your answer but I try all of things in this site and what can help me is this
    http://nonlinear.openspark.com/tips/xtras/multiuser/whiteboard/index.htm
    ifI could change size and the main page of it without any problem could you say me why it dose'nt work corectly after changing?

  • How Can i clean my memory and make my imac more faster ?

    I am new user in mac i have imac 4 g ram  and need a way to clean the memory and make my imac more faster ...

    You can't "clean" RAM. If the "storage" space on your hard drive isn't enough then put in a larger hard drive or delete any of your data you no longer need or can store on an external drive. Beyond this I cannot say because you have not provided enough information such as the amount of installed RAM, Capacity of your hard drive and the amount of available space on the hard drive, the specific iMac model you have.
    You can try reinstalling Lion:
    Reinstalling Lion Without the Installer
    Boot to the Recovery HD: Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alterhatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Repair the Hard Drive and Permissions: Upon startup select Disk Utility from the main menu. Repair the Hard Drive and Permissions as follows.
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the main menu.
    Reinstall Lion: Select Reinstall Lion and click on the Continue button.
    Note: You can also re-download the Lion installer by opening the App Store application. Hold down the OPTION key and click on the Purchases icon in the toolbar. You should now see an active Install button to the right of your Lion purchase entry. There are situations in which this will not work. For example, if you are already booted into the Lion you originally purchased with your Apple ID or if an instance of the Lion installer is located anywhere on your computer.
    However, if your computer doesn't have enough RAM or your hard drive is full, then reinstalling won't help.

  • How to make a painting book?

    hi everybody I'm realy new in director and I want to make a paintting book  I found this example http://nonlinear.openspark.com/tips/xtras/multiuser/whiteboard/index.htm
    but i have 2 problem with it
    1) when I chane the size of it
    2) when I change the main page of it (green page) with my selected Image
    in these 2 situation it doesn't work corectly
    what I should do?

    again thank's for your answer but I try all of things in this site and what can help me is this
    http://nonlinear.openspark.com/tips/xtras/multiuser/whiteboard/index.htm
    ifI could change size and the main page of it without any problem could you say me why it dose'nt work corectly after changing?

  • Make my computer run faster

    I hope I can get some help here; Recently I purchased Fios in a hope that my computer would run faster after Fios instalation, but no difference at all, then I asked the technician at verizon, they forwarded me to another verizon department to register for a service which will help about the computer run better, and that is $14 a month.
    Is there any other easy way or trick that makes your computer run faster, or what actually causes the computer to slow down? My friend told me that if you don't delete the long emails will slow it as well, is it true?
    Any experienced input will be appreciated

     There are a number of things that may help, but none of them are likely to help a great deal unless your computer is infected with one or more viruses/malware.
    1). If  any of your HDD's partitions  FAT (as opposed to NTFS) format, defragmenting the disk may be helpful. In general NTFS partitions don't need to be defragmented. 
    2). Get rid of the temporary files. It is not uncommon for PC's to end up with literally gigabytes of temporary files. They are left over from software updates, installs, and Internet Explorer SNAFU's. (Do this BEFORE you Defragment the disk).
    Most temporary files either live in directories called temp, have names that start with ~ and/or end with .tmp
    3). Clean up the registry. While Windows will usually still run with a truly amazing number of registry errors, it usually runs better with a lot fewer of them. Software you see such as 'speed up my pc' advertised on Television are in fact registry 'cleaners'. The registry in windows is kind of the like telephone operator before the days of dial telephones.  There are a number of commercial products that do this, but in general you are going to have to buy one.
    4). Unless you are running Vista or Windows 7, try Verizon's high speed internet optimizer to tweak some of the internet settings for better performance.
    5). Uninstall any software that you aren't using.
    6). Use a good anti-virus/anti-malware/spyware program, and scan your HDD's on a regular basis for viruses and other malware.
    Cleaning up your emails is very low on my list of things that are likely to be helpful. 

  • How can i make my macbook run faster again?

    Hey, i own 15 inch macbook pro 2011 that came with snow leopard and i upgraded it to lion but i observed that my computer got slower speacially when i start up i wait much more longer than i used to.I don't have many programs downloaded i mean only 130 gb is used out 500 so, is there anything i can do to make my mac run faster? In addition i am thinking about to make participation with win7 does it affect the speed of my computer negative? Thank you.

    If you have only 4GBs of RAM, this article may help you - https://discussions.apple.com/thread/3238726
    You may need to upgrade the RAM or make changes to the apps you use..  Since your Hard Drive is nicely underutilized and is probably behaving well, that should not be the problem.
    Check to see if you are getting Page Outs and read the article above

  • How to make mac desktop run faster . It is starting to freeze up in Safari sometimes.

    How to make IMAC desktop run faster.

    Mavericks is the Operating System, while you could call it a program it's the OS. We need to know:
    what year iMac you have including the amount of RAM installed, the capacity of the internal HD and how much is stored on it and under what conditions the computer runs slowly. Please CAREFULLY read Help us to help you on these forums

  • HT1338 how to make my MacBook pro faster

    I was wondering if there is any software to clean and make my MacBook Pro faster and lighter???
    I heard about the MacKeeper but I get some negative feedback about it....

    MacKeeper is garbage.
    The best way to speed up your Mac is not to install garbage software, such as MacKeeper, or to uninstall it if you've already done so.
    Beyond that, you can increase performance by replacing the internal hard drive with an SSD and/or adding memory.

  • JScrollPane, JPanel used to make a paint-like application

    I am new to swing. I need help with implementing a paint-like application using JScrollPane and JPanel.
    I have put a JPanel inside a JScrollPane.
    The size of JPanel exceeds preferred size of JScrollPane, and i can see the scrollbars, and can go up and down.
    Problem is, when i draw on the JPanel, i can see what i've drawn very clearly. Now if I scroll down, and then scroll back up, whatever i had previously drawn has been erased.
    let me put it in a simpler manner. suppose i have drawn a filled circle whose diameter is equal to the viewport size of the JScrollPane. Now i am scrolling down till i can see only the bottom half of the circle. When i scroll back up, the upper half of the circle has been erased.
    i think this is a newbie error, and i guess it'll have a textbook response, so i have not bothered to paste my entire code here. however, if it is required, please let me know.

    Sounds very much like you're painting outside the paint cycle. Read this,
    http://java.sun.com/products/jfc/tsc/articles/painting/
    When the user draws on the screen, you want to do one of two things (these being just the most obvious and easiest implementations). For raster operations you want to manipulate an Image; for vector operations you want to manipulate a collection of Shapes.
    Your paintComponent() method of the panel should simply draw the stored images and shapes to the supplied Graphics object as appropriate.
    If you paint to a Graphics object outside the paint cycle then it will all be erased when the paint cycle is next invoked.

  • Is it necessary to "clean" your Mac?   I'm not s but I've been getting ads about cleaning your Mac.  What does it do?   Would it make surfing the web faster?  thanks

    HI,    is it necessary to "clean" your Mac?     I'm not sure what that means or what it does but I've been getting ads that offer to clean it.  Would doing that make surfing the web faster?   Thanks!

    Suggestions for Mac maintenance
    Make redundant backups, keeping at least one off-site at all times. One backup is not enough. Don’t back up your backups; make them independent of each other. Don’t rely completely on any single backup method, such as Time Machine.
    Keep your software up to date. Software Update can be set to notify you automatically of updates to the Mac OS. Some third-party applications have a similar feature, if you don’t mind letting them phone home. Otherwise you have to check yourself on a regular basis.
    Don't install crapware, such as “themes,” "haxies," “add-ons,” “toolbars,” “enhancers," “optimizers,” “accelerators,” “extenders,” “cleaners,” “defragmenters,” “firewalls,” “guardians,” “defenders,” “protectors,” most “plugins,” commercial "virus scanners,” or "utilities." With very few exceptions, this kind of material is useless, or worse than useless. The more actively promoted the product, the more likely it is to be garbage. The only software you should install is that which directly enables you to do the things you use a computer for — such as creating, communicating, and playing — and does not modify the way other software works. Never install any third-party software unless you know how to uninstall it.
    The free anti-malware application ClamXav is not crap, and although it’s not routinely needed, it may be useful in some environments, such as a mixed Mac-Windows enterprise network.
    Beware of trojans. A trojan is malicious software (“malware”) that the user is duped into installing voluntarily. Such attacks were rare on the Mac platform until recently, but are now increasingly common, and increasingly dangerous. There is some built-in protection against downloading malware, but you can’t rely on it — the attackers are always at least one day ahead of the defense. You can’t rely on third-party protection either. What you can rely on is common-sense awareness — not paranoia, which only makes you more vulnerable. Never install software from an untrustworthy or unknown source. If in doubt, do some research. Any website that prompts you to install a “codec” or “plugin” that comes from the same site, or an unknown site, is untrustworthy. Software with a known corporate brand, such as Adobe Flash, must be acquired directly from the developer. No intermediary is acceptable, and don’t trust links unless you know how to parse them. Any file that is automatically downloaded from a web page without your having requested it should go straight into the Trash. A website that claims you have a “virus,” or that anything else is wrong with your computer, is rogue.
    Relax, don’t do it. Besides the above, no routine maintenance is necessary or beneficial for the vast majority of users; specifically not “cleaning caches,” “zapping the PRAM,” “rebuilding the directory,” “running periodic scripts,” “deleting log files,” “scanning for viruses,” or “repairing permissions.” Such measures are for solving problems as they arise, not for maintenance. The very height of futility is running an expensive third-party application called “Disk Warrior” when nothing is wrong, or even when something is wrong and you have backups, which you must have. Don’t waste money on Disk Warrior or anything like it.

  • Need a Free designing program. for example: something to help me make shirt

    Need a Free designing program. for example: something to help me make shirt graphics, posters, and other designs. i do not think my mac came with any such program. i have ilife 08 but i dont think anything there can help me?

    Got to VersionTracker or MacUpdate and search.

  • How Can I make the following query faster

    Hi Guru
    I want your valuable suggestion to make the following query faster.I did not write all required columns list. I gave here all those columns where I have conditon like decode,case when,or subquery
    (SELECT CASE WHEN REPORTED_BY IS NULL THEN
              (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.EMP_NO_RADIO)
         ELSE (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.REPORTED_BY) END RADIOLOGIST_NAME,
         (SELECT TEAM_NAME FROM DC_TECHTEAMMST WHERE TEAM_NO = M.GROUP_NO) GROUP_NAME,
         CASE WHEN M.RESULT_ENTRY_LOCK_BY IS NOT NULL THEN 'R'
    WHEN M.REPORT_DONE = 'D' THEN 'D'
    WHEN M.REPORT_DONE = 'P' THEN 'P'
    WHEN M.REPORT_DONE = 'F' THEN 'F'
         WHEN NVL(M.IMG_CAPTURED,'X') NOT IN ('B','Y') OR M.QA_RESULT = 'F' THEN 'S'
    WHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') NOT IN ('B','P') THEN 'Q'
         wHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') IN ('B','P') THEN 'C'
    END STATUS,
         (SELECT DECODE(NVL(V.DELIVERY_STATUS,'N'),'E',3,'U',2,1)
              FROM FN_VOUCHERCHD V WHERE V.VOUCHER_NO = M.VOUCHER_NO AND V.ITEM_NO = M.TEST_NO) DELIVERY_STATUS,
         trunc((start_time-order_end)*24,0)||' hr'||':'||
         decode(length(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)),2,to_char(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0))
              ,1,to_char('0'||trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)))||' mi' duration_order_capture,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',NVL(R.NAME,R.name_lang_name||' '||R.name_lang_fname)) PAT_NAME,
         FNC_PATIENTAGE(R.REG_NO,'',R.CONFIDENTIAL_PATIENT) pat_age,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',R.PATIENT_SEX) PAT_SEX
    FROM DC_MODALITYAPPOINTMENT M,DC_TESTMST T,OP_REGISTRATION R
    WHERE M.ACCESSION_NO IS NOT NULL AND NVL(M.CANCEL_FLAG,'N') = 'N'
    AND (NVL(T.SP_GEN,'S') = 'S' OR NVL(M.DOC_REQ_GEN,'N') = 'Y')
    AND M.TEST_NO IS NOT NULL AND M.TEST_NO = T.TEST_NO AND M.REG_NO = R.REG_NO)
    How can I make the above query faster.
    Query condition or indexing whatever is preferable please guide me.
    The approximate data of tables
    DC_MODALITYAPPOINTMENT 2,000,000
    A lot of updating is going on some columns of this table.all columns are not in the select list, Insertion is happend in batch process by back-end trigger of another table.
    Primary key based one column,
    OP_REGISTRATION 500,000
    Daily insertion on this table around 500 records,updation is not much.
    Primary key based one column 'reg_no'
    DC_TESTMST
    Total records of this table not more than 1500.This is setup table. Insertion and updation is not much on this table also
    I have to create a view based on this query .
    and I have to create another view to serve another purpose.
    In the 2nd view I need this query as well as I need another query by using union all operator based on a table(dc_oldresult)
    which have 1,600,000 records.There is no DML on this table
    SELECT      NVL((SELECT USER_DEFINE_TEST_NO FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ),SV_ID) USER_D_EXAM_NO,
    (SELECT TEST_TYPE FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ) EXAM_TYPE,
         NVL((SELECT TEST_NAME FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1),'Exam Code: '||sv_id) EXAM_NAME,
         (SELECT PAT_NAME FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_NAME,
         (SELECT PAT_AGE FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_AGE,
         (SELECT PAT_SEX FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_GENDER
    FROM DC_OLDRESULT
    WHERE HN IS NOT NULL AND SV_ID IS NOT NULL AND UPPER(ACTIVE) = 'TRUE'
    Should I make join DC_OLDRESULT, OP_REGISTRATION and DC_TESTMST? or The eixisting subquery is better?
    I use OP_REGISTRATION and DC_TESTMST in both query
    Thanks in advance
    Mokarem

    When your query takes too long ...

  • Does turning off debugging help a compiled .exe file run faster?

    I'm trying to get my application to run faster.  I saw on this website that turning off the debugger makes the application run faster but it's unclear if that applies to the development platform or a compiled executable.

    You are probably referring to this KB article: General Performance Improvements. When you create a stand-alone application you can also enable debugging. This will save the block diagrams so you can debug the application while it's running. Normally when you build an app the block diagrams is stripped.
    The amount of impact that turning off debugging will have to your VI/app performance is hard to say. To best way to get a VI/app to run faster is to improve the code in the first place. This means avoiding very large memory arrays, not initializing and closing references every time you iterate in a loop, minimizing file I/O, etc. If you provide some idea of what your code does, and can perhaps post your code, specific suggestions can be provided. 

Maybe you are looking for