When a single program stops working:
In GNOME, when a program in a window stops responding, you can usually stop it by clicking the X-shaped close button at the top right of the window, or at the top left on newer Ubuntu versions with Unity. That will generally result in a dialog box saying that the program is not responding (but you already knew that) and presenting you with the option to kill the program or to continue to wait for it to respond.
Sometimes this does not work as expected. If you can't close a window by normal means, you can open a terminal (or use Alt + F2) and run xkill. Your mouse cursor will then turn into an X. Hover over the offending window and left-click to kill that process. Right clicking will cancel and return your mouse to normal.
When commands run from an xterm or console stop responding, they can sometimes be halted with Ctrl + C. Ctrl + Z will sometimes work when that fails. If neither of these works, open another terminal and run ps ax |grep foo where foo is the name of the unresponsive program. This should return a line of output that looks something like this:
$ ps ax |grep firefox
2222 ? S 0:00 /bin/sh /usr/lib/firefox-3.6.9/firefox
2227 ? S 0:00 /bin/sh /usr/lib/firefox-3.6.9/run-mozilla.sh /usr/lib/firefox/3.6.9/firefox-bin
2231 ? Sl 514:36 /usr/lib/firefox-3.6.9/firefox-bin
24970 ? Sl 173:30 /usr/lib/firefox-3.6.9/plugin-container /home/andyman/.mozilla/plugins/libflashplayer.so 2231 plugin true
30290 pts/2 S+ 0:00 grep --color=auto firefox
The first field of each line of output is a number which represents the Process ID of the program matched by grep (you can safely ignore the last one, which represents grep itself). To halt the offending process, do:
kill -9 bar where bar is the Process ID of the program. You might have to use your judgment as to which of the matches needs to be killed, or you could use top instead.
If you are running GNOME, of course, you don't have to fool with this crazy command-line stuff to get the job done- just go to System → Administration → System Monitor. Navigate to the Processes tab. Choose the process you want to halt (Hm, could it be the one using 90% CPU?) and right-click it. Since the process is already stopped, (that's the problem, right?) choose End Process or Kill Process from the resulting menu.
I'm not sure what the difference is between the two. In my experience they both get the job done. Perhaps someone can chime in with that information?
When the mouse stops working:
If the keyboard still works, hit Alt + F2 and run gnome-terminal. From there you can troubleshoot things. I'm not going to get into mouse troubleshooting here, as I haven't researched it. If you just want to try restarting the GUI, run sudo service gdm restart. This should bring down the GUI, which will then attempt to respawn, bringing you back to the login screen.
When everything, keys and mouse and all, stop working:
First try the Magic SysReq method outlined in Phoenix' answer. If that doesn't work, hit the Reset button on the computer case. If even that doesn't work, you'll just have to power-cycle the machine. May you never reach this point.