When my thread starts running, at that time keylistener is not working.

when my thread starts running, at that time keylistener is not working.
plz reply me.

//FrameShow.java
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.logging.Level;
import java.awt.event.*;
import java.util.*;
public class FrameShow extends JFrame implements ActionListener,KeyListener
     boolean paused=false;
     JButton stop;
     JButton start;
     JButton exit;
     public IncludePanel CenterPanel;
     public FrameShow()
CenterPanel= new IncludePanel();
          Functions fn=new Functions();
          int height=fn.getScreenHeight();
          int width=fn.getScreenWidth();
          setTitle("Game Assignment--Santanu Tripathy--MCA");
          setSize(width,height);
          setResizable(false);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          show();
          initComponents();
          DefaultColorSet();
          this.addKeyListener(this);
     this.setFocusable(true);
     public void initComponents()
          Container contentpane=getContentPane();
          //Creating Panel For Different Side
          JPanel EastPanel= new JPanel();
          JPanel WestPanel= new JPanel();
          JPanel NorthPanel= new JPanel();
          JPanel SouthPanel= new JPanel();
          //CenterPanel = new IncludePanel();
          //IncludePanel CenterPanel= new IncludePanel();
          EastPanel.setPreferredSize(new Dimension(100,10));
          WestPanel.setPreferredSize(new Dimension(100,10));
          NorthPanel.setPreferredSize(new Dimension(10,100));
          SouthPanel.setPreferredSize(new Dimension(10,100));
          //CenterPanel.setPreferredSize(new Dimension(200,200));
          //Adding Color to the Panels
          NorthPanel.setBackground(Color.green);
          SouthPanel.setBackground(Color.orange);
          CenterPanel.setBackground(Color.black);
          //Creating Border For Different Side
          Border EastBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
          Border WestBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
          Border NorthBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
          Border SouthBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
          Border CenterBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
          //Creating Components For East Panel
          JLabel left= new JLabel("LEFT");
          JLabel right= new JLabel("RIGHT");
          JLabel rotate= new JLabel("ROTATE");
          left.setForeground(Color.blue);
          right.setForeground(Color.blue);
          rotate.setForeground(Color.blue);
          //Creating Components For West Panel
          ButtonGroup group = new ButtonGroup();
          JRadioButton rb1 = new JRadioButton("Pink",false);
          JRadioButton rb2 = new JRadioButton("Cyan",false);
          JRadioButton rb3 = new JRadioButton("Orange",false);
          JRadioButton _default = new JRadioButton("Black",true);
          rb1.setForeground(Color.pink);
          rb2.setForeground(Color.cyan);
          rb3.setForeground(Color.orange);
          _default.setForeground(Color.black);
          //Creating Components For North Panel
          JLabel name= new JLabel("Santanu Tripathy");
          name.setForeground(Color.blue);
          name.setFont(new Font("Serif",Font.BOLD,30));
          //Creating Components For South Panel
          start = new JButton();
          stop = new JButton();
          exit = new JButton();
          start.setToolTipText("Click this button to start the game");
          start.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
          start.setText("START");
          start.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
          start.setMaximumSize(new java.awt.Dimension(90, 35));
          start.setMinimumSize(new java.awt.Dimension(90, 35));
          start.setPreferredSize(new java.awt.Dimension(95, 35));
          if(paused)
               stop.setToolTipText("Click this button to pause the game");
          else
               stop.setToolTipText("Click this button to resume the game");
          stop.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
          stop.setText("PAUSE");
          stop.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
          stop.setMaximumSize(new java.awt.Dimension(90, 35));
          stop.setMinimumSize(new java.awt.Dimension(90, 35));
          stop.setPreferredSize(new java.awt.Dimension(95, 35));
          exit.setToolTipText("Click this button to exit from the game");
          exit.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
          exit.setText("EXIT");
          exit.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
          exit.setMaximumSize(new java.awt.Dimension(90, 35));
          exit.setMinimumSize(new java.awt.Dimension(90, 35));
          exit.setPreferredSize(new java.awt.Dimension(95, 35));
          //Adding some extra things to the Panels
          group.add(rb1);
          group.add(rb2);
          group.add(rb3);
          group.add(_default);
          //Adding Component into the Panels
          EastPanel.add(left);
          EastPanel.add(right);
          EastPanel.add(rotate);
          WestPanel.add(rb1);
          WestPanel.add(rb2);
          WestPanel.add(rb3);
          WestPanel.add(_default);
          NorthPanel.add(name);
          SouthPanel.add(start);
          SouthPanel.add(stop);
          SouthPanel.add(exit);
          //Adding Border Into the Panels
          EastPanel.setBorder(EastBr);
          WestPanel.setBorder(WestBr);
          NorthPanel.setBorder(NorthBr);
          SouthPanel.setBorder(SouthBr);
          CenterPanel.setBorder(CenterBr);
          //Adding Panels into the Container
          EastPanel.setLayout(new GridLayout(0,1));
          contentpane.add(EastPanel,BorderLayout.EAST);
          WestPanel.setLayout(new GridLayout(0,1));
          contentpane.add(WestPanel,BorderLayout.WEST);
          contentpane.add(NorthPanel,BorderLayout.NORTH);
          contentpane.add(SouthPanel,BorderLayout.SOUTH);
          contentpane.add(CenterPanel,BorderLayout.CENTER);
          //Adding Action Listeners
          rb1.addActionListener(this);
          rb2.addActionListener(this);
          rb3.addActionListener(this);
          _default.addActionListener(this);
          exit.addActionListener(this);
          start.addActionListener(this);
