Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:19+00:00 2026-06-15T06:10:19+00:00

public void actionPerformed(ActionEvent e) { String sp1=Player 1’s turn. ; String sp2=Player 2’s turn.

  • 0
public void actionPerformed(ActionEvent e) {
        String sp1="Player 1's turn. ";
        String sp2="Player 2's turn. ";
          System.out.println("Mouse entered for rating " + index);  //helps me track the cards
           ori=new ImageIcon(getClass().getResource(index+1+".png")); //set the image to the card

        ori.setDescription("ori");  //It's weird that I cannot directly flip the card, so I used this method to flip the cards.
        tail.setDescription("tail");//http://stackoverflow.com/questions/13557561/the-method-about-imageicons-does-not-work


        if (((ImageIcon) bt[index].getIcon()).getDescription()=="ori")
            bt[index].setIcon(tail);
         else
            bt[index].setIcon(ori);

        count++;

       System.out.printf("Action Performed %d times \n",count);
         if(count==1){  //if the card is clicked for once, the card should not flip and the index is stored in record.
           record=index;
           countS++;

       }
       String turnS=Integer.toString(countS);//parse the int and printout the turn 
     //  text3.setText(sp1+"This is turn "+turnS);
       if(count==2){
           int match1=record/4;   //Since every four cards have the same rank, I used this to get the rank very easily
           int match2=index/4;
          if(match1==match2&&record!=index){  //compare the two cards clicked
              p1++;
              score1=Integer.toString(p1);   
              text1.setText("Player 1: "+score1);  //display the score
              text3.setText(sp2+"This is turn "+turnS);
              bt[index].setEnabled(false);//remove the cards that match
              bt[record].setEnabled(false);
          }
          if(record==index){
              text3.setText(sp2+"This is turn "+turnS);//designed for the situation that the user clicks the same card
          }
          if(match1!=match2){//designed for the situation that the two cards do not match
           //time.schedule(taskFlip1,500);//delay the flip so that the user can see the cards
           //time.schedule(taskFlip2,500);


              try{   **//This part is problematic!**

                  Thread.currentThread().sleep(4000);
                  flip(index);
                  flip(record);


                }
                catch(Exception ie){

                }
              }
          text3.setText(sp2+"This is turn "+turnS);


       }

When I click on the button, the button is supposed to change the ImageIcon. It works fine without the sleep. But after I add sleep, when I click on the button, the program pauses without changing the ImageIcon! Can you tell me why? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:10:20+00:00Added an answer on June 15, 2026 at 6:10 am

    The actionPerformed() method runs in the event dispatching thread. So does the repaint system. If you sleep, you are deferring painting, and everything else. You should never sleep in this thread. If you want a deferred paint, use SwingWorker or javax.swing.Timer to start a deferred task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class saveButtonListener implements ActionListener{ public void actionPerformed(ActionEvent ev){ JFileChooser chooser= new JFileChooser(); String
public void actionPerformed(ActionEvent e) { String sout; try { if(e.getSource()==compile) { sout=input.getText(); Runtime rt=Runtime.getRuntime();
public void printList( ){ Node<E> p ; System.out.printf( [ ) ; for ( p=head.next
public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
public class Start { public static void main(String[] args) { JFrame j = new
public class XXX { public static void main(String args[]) { JComponent comp = new
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
public void swap(Point var1, Point var2) { var1.x = 100; var1.y = 100; Point
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Init(); backthread tr=new backthread(); tr.execute(0,0,0); } backthread
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); TextView lattv=(TextView)findViewById(R.id.lat); TextView lngtv=(TextView)findViewById(R.id.lng); JSONParstring jParser =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.