Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Jar Embedded in Website: Double Buffering Issue?

  1. #1
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Lightbulb Jar Embedded in Website: Double Buffering Issue?

    I'm not sure if this would be the correct post, but I've started some simple development for my portfolio website. I embedded several different jars (as tests) with an Object tag and they all uploaded correctly. However, only 1 out of the many programs repainted correctly.

    The problem:

    The program flashes a lot. It will take the current background and display it (usually white/black) on top of the Images/Drawn shapes. However, if the program is receiving constant Mouse input, the program will display everything correctly.

    Would this be a double buffering issue? None of my programs have been double buffered, and this is because they never required it. I use a Mac, and a good friend of mine can run my programs and view them perfectly.. But for others, who use Windows (probably a coincidence), have the same issue as I am having with the website.

    I can post further information if necessary, and any help/advice would be great. I understand the basic concept of Double Buffering as well, but would like to know a bit more if possible as well. Thanks!
    Simplicity calls for Complexity. Think about it.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    I embedded several different jars (as tests) with an Object tag and they all uploaded correctly
    I am confused by this statement. Do you mean they are applets?

    The program flashes a lot
    Typically has to do with incorrect java2D painting, and nothing to do with double buffering. Construct an SSCCE to demonstrate.

  3. #3
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    Quote Originally Posted by copeg View Post
    I am confused by this statement. Do you mean they are applets?
    Sorry about that. They're .jar files. It's easier/faster to upload the several classes using a Jar instead of an Applet.

    Here is the HTML snippet.
    HTML Code:
          <!--[if !IE]>-->
          <object class="feature-item" classid="java:Main.class" 
                  type="application/x-java-applet"
                  archive="projects/Minesweeper.jar" 
                  height="425" width="500" >
            <!-- Backup param -->
            <param name="archive" value="projects/Minesweeper.jar" />
          <!--<![endif]-->
            <object class="feature-item" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
                    height="425" width="500" > 
              <param name="code" value="Main" />
              <param name="archive" value="projects/Minesweeper.jar" />
            </object> 
    Here is the dummy code that represents what I'm doing. If you'd like to see the actual page, I can send over the URL.
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;
     
    import javax.swing.JFrame;
     
    @SuppressWarnings("serial")
    public class Main extends Applet implements Runnable {
     
    	public static int FPS = 10;
    	public static int WIDTH = 500;
    	public static int HEIGHT = 500;
    	public static Minesweeper game;
     
    	public Main(){
    		init();
    		game = new Minesweeper();
    	}
     
    	public void init() {
    		setSize(WIDTH, HEIGHT);
    		setBackground(Color.gray);
    	}
     
    	public void run() {
    		while (true) {
    			repaint();
    			try {
    				Thread.sleep(1000 / FPS);
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    	}
     
    	public void stop() {
    	}
     
    	public void start() {
    		new Thread(this).start();
    	}
     
    	public void paint(Graphics g) {
    		game.draw(g);
    	}
     
    	public static void main(String args[]){
    		JFrame frame = new JFrame();
    		Applet app = new Main();
    		frame.add(app);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(Main.WIDTH, Main.HEIGHT);
    		frame.setTitle("SSCCE");
    		frame.setResizable(false);
    		frame.setVisible(false);
                    app.init();
                    app.start();
    	}
     
    }

    What constitutes incorrect Java 2D Painting? My program draws perfectly fine on my computer. It just doesn't look great when distributing to others/my website.
    Last edited by Staticity; July 16th, 2012 at 02:40 PM. Reason: More information added
    Simplicity calls for Complexity. Think about it.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    The posted code is not an SSCCE that reproduces the problem (I have no clue what is in the Minesweeper class), so one can only guess. Perhaps someone else has better eyes than I because I don't see much aside from small things like calling super.paint() or that the game.draw method takes too long

    What constitutes incorrect Java 2D Painting?
    Things like painting to a graphics object of a Swing component that was retrieved from calling getGraphics(), not understanding the EDT and calling Thread.sleep from within the EDT, and many more things that could be more context dependent...I don't see anything glaring in this code (repaint() is thread safe)

  5. #5
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    Quote Originally Posted by copeg View Post
    The posted code is not an SSCCE that reproduces the problem (I have no clue what is in the Minesweeper class)
    Like I've stated, there is nothing fundamentally incorrect with the way I have been drawing anything. If I run the program on my computer, it looks fine. Also considering that one of my other friend's could run it as well without problems, gives me a bit of support.

    I'm trying to figure out what confounding problem is, causing the program to display the way it is. My friend also programs frequently, so maybe it has something to do with older Java versions? I'm not sure.

    I only know this:

    - My program does work without error
    - My program doesn't display well on websites/some computers
    - I am not double buffering
    - The program remains black/white screened until mouse movement
    therefore...
    - When constantly moving the mouse over the Program (in the website), it displays perfectly fine

    I'm not trying to sound rude, and sorry if I am. I just don't believe anything is necessarily wrong with my code. I just want to understand what I need to do to make the program display well for others. I don't want to create something that only displays well for myself.

    Edit: I have a feeling that it has something to do with obtaining focus, or something of the sort. I'm not too knowledgeable on this, but if the program won't update the screen until it receives input (in websites/other computers), maybe that's where we should start from.
    Last edited by Staticity; July 16th, 2012 at 03:09 PM.
    Simplicity calls for Complexity. Think about it.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    Here is what I recommend trying: change all your AWT classes to Swing classes - an Applet becomes a JApplet, a Panel a JPanel. Swing is by default double buffered. In doing so, override paintComponent, not paint. And always call super.paintComponent to invoke the parent class paintComponent method.

  7. #7
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Jar Embedded in Website: Double Buffering Issue?

    It seems like that didn't work for me, I had the same reuslt. Do you have any other suggestions perchance?
    Simplicity calls for Complexity. Think about it.

Similar Threads

  1. Android - SurfaceView flickers - Double Buffering
    By Nesh108 in forum Android Development
    Replies: 2
    Last Post: April 22nd, 2012, 06:09 AM
  2. Replies: 5
    Last Post: October 21st, 2011, 08:48 AM
  3. [SOLVED] embedded classes issue
    By Shocked in forum Object Oriented Programming
    Replies: 2
    Last Post: October 3rd, 2011, 12:09 PM
  4. Help With Double Buffering/Animations
    By bgroenks96 in forum Java Theory & Questions
    Replies: 1
    Last Post: July 18th, 2011, 06:58 PM
  5. Double Buffering
    By Ganezan in forum Java Theory & Questions
    Replies: 2
    Last Post: November 20th, 2009, 03:51 AM

Tags for this Thread