Results 1 to 4 of 4
  1. #1
    scopene is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Graphics problems

    So here's my problem it's simple I hope, Currently I'm using a paint method in Class2 to paint many different graphic objects, the problem is when i paint a lot of things it starts lagging and has to repaint the whole map and everything over again, is there a way of making it paint once and stay or maybe some way of rendering it so it only has to paint once?

    BTW: I know its wrong section but i wasn't getting anyone to help me..

    Java Code:
    public class Class1{
        
        JFrame MainFrame = new JFrame();
        JPanel MainPanel = new Class2();
        JScrollPane MainPane = new JScrollPane(MainPanel);
        
        public Class1(){
            MainFrame.setTitle("TEST");
            MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MainFrame.add(MainPane);
            MainPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            MainPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            MainPanel.setPreferredSize(new Dimension(100000, 100000));
            MainFrame.setSize(810, 630);
            MainFrame.setVisible(true);
            MainFrame.setResizable(false);
            MainFrame.setLocationRelativeTo(null);
            
        }
        
        public static void main(String[] args){
            Class1 class1 = new Class1();
        }
    }
    Java Code:
    public class Class2 extends JPanel{
        
        public Class2(){
            setBackground(Color.green);
            setFocusable(true);
        }
        
        public void paintComponent(Graphics g){
        super.paintComponent(g);
        mapGraphics(g); objectsGrahpics(g); playerText(g); playerGraphics(g);
        }
            
        private void objectsGrahpics(Graphics g){
            Graphics2D objectsGrahpics = (Graphics2D) g;
            g.drawString("Test", 25,25);
        }
        
        private void mapGraphics(Graphics g){
            Graphics2D mapGraphics = (Graphics2D) g;
    g.drawString("Test", 50,60);
        }
        
        private void playerText(Graphics g){
        }
        
        private void playerGraphics(Graphics g){
            Graphics2D CarGraphics = (Graphics2D) g;
    
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Graphics problems

    is there a way of making it paint once
    Create a BufferedImage object, get its Graphics object and draw your images on the BufferedImage.
    Then in the paint method, draw that one image.

    Does the image change much or is it always the same?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    scopene is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Graphics problems

    No it never changes, trying this right now.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Graphics problems

    Additionally -


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

Similar Threads

  1. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  2. Drawing a graphics onto another Graphics ?
    By Ziden in forum Java Applets
    Replies: 0
    Last Post: 01-08-2011, 07:30 PM
  3. How to use graphics
    By Mattedatten in forum New To Java
    Replies: 3
    Last Post: 03-18-2010, 02:10 PM
  4. Replies: 2
    Last Post: 01-16-2010, 04:50 PM
  5. Problems with Graphics and a Timer...
    By r0binho0d in forum Java Applets
    Replies: 5
    Last Post: 07-26-2008, 03:03 AM

Posting Permissions

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