Why is it drawing twice? WHY!!!?

Hi,
Can someone please explain why the hell this thing is drawing twice?!?!?!?!
I've tried repaint and validate, but to no avail.
I'm just trying to make a simple kids game thingy - draws pictures, you press buttons and right disc moves left or right.
(you'll all be playing it in six months!)
What have I done wrong?
Thanks in advance.
2 java files follow:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ImagePanel1 extends JPanel
// Declare an image array
    Image [] disc1Pics = new Image[36];
    Image [] disc2Pics = new Image[36];
//Declare temporary index list
    static int [] indexArray1 = new int [36];
    static int [] indexArray2 = new int [36];
// Declare x co-ords Array
    int [] xPos1 = {206, 214, 221, 234, 257, 281, 255, 285, 315, 255, 285, 315,
    234, 258, 281, 205, 213, 220, 170, 162, 155, 141, 118, 91, 122, 92, 62,
    122, 92, 62, 141, 118, 94, 169, 161, 154};
    int [] xPos2 = {606, 614, 621, 634, 657, 681, 655, 685, 715, 655, 685, 715,
    634, 658, 681, 605, 613, 620, 570, 562, 555, 541, 518, 494, 522, 492, 462,
    522, 492, 462, 541, 518, 494, 569, 561, 554};
// Declare y co-ords Array
    int [] yPos = {117, 87,  59,  141, 118, 94,  170, 162, 154, 204, 212, 220,
    234, 258, 281, 257, 287, 315, 257, 287, 315, 234, 257, 281, 204, 212, 220,
    171, 163, 155, 141, 118, 94, 117, 87, 59};
    public ImagePanel1()
        this.setBackground(Color.white);
// Create FOR loop to increment the 'pic number' - ie pic0, pic1, pic2
        for(int i1=0; i1<36; i1++)
        disc1Pics[i1] = Toolkit.getDefaultToolkit().getImage("pic"+i1+".gif");
        for (int j1=0; j1<36; j1++)
        indexArray1[j1] = j1;
        for (int lastPlace1 = indexArray1.length-1; lastPlace1 > 0; lastPlace1--)
// Choose a random location from among 0,1,...,lastPlace.
            int randLoc1 = (int)(Math.random()*(lastPlace1+1));
// Swap items in locations randLoc and lastPlace.
            int temp1 = indexArray1[randLoc1];
            indexArray1[randLoc1] = indexArray1[lastPlace1];
            indexArray1[lastPlace1] = temp1;
        for(int i2=0; i2<36; i2++)
        disc2Pics[i2] = Toolkit.getDefaultToolkit().getImage("pic"+i2+".gif");
        for (int j2=0; j2<36; j2++)
        indexArray2[j2] = j2;
        for (int lastPlace2 = indexArray2.length-1; lastPlace2 > 0; lastPlace2--)
// Choose a random location from among 0,1,...,lastPlace.
            int randLoc2 = (int)(Math.random()*(lastPlace2+1));
// Swap items in locations randLoc and lastPlace.
            int temp2 = indexArray2[randLoc2];
            indexArray2[randLoc2] = indexArray2[lastPlace2];
            indexArray2[lastPlace2] = temp2;
    public void paint (Graphics g)
        int x, y;
        double angle1=0;
        double angle1a=0.26166666666666666666666666666667;
        double angle2=0;
        Graphics2D g2d = (Graphics2D)g;
//          LEFT DISK                    LEFT DISK                    LEFT DISK
        do
            x=(int)(java.lang.Math.cos(angle1)*150)+200;
            y=(int)(java.lang.Math.sin(angle1)*150)+200;
//150 = radial length, 200 = co-ord of centre
            g.setColor(Color.black);
            g.drawLine(200,200,x,y);
            angle1 = angle1 + 0.52333333333333333333333333333333;
//0.52333 is 6.28/12 - ie 1/12th of 360 degrees in radians
        while (angle1<6.28);
//Create FOR loop with increment 'k' - equates to pic0, x_pos[0], y_pos[0], pic1, x_pos[1] etc
        //for(int k1=0; k1<36; k1++)
        //g.drawImage(disc1Pics[indexArray1[k1]],xPos1[k1],yPos[k1],this);
//          RIGHT DISK                    RIGHT DISK                    RIGHT DISK
        do
            x=(int)(java.lang.Math.cos(angle2)*150)+600;
            y=(int)(java.lang.Math.sin(angle2)*150)+200;
            g.setColor(Color.black);
            g.drawLine(600,200,x,y);
            angle2 = angle2 + 0.52333333333333333333333333333333;
        while (angle2<6.28);
        for(int k2=0; k2<36; k2++)
        g.drawImage(disc2Pics[indexArray2[k2]],xPos2[k2],yPos[k2],this);
//add in the circles
        g.drawOval(50,50,300,300);
        g.drawOval(450,50,300,300);
        g.setColor(Color.white);
        g.fillOval(163,163,74,74);
        g.fillOval(563,163,74,74);
        g.setColor(Color.black);
        g.drawOval(163,163,74,74);
        g.drawOval(563,163,74,74);
    public void doAntiClockwise()
        int current = 3;
        int [] temp = new int[indexArray2.length];
        for(int x=0; x<indexArray2.length; x++)
            if(current < indexArray2.length)
                temp[current] = indexArray2[x];
                current++;
            else
                current = 0;
        indexArray2 = temp;
        repaint();
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class SafeCracker
    extends JFrame
    private JPanel buttonPanel, buttonPanel2, blank1, blank2, blank3,
        blank4, blank5, blank6;
    private JButton anti, clock, ok, disc1, disc2, disc3;
    ImagePanel1 myPanel = new ImagePanel1();
    public SafeCracker()
        super("SAFE CRACKER");
        JPanel panelForStuff = new JPanel();
        panelForStuff.setLayout(new BorderLayout());
        anti = new JButton("Anti-Clockwise");
        anti.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent ae)
               myPanel.doAntiClockwise();
        clock = new JButton("Clockwise");
        ok = new JButton("OK");
        disc1 = new JButton("Disc 1");
        disc2 = new JButton("Disc 2");
        disc3 = new JButton("Disc 3");
        blank1 = new JPanel();
        blank2 = new JPanel();
        blank3 = new JPanel();
        blank4 = new JPanel();
        blank5 = new JPanel();
        blank6 = new JPanel();
        buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1, 6));
        buttonPanel.add(blank1);
        buttonPanel.add(blank2);
        buttonPanel.add(blank3);
        buttonPanel.add(anti);
        buttonPanel.add(clock);
        buttonPanel.add(ok);
        buttonPanel2 = new JPanel();
        buttonPanel2.setLayout(new GridLayout(1, 6));
        buttonPanel2.add(blank4);
        buttonPanel2.add(blank5);
        buttonPanel2.add(blank6);
        buttonPanel2.add(disc1);
        buttonPanel2.add(disc2);
        buttonPanel2.add(disc3);
        panelForStuff.add(myPanel(), BorderLayout.CENTER);
        panelForStuff.add(buttonPanel, BorderLayout.SOUTH);
        panelForStuff.add(buttonPanel2, BorderLayout.NORTH);
        getContentPane().add(panelForStuff);
        setSize(800, 500);
        setVisible(true);
    public static void main(String args[])
        SafeCracker application = new SafeCracker();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Hi,