try
          start.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
                    start.setEnabled(false);
CenterPanel.drawCircle();
catch(Exception e)
{System.out.println("Exception is attached with sart button exp = "+e);}
try
          stop.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
                    paused=!paused;
                    if(paused)
                         start.setToolTipText("Click this button to resume the game");
                         stop.setText("RESUME");
                    else
                         start.setToolTipText("Click this button to pause the game");
                         stop.setText("PAUSE");
CenterPanel.pause();
catch(Exception e)
{System.out.println("Exception is attached with sart button exp = "+e);}
     public void DefaultColorSet()
          getContentPane().setBackground(Color.white);
     public void actionPerformed(ActionEvent AE)
          String str=(String)AE.getActionCommand();
          if(str.equalsIgnoreCase("pink"))
               CenterPanel.setBackground(Color.pink);
          if(str.equalsIgnoreCase("cyan"))
               CenterPanel.setBackground(Color.cyan);
          if(str.equalsIgnoreCase("orange"))
               CenterPanel.setBackground(Color.orange);
          if(str.equalsIgnoreCase("black"))
               CenterPanel.setBackground(Color.black);
          if(str.equalsIgnoreCase("exit"))
               System.exit(0);
     public void keyTyped(KeyEvent kevt)
//repaint();
public void keyPressed(KeyEvent e)
          System.out.println("here key pressed");
          //CenterPanel.dec();
     public void keyReleased(KeyEvent ke) {}
}//End of FrameShow.ja
//IncludePanel.java
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.Graphics.*;
import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.util.*;
import java.util.logging.Level;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class IncludePanel extends JPanel implements Runnable
int x=0,y=0;
int color_1=0;
int color_2=1;
int start=0;
Thread th;
Image red,blue,green,yellow;
java.util.List image;
static boolean PAUSE=false;
     public IncludePanel()
     red= Toolkit.getDefaultToolkit().getImage("red.png");
     blue= Toolkit.getDefaultToolkit().getImage("blue.png");
     green= Toolkit.getDefaultToolkit().getImage("green.png");
     yellow= Toolkit.getDefaultToolkit().getImage("yellow.png");
public void paintComponent(Graphics g)
          super.paintComponent(g);
          draw(g);
public void dec()
     System.out.println("in dec method");
     x=x+30;
public void draw(Graphics g)
          g.setColor(Color.red);
          int xx=0,yy=0;
          for (int row=0;row<=12;row++)
               g.drawLine(xx,yy,180,yy);
               yy=yy+30;
          xx=0;
          yy=0;
          for (int col=0;col<=6;col++)
               g.drawLine(xx,yy,xx,360);
               xx=xx+30;
          if(color_1==0)
               g.drawImage(red, x, y, this);
          else if(color_1==1)
               g.drawImage(blue,x, y, this);
          else if(color_1==2)
               g.drawImage(green,x,y, this);
          else if(color_1==3)
               g.drawImage(yellow,x,y, this);
