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 3 of 3

Thread: PLEASE HELP ME with double buffer

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation PLEASE HELP ME with double buffer

    // Chengcheng Guo
    // Computer science
    // january 1, 2010
    This may seem like a long code but it's not, it's just copys of each other.
    Can someone PLEASE help me put a double buffer into this? Thanks you sooo much!

    // year end project
    //ccg
    import java.applet.*;
    import java.awt.*;
    import java.awt.Font;
    import java.util.Random;
    import java.awt.event.*;
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.net.*;
    import java.io.*;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.awt.FlowLayout;
     
    public class Yearendversion2 extends Applet
    {
     
    // So the program never really ends
    static int neverending;
    static int userchoice;
    static int Enter;
    static int width = 35;
    Color brownColor = new Color (128, 64, 0);
    static int width2 = 1;
    static int length = 1;
    private Image car;
    private Image background;
    private Image star;
    private Image santa;
    private Image snowman;
     
    MediaTracker mt;
     
    public void init ()
    {
    Enter = -100;
    setFont (new Font ("Rockwell", Font.BOLD, 15));
    car = getImage (getDocumentBase (), "car.JPG");
    background = getImage (getDocumentBase (), "background.JPEG");
    santa = getImage (getDocumentBase (), "santa.GIF");
    snowman = getImage (getDocumentBase (), "snowman.GIF");
     
    } // init method
     
    public boolean keyDown (Event evt, int key) //user input
    {
    switch (key)
    {
    case 's':
    Enter = -100;
    break;
    case Event.ENTER:
    Enter = -99;
    break;
    case '1':
    Enter = 1;
    break;
    case '2':
    Enter = 2;
    break;
    case '3':
    Enter = 3;
    break;
    case '4':
    Enter = 4;
    break;
    case '5':
    Enter = 5;
    break;
    case '6':
    Enter = 6;
    break;
    case '7':
    Enter = 7;
    break;
    case '8':
    Enter = 8;
    break;
    case 'x':
    Enter = -98;
    break;
    case 'z':
    Enter = -97;
    break;
     
    default:
    Enter = 0;
    }
    repaint ();
    return true;
    }
     
    public void paint (Graphics g)
    {
     
    if (Enter == -100)
    {
    g.setColor (Color.black);
    //The the questions and commands
    for (int loop = 1 ; loop < 600 ; loop = loop + 25)
    {
    //the directions of what the user should do
    g.drawString ("Loading...AND also press on the screen", 50, 50);
    //the loading bar
    g.fillRect (width + loop, 250, 10, 10);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    //the command for the user after the loading screen
    if (loop > 550)
    {
    g.drawString ("Press 'ENTER' to start", 50, 400);
    }
    }
    }
    if (Enter == -99)
    {
    g.setColor (Color.black);
    //The the questions and commands
    g.drawString ("Welcome to chengcheng's Year End project for Computer Science", 0, 40);
    g.drawString ("To return to this screen please press (ENTER)", 0, 60);
    g.drawString ("Please enter a number from the list below", 0, 120);
    g.drawString ("Please enter (1) if you want to see the lights on the house flash", 0, 140);
    g.drawString ("Please enter (2) if you want to see smoke comming out of the chimney", 0, 160);
    g.drawString ("Please enter (3) if you want to see the lights on the tree flash", 0, 180);
    g.drawString ("Please enter (4) if you want to see the moon move while changing colors", 0, 200);
    g.drawString ("Please enter (5) if you want to the stars flash", 0, 220);
    g.drawString ("Please enter (6) if you want to see the car drive", 0, 240);
    g.drawString ("Please enter (7) and HOLD down (7) if to see the scene made with a additional pictres imported", 0, 260);
     
    }
    if (Enter == 1)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 1", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
     
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the lights on the house flash", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    for (int loop = 1 ; loop < 30 ; loop++)
    {
    Random rand = new Random ();
    int x = 6 + rand.nextInt (240);
    Random rand2 = new Random ();
    int y = 6 + rand.nextInt (240);
    Random rand3 = new Random ();
    int z = 6 + rand.nextInt (240);
    Color randomcolor = new Color (x, y, z);
    g.setColor (randomcolor);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
     
    } //The end of scene one
    if (Enter == 2)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 2", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the smoke come out of the house", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    //The smoke
    for (int loop = 1 ; loop < 150 ; loop = loop + 5)
    {
    g.setColor (Color.gray);
    g.fillOval (265 - width2, 150 - loop, 10 + width2, 10 + length);
    length = length + length;
    width = width + width;
    if (width > 15)
    {
    width = 1;
    length = 1;
    }
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the smoke come out of the house", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    }
     
    } //The end of scene two
    if (Enter == 3)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 3", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the lights on the tree flash", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    for (int loop = 1 ; loop < 15 ; loop++)
    {
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    g.setColor (Color.red);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.blue);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
     
    } //The end of scene three
    if (Enter == 4)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 4", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the moon move while flashing", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    int movement = 5;
    int total = 500;
    for (int loop = 1 ; loop < 15 ; loop++)
    {
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (total = total - movement, 0, 150, 150);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the moon move while flashing", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    g.setColor (Color.red);
    g.fillOval (total = total - movement, 0, 150, 150);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the moon move while flashing", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
     
    }
    g.setColor (Color.red);
    g.fillOval (500, 0, 150, 150);
    } //The end of scene four
    if (Enter == 5)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 5", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the stars flash", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    //The lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //Stars
    for (int loop = 1 ; loop < 25 ; loop++)
    {
    Random rand = new Random ();
    int x = 6 + rand.nextInt (240);
    Random rand2 = new Random ();
    int y = 6 + rand.nextInt (240);
    Random rand3 = new Random ();
    int z = 6 + rand.nextInt (240);
    Color randomcolor = new Color (x, y, z);
    g.setColor (randomcolor);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    } //The end of scene five
    if (Enter == 6)
     
    {
    for (int loop = 1 ; loop < 361 ; loop = loop + 10)
    {
    g.setColor (Color.black);
    //the directions of what the user should do
    g.drawString ("Chengcheng's computer science project part 6", 50, 50);
    //the loading bar
    g.fillArc (240, 175, 170, 170, 0, 10 + loop);
    g.setColor (Color.white);
    g.drawString ("L O A D I N G . . .", 265, 265);
    //delaying the loading screen
    try
    {
    Thread.sleep (200); // do nothing for 200 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    }
    //The Main Background Also Known As The Sky
    g.setColor (Color.black);
    g.fillRect (0, 0, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the car move", 0, 490);
    g.drawString ("When the flashing comes to a conclusion press (ENTER) to return to the menu screen", 0, 470);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.fillOval (100, 150, 200, 200);
    //The Chimney
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.gray);
    g.fillRect (185, 310, 30, 40);
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The Tree
    g.setColor (brownColor);
    g.fillRect (450, 290, 30, 60);
    g.setColor (Color.green);
    g.fillArc (400, 210, 125, 200, 0, 180);
    //The Moon
    g.setColor (Color.yellow);
    g.fillOval (500, 0, 150, 150);
    //Stars
    g.setColor (Color.yellow);
    g.fillRect (100, 10, 1, 10);
    g.fillRect (95, 15, 10, 1);
    g.fillRect (120, 40, 1, 10);
    g.fillRect (115, 45, 10, 1);
    g.fillRect (10, 0, 1, 10);
    g.fillRect (5, 5, 10, 1);
    g.fillRect (150, 30, 1, 10);
    g.fillRect (145, 35, 10, 1);
    g.fillRect (230, 60, 1, 10);
    g.fillRect (225, 65, 10, 1);
    g.fillRect (360, 50, 1, 10);
    g.fillRect (355, 55, 10, 1);
    g.fillRect (30, 20, 1, 10);
    g.fillRect (25, 25, 10, 1);
    g.fillRect (320, 70, 1, 10);
    g.fillRect (315, 75, 10, 1);
    g.fillRect (80, 50, 1, 10);
    g.fillRect (75, 55, 10, 1);
    g.fillRect (300, 5, 1, 10);
    g.fillRect (295, 10, 10, 1);
    g.fillRect (320, 20, 1, 10);
    g.fillRect (315, 25, 10, 1);
    g.fillRect (220, 20, 1, 10);
    g.fillRect (215, 25, 10, 1);
    g.fillRect (250, 40, 1, 10);
    g.fillRect (245, 45, 10, 1);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.gray);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    //Lights on the trees
    g.setColor (Color.blue);
    g.fillOval (480, 280, 20, 20);
    g.fillOval (420, 275, 20, 20);
    g.fillOval (450, 280, 20, 20);
    g.fillOval (475, 250, 20, 20);
    g.fillOval (445, 245, 20, 20);
    g.setColor (Color.red);
    g.fillOval (435, 225, 20, 20);
    g.fillOval (415, 250, 20, 20);
    g.fillOval (465, 215, 20, 20);
    g.fillOval (495, 265, 20, 20);
    //movement for the car
    int movement = 0;
    for (int loop = 1 ; loop < 660 ; loop = loop + 1)
    {
    //inporting the car
    g.drawImage (car, movement, 425, null);
    movement = movement + 1;
    try
    {
    Thread.sleep (2); // do nothing for 2 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
    //The Street
    g.setColor (Color.lightGray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    try
    {
    Thread.sleep (2); // do nothing for 2 miliseconds
    }
    catch (InterruptedException e)
    {
    e.printStackTrace ();
    }
     
    }
     
    } //The end of scene six
    if (Enter == 7)
     
    {
     
    //new background picture
    g.drawImage (background, 0, 0, null);
    //The Main Background Also Known As The Sky
    g.setColor (Color.white);
    g.fillRect (0, 300, 800, 350);
    //tell user how to return
    g.setColor (Color.black);
    g.drawString ("You have chosen to watch the imported pictures - Hold 7 -", 0, 490);
    g.drawString ("Press (ENTER) to return to the menu screen", 0, 470);
    //The Street
    g.setColor (Color.gray);
    g.fillRect (185, 350, 30, 100);
    g.fillRect (0, 420, 800, 30);
    //The House
    g.setColor (Color.lightGray);
    g.fillRect (100, 200, 200, 150);
    //The Roof
    g.setColor (Color.lightGray);
    g.fillOval (100, 150, 200, 200);
    //Windows Of The House (square) + Windows Of The House (circles)
    g.setColor (Color.black);
    g.drawRect (140, 225, 20, 20);
    g.drawRect (190, 225, 20, 20);
    g.drawRect (140, 275, 20, 20);
    g.drawRect (190, 275, 20, 20);
    g.drawRect (240, 225, 20, 20);
    g.drawRect (240, 275, 20, 20);
    g.drawOval (190, 175, 20, 20);
    //The Chimney
    g.setColor (Color.lightGray);
    g.fillRect (260, 150, 20, 40);
    //The Door
    g.setColor (Color.black);
    g.fillRect (185, 310, 30, 40);
    //Santa
    g.drawImage (santa, 460, 300, null);
    //Snowman
    g.drawImage (snowman, 0, 300, null);
     
    } //The end of scene seven
     
    } // paint method
    } // Yearendversion2 class
    Last edited by copeg; January 9th, 2011 at 07:35 PM.


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

    Default Re: PLEASE HELP ME with double buffer

    I recommend reading JFP Announcement (which should have beend read before posting), in particular the code formatting section...I have edited your post to format the lengthy code you posted.

    To answer your question...use Swing components, they are double buffered by default. To manually do it, you must draw everything offscreen, typically to a BufferedImage which the paint/paintComponent method draws. Many examples in a google search which describes how to do this.

  3. The Following User Says Thank You to copeg For This Useful Post:

    DouboC (January 10th, 2011)

  4. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME with double buffer

    thank you

Similar Threads

  1. Thread/Mutex/Shared data buffer
    By m000 in forum Threads
    Replies: 0
    Last Post: January 5th, 2011, 10:18 PM
  2. Unable to redirect all the eclipse console logs to buffer
    By skrishnapradeep in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 23rd, 2010, 11:03 PM
  3. The Bounded Buffer Problem
    By skatescholar in forum Java Theory & Questions
    Replies: 0
    Last Post: April 8th, 2010, 11:22 AM
  4. Double Buffering
    By Ganezan in forum Java Theory & Questions
    Replies: 2
    Last Post: November 20th, 2009, 03:51 AM
  5. string to double
    By wolfgar in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 13th, 2009, 10:47 PM