473,473 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

waiting for a mouse click

6 New Member
Really need help with this one. I'm writing a program to simulate a Risk game and I need to write a method to make two countries neighbors, which would be done by adding each the neighbor country to each country's neighbor's array. To do this, I will need to click on the country, click on the map and then click on the other country. My method gets the country's name but how do I tell it to wait for a mouse click before trying to get the second country's name???? I've tried everything but to no avail. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. public void addNeighbor(Country country) {
  2.  
  3.         boolean exists, click;
  4.  
  5.         Country tempCountry;
  6.         tempCountry = searchCountry(red, green, blue);
  7.  
  8.         if (country == tempCountry){
  9.             JOptionPane.showMessageDialog(null, "Error: Territories are the same. Please try again");
  10.         }
  11.         else {
  12.             exists = country.borderExists(tempCountry);
  13.             if (exists){
  14.                 JOptionPane.showMessageDialog(null, "Error: Territories are already borders.");
  15.             }
  16.             else {
  17.                 country.addBorderArray(tempCountry);
  18.                 tempCountry.addBorderArray(country);
  19.                 JOptionPane.showMessageDialog(null, "Border successfull added.");
  20.             }
  21.  
  22.         }
  23.  
  24.  
  25.     }
Oct 14 '07 #1
2 3463
Laharl
849 Recognized Expert Contributor
I believe you need a MouseListener, though I've never actually used one, I've seen them used in simulations of games like Concentration.
Oct 15 '07 #2
eeriehunk
55 New Member
Really need help with this one. I'm writing a program to simulate a Risk game and I need to write a method to make two countries neighbors, which would be done by adding each the neighbor country to each country's neighbor's array. To do this, I will need to click on the country, click on the map and then click on the other country. My method gets the country's name but how do I tell it to wait for a mouse click before trying to get the second country's name???? I've tried everything but to no avail. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. public void addNeighbor(Country country) {
  2.  
  3.         boolean exists, click;
  4.  
  5.         Country tempCountry;
  6.         tempCountry = searchCountry(red, green, blue);
  7.  
  8.         if (country == tempCountry){
  9.             JOptionPane.showMessageDialog(null, "Error: Territories are the same. Please try again");
  10.         }
  11.         else {
  12.             exists = country.borderExists(tempCountry);
  13.             if (exists){
  14.                 JOptionPane.showMessageDialog(null, "Error: Territories are already borders.");
  15.             }
  16.             else {
  17.                 country.addBorderArray(tempCountry);
  18.                 tempCountry.addBorderArray(country);
  19.                 JOptionPane.showMessageDialog(null, "Border successfull added.");
  20.             }
  21.  
  22.         }
  23.  
  24.  
  25.     }
To use an action listener you have to instantiate a button class (not just a button, you can use many others like check box or radio button or more). Check this sample code of a JButton class click me
Oct 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: punkin | last post by:
I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. My code only works for IEs but not any Netscape or Gecko-based browsers. The...
3
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The...
4
by: Andreas Müller | last post by:
Hi all, I need to wait for the user to click the mouse: // some code before WaitForMouseClick();// Wait until the user clicks the mouse // go on doing something Under Win32 using C++, you...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
2
by: scott_gui | last post by:
I am creating a Windows application: The mouse event <Double-Button-1> has a conflict when the <Button-1> event also has a binding. Double clicks will first perform the single click action. This...
19
by: wmanzo | last post by:
I have a really professional conspiracy movie site and I use tons of layers and an external scroll bar assembly. I would like to put the various sections into MS Iframes and in order to clean up...
5
by: Adeel | last post by:
Hi group! I'm trying to learn C# on my own... I'd appreciate it very much if someone can help me out here. I have a basic form without any controls on it... I want to catch mouse clicks (both...
10
by: Sebouh | last post by:
Hi guys. I don't know how to implement this so i was hoping if any of you can help me. I have a code like this one: public static void main (String args) { //create frame and button ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.