x=x+30;
          if(color_2==0)
               g.drawImage(red, x, y, this);
          else if(color_2==1)
               g.drawImage(blue,x,y, this);
          else if(color_2==2)
               g.drawImage(green,x,y, this);
          else if(color_2==3)
               g.drawImage(yellow,x,y, this);
x=0;
public void drawCircle( )
     th=new Thread(this);
     th.start();
     public void pause()
          if(PAUSE)
               th.resume();
               PAUSE=false;
               return;
          if(!PAUSE)
          PAUSE=true;
     public synchronized void run()
          Random rand = new Random();
          Thread ani=Thread.currentThread();
          while(ani==th)
               if(PAUSE)
                    th.suspend();
               if(y==330)
                    color_1 = Math.abs(rand.nextInt())%4;
                    color_2 = Math.abs(rand.nextInt())%4;
                    if(color_1==color_2)
                         color_2=(color_2+1)%4;
                    y=0;
               else
                    y=y+30;
               repaint();
               try
                    Thread.sleep(700);
               catch(Exception e)
     }//End of run
i sent two entire program

Similar Messages

  • When I start mozilla firefox web browser, sometimes I see a message saying that "a Mozilla Firefox is already running, please close it or restart your program", while I don't have one running at that time. What is the problem?

    When I start mozilla firefox web browser, sometimes I see a message saying that "a Mozilla Firefox is already running, please close it or restart your system". As a matter of fact, there is no firefox browser running at that time. Since I cannot do anything about it, I have to restart my computer before I can use the web browser, which bothers me dearly. What is the problem?

    Plug-in and tasks started by Firefox may continue after attempting to close Firefox. The "X" in the upper right-hand corner closes the Window (same as Ctrl+Shift+W) but even if it is the last Firefox window, it does not necessarily close Firefox .
    '''The only proper way to exit Firefox is to use Exit through the File menu''', not the "X" in the upper right corner of last Firefox window.
    ''Menus hidden: then use Alt+F then X.''
    '''Firefox hangs''' | Troubleshooting | Firefox Support ''(some extensions cause a problem)''
    * http://support.mozilla.com/kb/Firefox%20hangs#w_hang-at-exit
    Use the '''Windows Task Manger''' to remove all running firefox.exe in the "Processes"
    tab of the Windows Task Manager, then restart Firefox.
    "'''Restartless Restart'''" extension for Firefox 4.0 only (2 KB download )
    * https://addons.mozilla.org/firefox/addon/249342/
    use to close and restart Firefox after enabling or disabling an extension, switching
    to a new theme, or modifying configuration files, then you don't have to worry
    about delay or have to look in the Task Manager to see if Firefox is closed yet.
    Uses keyboard shortcut "'''Ctrl+Alt+R'''" or a file menu option.
    '''Windows 7''' users can use '''Ctrl+Shift+Esc''' to get to the Windows Task Manager quicker than starting with Ctrl+Alt+Del.

  • I just got the iPhone 5 and noticed that the message alerts will only alert once . I have it set up as 3 times and its not working . Please help. I'm running 6.0.2 and I really starting to get ****** off with apple products

    I just got the iPhone 5 and noticed that the message alerts will only alert once . I have it set up as 3 times and its not working . Please help. I'm running 6.0.2 and I really starting to get ****** off with apple products

    Instead of getting annoyed, read the User's Guide and try basic troubleshooting.

  • I get an error that says that LR5 encounterd a preview cach error when trying to start LR5 and that it will try to fix it the next time it starts. What can I do to fix this error?

    I get an error that says that LR5 encountered a preview cache error when trying to start LR5 and that it will try to fix it the next time it starts. What can I do to fix this error?

    Go to the folder with you Lightroom Catalog (usually in Pictures) and delete the folder ending in .lrpreviews
    This contains the previews for the files Lightroom has linked to. They will need to be rebuilt which can be done while working or selecting an amount you want to rebuild and accessing the rebuild command in the Library Dropdown menu...

  • Hello guys my problem is that when I go to run the setup of cloud crative not let me install and I get could not open the installer

    hello guys my problem is that when i go to run the setup of cloud crative not let me install and i get could not open the installer

    Please read https://forums.adobe.com/thread/1499014
    -try some steps such as changing browsers and turning off your firewall
    -also flush your browser cache so you are starting with a fresh browser
    http://myleniumerrors.com/installation-and-licensing-problems/creative-cloud-error-codes-w ip/
    http://helpx.adobe.com/creative-cloud/kb/failed-install-creative-cloud-desktop.html
    or
    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • Updated to Oct 2014 version of photoshop CC. since that time cannot save ANY work.  I can work on files but when I hit 'save as" every time it says "photoshop has quit working and needs to close."

    Updated to Oct 2014 version of photoshop CC. since that time cannot save ANY work.  I can work on files but when I hit 'save as" every time it says "photoshop has quit working and needs to close." Need solution now.

    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • How to deal with the mouse events when the thread is running

    Hi everybody,
    I have a problem with my program.
    Now I want to present a picture for some time in the Canvas,then automatically clear the screen, but when the user press the mousebutton or keybutton, I want to stop the thread and clear the screen.
    How can I receive the mouse event when the thread is running?
    Thanks,

    I use my code in a GUI applet.
    I try to use the code tag, it's the first time.
                   Image im=sd.getStimulus(obj);
                   if(pos==null){
                        g.drawImage(im, (w-im.getWidth(null))/2,(h-im.getHeight(null))/2,null);
                   }else{
                        g.drawImage(im, pos.x,pos.y,pos.w,pos.h,null);
                   try{
                        sleep(showtime);
    //                    Thread.sleep(showtime);
                   }catch(InterruptedException e){}
                   if(pos==null){
                        g.clearRect((w-im.getWidth(null))/2,(h-im.getHeight(null))/2,im.getWidth(null),im.getHeight(null));
                   }else{
                        g.clearRect(pos.x,pos.y, pos.w, pos.h);
                   }

  • HT5429 i m using iphone 4s . when i try to set direction that time i get one error like the map server is not available . will you help me ?

    i m using iphone 4s . when i try to set direction that time i get one error like the map server is not available . will you help me ?
    how to help this problem..?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • TS3367 when open the  face time microfiche is not working but if you use headset that time working

    when open the  face time microfiche is not working but if you use headset that time working

    Read through this... http://support.apple.com/kb/HT4319

  • HT4623 i am updating to ios 6.1 but i dont want immediatly i have shut down my iphone by holding sleep wake button and home button and cracks from that time and its not restarting

    i am updating to ios 6.1 but i dont want immediatly i have shut down my iphone by holding sleep wake button and home button and cracks from that time and its not restarting

    HarryAustralia wrote:
    I recently updated my ipad wifi only to the new ios 6.1.2 and initially I had the auto cover lock option which can be seen in the Generals tab, but then it stoped working!! Before the update, the auto cover lock worked fine. So after trying all the options, I then did a complete reset on the ipad and now its gone all together from the General tab!! I can no longer see the "auto cover lock" option.
    The iPad cover lock is for when you use a cover with magnets in it to lock and unlock the iPad when you close the cover or open it. Try running a refrigerator magnet along the sides of the iPad and see if that trips the iPad Cover Lock back into the settings.
    That is not the same thing as the iPad Auto Lock setting which allows you to set an allotted time before the iPad goes to sleep.
    You can try resetting all settings to see if the Auto Lock feature retinrs to the iPad.
    Settings>General>Reset>Reset All Settings. You will have to enter all of your device settings again.... All of the settings in the settings app will have to be re-entered. This can be a little time consuming re-entering all of the device settings again.

  • I bought the Keynote app for my MacBook, but when I open the application and try to install it, I get an error message saying that the application will not work with my MacBook. What gives? And, can I please request a refund? ($19.99 = a week's groceries)

    I bought the Keynote app for my MacBook, but when I open the application and try to install it, I get an error message saying that the application will not work with my MacBook. What gives? And, can I please request a refund? ($19.99 = a week's groceries).
    Thank you for your help! - I did try looking for all available specs about Keynote on the Apple iTunes website, and found nothing that could help me. HELP!

    1
    Close all iWork applications
    2
    Uninstall Keynote; this must be done with an application remover tool to delete the installation properly. Appcleaner is known to work correctly for this purpose, it is free and can be downloaded from here: Appcleaner Download
    3
    empty the trash
    4
    shutdown the Mac and restart. After the start up chime, hold down the shift key until the apple logo appears
    let the Mac complete the start up procedure completely, it will take longer than usual as the hard drive is being repaired
    5
    Reinstall Keynote by logging into the Mac App Store using download / install

  • I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first p

    I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first place can someone please explain and tell me how to make it work again

    Sorry first time asking question didn't mean to write same thing twice well copy paste

  • I am a windows user that has converted to Mac and loving it but when I updated to Lion my wireless internet dongle would not work anymore and the Macbook Pro does not recognise the device at all so I am unable to reinstall it again. Any ideas

    I am a windows user that has converted to Mac and loving it but when I updated to Lion my wireless internet dongle would not work anymore and the Macbook Pro does not recognise the device at all so I am unable to reinstall it again. Any ideas would be greatly appreciated.

    Go to Finder > Preferences then select the General tab
    Make sure External disks is selected.

  • My time machine is not working and the disk utilities cant repair it and is asking me to format the drive again. How can I backup the files before formatting the drive so that I don't lose my files?

    Hi
    My time machine hard drive has stopped working after the latest update and the Disk Utilities says,:
    Error: Disk Utility can’t repair this disk. Back up as many of your files as possible, reformat the disk, and restore your backed-up files."
    How can I back up my files before reformatting when I can't even open the drive's folder?
    Thanks for the help.

    I think my time machine is not working correctly and I dont know how to get it back... I really need to get back my photos!!!!!
    Exactly this was the way I USED to make restores of files and photos..
    but know I CANT!!!!
    When I am inside iPhoto y click on the Time Machine icon at the Dock and it goes to this...
    at my right side there are the backups but when i click them nothing happens they are like NOT CLICKABLE...
    PLEASEE!!! Help me!!

  • When I connect my ipod touch tomy computer it says that the device will not work because the Apple mobile device hasnt been activated?

    Why does a meesage pop up when I connect my iPod touch saying that the device will not work because the Apple mobile device hasn't been activated?          

    Refer to this article to restart AMDS:
    How to restart the Apple Mobile Device Service (AMDS) on Windows
    http://support.apple.com/kb/TS1567

Maybe you are looking for

  • Using a Mac Mini with my Mac Pro

    I have a Mac Pro and a Mac Mini, but only one monitor and one keyboard. Can I hook up the Mac Mini so it will appear on the monitor (like another hard drive) when I am using the Mac Pro? I would like to use the Mac Mini strictly as a storage device a

  • WI-FI and Windows XP

    Just a revelation for those who are having problems connecting to their network. Simple, but it was a headache for me for about 4 hours today. I couldn't connect my iPhone to my home network, but the iPhone saw a network with no name (it was blank in

  • Qosmio G30: SPDIF option unavailable in Audio Properties

    Qosmio G30, SigmaTel HD Audio Codec, running XP 2 I'm attempting to route the audio signal thru the built in coaxial out to amp. No signal. When I go to Sounds and Audio Devices>Advanced>Volume control panel /Properties there is no slider /column for

  • Bootcamp 'Glowing' windows logo freeze after gfx driver install

    Bootcamp 'Glowing' windows logo freeze after gfx driver install Last week suddenly, after having changed or installed nothing, trying to boot into windows resulted in a frozen glowy window logo 'Starting Windows', which resulted in having to format t

  • Change the deadline using FM SWW_WI_DEADLINES_CHANGE

    hi, i am facing problem while changing the deadline for my workitem using FM SWW_WI_DEADLINES_CHANGE. my coding is as follows.. w_deadline-wi_dattype = 'DS'.    w_deadline-wi_date = l_new_date.   w_deadline-wi_time = '000001'.    APPEND w_deadline TO