but I just ran this with no pictures - and it drew it
properly.
So it's something to do with bringing the pictures in.
Can anybody see where my error is?I haven't looked at your code but the statement above might indicate that you need to wait till the images are loaded. Try to add them to a mediatracker, and see if that solves your problems.
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/MediaTracker.html
/Kaj

Similar Messages

  • Why is Photoshop listed twice under Apps in Creative Cloud?

    Why is Photoshop listed twice under Apps in Creative Cloud?

    Thanks for the reply.
    I opened a chat session with Adobe and they instructed me to simply
    uninstall one of the versions.  For example
    I had Photoshop CC and Photoshop CC(2014).  I uninstalled the Photoshop CC.
    Thanks again,
    *Pete Sadel **
    [email protected] <mailto:[email protected]>
    404-213-8454*

  • My MacAir cannot see the same WiFi router twice, why?

    My MacAir cannot see the same WiFi router twice, why?
    So if it gets connected to a WiFi then gets disconnected for any reason, I cannot reconnect it to the same WiFi again as it cannot see that specific router again.
    Unless, in my case, I turn on my Galaxy note 10.1 Tethering hotspot which it sees ALL the time then the Wifi router shows again so I can reconnect to it.
    This happens at home and at work and at any other place... so No, there is no problem with my router or WiFi connection.
    it is really getting to my nerves.
    the whole purpose of me getting a MacAir is the light weight!
    Now I have to carry my Galaxy Note 10.1 around with me, especially if I am going out, so I can get connected to WiFi!!
    Can anyone help me out!

    Try the following on your MBP, in order, until (hopefully) resolved:
    1a. Delete Preferred Network(s)
    System Preferences > Network > Wi-Fi > Advanced > Wi-Fi tab
    Under "Preferred Networks," delete the network(s) you regularly use from the list.
    1b. Delete AirPort Keychain Entries
    Launch the "Keychain Access" application located in Applications/Utilties.
    In the windows on the left side: Select login for Keychains and "All Items" for Category.
    Click on the "Kind" filter at the top, and look for any "AirPort network password" entries...and delete them.
    1c. Add Preferred Network(s)
    System Preferences > Network > Wi-Fi > Advanced > Wi-Fi tab
    Add the preferred network(s) using the "+" button.
    Restart or log out then back in.
    2. Move System Configuration Files
    (Note: You will have to reestablish your network connections settings.)
    Go to /Library/Preferences
    Move the SystemConfiguration folder to the desktop.
    Restart your Mac. (Note: OS X will rebuild the files that are now sitting on your desktop. If this doesn't resolve the issue, you can move the folder back to it's original location.)

  • Why are birthdays showing twice in ical

    Why do Bithdays appear twice in ICal

    It's bad design. It's not anticipating the result of the way they've implemented iCloud and the crazy, unintuitive way that you set up iCloud in System Preferences: Instead of taking you through a well-explained set of questions, the answers to which give you the results you expect (something like Mail) - Apple designers have gone for a spartan and elegant look, and dire and ambiguous warnings. It's like a bad, little time-wasting puzzle.
    The iCloud Preference Pane should have been thoroughly tested. But the Apple designers knew what they meant. and feeling assured that the keeners in the Mac Communities will eventually figurre out a fix, post it somewhere, and you'll be able Google it and fix it yourself, they just left it like that.
    It's the evolution of Apple culture.
    (and yes I have the same problem, and no, I haven't found the fix yet.)

  • Why was i charged twice for one album

    why was i charged twice for one album

    Did you click 'buy' on it twice or re-download it via the main part of the store instead of the Purchased link/tab ?  You can contact iTunes support (these are user-to-user forums) via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Why am I charged twice for an amount of

    Why was I charged twice for the same amount of #21.09 in my bank statement. This doesn't happen!!!! Please credit back one of the $21.09 charges.
    <Personal Information Edited by Host>

    Contact the bank or iTunes Customer Support.

  • In my library i'll show an album but on my classic it will show the album twice, why? and how can I fix it?

    Not every body is a computer wizz so why make it so difficult to get an answer. I asked how do I fix it when your library on your PC shows an album that same album shows up twice on my classic. Am I the only one getting frustrated from having to jump through hoops. I thought they were going to make this technology easier for the common person, maybe I was wrong. Help.

    See Grouping tracks into albums - still a few hoops but they should get you sorted.
    tt2

  • Why imageComplete is called twice!

    I wrote the following code:
    public class Test{
    public static void main(String[] args){
    //get image
    Image image = Toolkit.getDefaultToolkit().createImage("javalogo.gif");
    ImageConsumerImpl impl = new ImageConsumerImpl();
    //get image producer
    ImageProducer ip = image.getSource();
    // start production
    ip.startProduction (impl);
    //wait here
    class ImageConsumerImpl implements ImageConsumer{
    // other methods are "null"
    public void imageComplete(int status){
    System.out.println("Status:"+status);
    This code did not behavior as I had expected. I thought imageComplete could be called for only once. But it will be called twice, value status is 3(STATICIMAGEDONE) for the first time, but 1 for the second call, which indicates an image error.
    I don't know why, can you give me the answer? javalogo.gif is a static picture.

    pls help me with this, thanks

  • I updated my payment option details for app store and was charged with Rs. 60 twice. why did that happen?

    i changed my app store from canada to india and for that i'd to update my payment option details for app store and was charged with Rs. 60 twice. once the day i added the card details. and then another one 3 days later. why did that happen?
    i read soemwhere that it automatically gets credited back within 3-5 working days.
    waited for more than 7 days but no credit was given back.
    m feeling bad that i got charged without making any purchase.

    Each time that you add or change the card details on your account (and possibly also if you change your name and address, as the card needs to be registered to the same name and address as on your iTunes account) you will be charged a temporary store holding charge to check that the card details are valid and that the card is active, but it should disappear within a few days or so (the amount of time that it takes will vary by card issuer) : store holding charge.
    Give it a few more days, and if it still hasn't disappeared then try contacting iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Urgent, please help. why the ListSelectionListener() called twice?

    I had two JList, and every time, I click value in list1, it will call the ListSelectionListener() twice, and when I click on value in List2, it called the list2 actionListener twice also, I don't know why?
    Please help.
    The part of the code list below:
    jList1 = new JList(words1);
    JScrollPane scrollPane1 = new JScrollPane(jList1); jList1.setBackground(Color.lightGray);
    jList1.setBorder(BorderFactory.createLoweredBevelBorder());
    jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
         jList1_valueChanged(e){
    /* add Column_Name to the jList2*/
    JScrollPane scrollPane2 = new JScrollPane(jList2);
    jList2.setBackground(Color.lightGray);
    jList2.setBorder(BorderFactory.createLoweredBevelBorder());
    jList2.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    jList2_valueChanged(e);
    void jList1_valueChanged(ListSelectionEvent evt)
    void jList2_valueChanged(ListSelectionEvent evt)
    {     }

    You can call ListSelectionEvent.getValueIsChanging() to find out if the selection is in progress or if has been finished. You will get an event both when the user starts the selection (presses the button) and when he/she finishes it (lets go of the betton).
    /Michael

  • Why is adobe running twice?

    as you can see adobe is running twice? why??
    I have windows 7 32bit, latest version of firefox and adobe

    I have the same thing happening. Today my pc became noticeably slow (even logging into windows usually takes about 5 seconds, today it takes almost a min). I have ran virus and malware scans and found nothing. I checked processes to see if there is anything unusual and found nothing except this. And when I re-entered task manager both processes were gone.

  • Why does my drawing tool go see through in onion skin mode?

    I'm using CS6 photoshop as an animation software and I'm new to the process. When I try to draw on the next frame, the paintbrush draws in a see through colour.... as if the drawing tool itself has an onion skin.

    Thanks for the response Rudegar, but I was under the impression that this could work (as explained to me by a Apple sales guy) when I bought the AirPort Express. (and yes I told him I had a Samsung laser printer ML-1915)
    Is the AirPlay printer requirement only an issue when the AirPort Express is in server mode?
    I thought I could just extend my network in Client mode from the AirPort Express.
    So when it talks here about a "wireless print server" it is only referring to either a): ipad to AirPrint printers or b): Windows to any printer?
    http://support.apple.com/kb/HT2272
    Is Apple going to support more printers anytime soon? Because I am happy that my 3 Windows laptops/PC can print wirelessly through Apple gear but kinda confused why my ipad will not play nicely.

  • Why valueChaged( ) method called twice

    Dear All,
    I have made a class MyList by extending JList and implements ListSelectionListener and override valueChanged method. When we clicked on the list item this method called twice. Can you please explain the region?
    I write my code like that:
    Public void valueChanged(ListSelectionEvent lse)
    System.out.println(�Hello�);
    Out put:
    Hello
    Hello
    Thanks
    Bipin Kuma

    It's expected - check the details and you'll see why.
    If, say, the user had selected item 3 and then select item 8 then you might get two events:
    1. first 3, last 3, isAdjusting true
    2. first 8, last 8, isAdjusting false
    It's a poor event protocol if you ask me but there you go.

  • Why I must click twice Back Link in TLN to get back to Area Page

    Hi everyone, i need a little help about TLN. I'm developed webdynpro application and i have integrated it with ess. The problem is arise when I click <b>Back</b> link in top level navigation (TLN) from my iview (custom application). I need to click this link twice to get back to area page (actually just one click to go back to area page). How i handle this problem ? Thank you.
    Regards,
    Satria B

    Hi,
    <b>So that means when i click link to my custom application X, it will create 2 link into history. Why this happen ?</b>
    Exactly, so now you know why you have to click twice, right ? Well, why it has created two links there, that needs to be checked or thought over. Need some time for this.
    <b>I have a button in my iview (custom application), when i click this button, the page will be back to area page but Detailed Navigation will be display (i have setting this to be hide), why this happen ?</b>
    Sorry, didn't get your question. Do you mean to say that you want to hide the detailed navigation on the Area page. Is this Area Page a custom application ? What is the code written on the click of button ? Is the Area Page an iview within a page and then attached to role or workset or just an iview attached to role or workset ?
    Have you changed the following property of iview or page (for Area Page) "Initial State of Navigation Panel" to closed ?
    Hope this helps.
    Cheers,
    Sunil
    PS: Reward points for helpful answers.

  • Why cant I draw an ellipse?

    Hi,
    I'm using MemoryImageSource source to animate a background, but I want to draw some shapes on top. Below is my update() method, and I try to draw an ellipse, and it simply doesn't show up. Why is this? How can I draw on top of this screen?
    public void update(Graphics g) {
    source.newPixels(); //Source is of type MemoryImageSource
    g.drawImage(img, 0, 0, width, height, null); // img was constructed from MemoryImageSource
    g.setColor(Color.GREEN);
    g.fillOval(20, 20, 10,10); //Not displayed?
    Cheers,
    Lloyd

    Sorry, I could draw an ellipse it just wasn't visible on screen due to the co-ordinates!

Maybe you are looking for