having processing wait for mouse click
843805May 12 2006 — edited May 12 2006Okay, theres the rest of my Duke Dollars riding on this if it can be solved within the next two days. I have a graphic component (a cgm actually) inside a layered pane (in a tabbedpane, in a splitpane) that contains all the mouse functions. Among them is the mouseClicked(MouseEvent me) method. From outside the component, I can access the location of the position the mouse was clicked quite easily. The problem is - I need to find a way in a method I can call that will wait for a mouse click before processing the location coordinates. What I'd like to do is to display a label on the layered pane that tells me to click on some location then wait til the mouse is clicked somewhere so that I can locate a new component at that location.
public void addTextBox()
{
ViewBox newView = new ViewBox();
int x = (int)newView,getPoint.getX(); //this is where i can get the last mouseClicked coordinates
int x = (int)newView,getPoint.getX();
JLabel instructLabel = new JLabel("Select a location by clicking mouse");
instructLabel.setBounds( x, y, 300, 20);
layeredPane.add(instructLabel, JLayeredPane.MODAL_LAYER, 0);
/****This is where I need to wait for the mouse click****/
stepTextBoxr] = new JTextArea();
int tabSize = 1;
stepTextBox.setTabSize(tabSize);
boxSizeW= 300
boxSizeH = 200
n=mgNumber;
stepTextBox.setBounds( x, y, boxSizeW, boxSizeH);
layeredPane.add(stepTextBox, JLayeredPane.MODAL_LAYER, 0);
}
Class ViewBox contains the mouse functions. I created an instance of this class (newView) which has access to the mouse functions. I believe a thread may be the answer, but i don't know how to create and work it. If I use a while statement like below:
while (x==0 && y==0) {
x = (int)newView.getPoint.getX();
y = (int)newView.getPoint.getY();
}
everything just stops, including the menu I used to select and initiate the addStep() method. I need help fast as I have to turn in the project (of which this is part) by Monday evening May 15!