dcsimg
Restricting multiple clicks on a component
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rajesh_Mohapatra
Posted On:   Saturday, July 27, 2002 12:10 AM

I have defined two classes TestA and TestB as follows (excluding GUI details): TestA.java: public class TestA extends JFrame { JTextArea ta; public TestA() { ta = new JTextArea(); ta.setEditable(false); ta.addMouseListener(new MyMouseAdapter()); } } class MyMouseAdapter extends MouseAdapter { public void mouseClicked(MouseEvent me) { if(me.getSource() == ta) { TestB b = new TestB(); } } } TestB.java: public class TestB extends JFrame implements ActionListener { JButton btn; public TestB() { btn = new    More>>

I have defined two classes TestA and TestB as follows (excluding GUI details):

TestA.java:
public class TestA extends JFrame
{
JTextArea ta;

public TestA()
{
ta = new JTextArea();
ta.setEditable(false);
ta.addMouseListener(new MyMouseAdapter());
}
}

class MyMouseAdapter extends MouseAdapter
{
public void mouseClicked(MouseEvent me)
{
if(me.getSource() == ta)
{
TestB b = new TestB();
}
}

}



TestB.java:

public class TestB extends JFrame implements ActionListener
{
JButton btn;

public TestB()
{
btn = new JButton("Ok");
btn.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == btn)
{
this.dispose();
}
}
}

In the above case, I want to avoid instanciating multiple instances of TestB. That is, once one TestB instance is created I should not be able to create one more TestB instance until I close the first instance (dispose the first instance). At the same time there must not be two
separate instances of TestB.

How to proceed about this?

If anybody has any idea about this please help me out.

Thanx in advance

Rajesh

   <<Less

Re: Restricting multiple clicks on a component

Posted By:   S_A  
Posted On:   Saturday, July 27, 2002 02:02 AM

Try declaring a public static variable(preferably boolean), and initialise it as 'false'. Before opening the inner JFrame just check for the value for 'false', and if yes, set the variable to 'true' and the window opens. Also reset the variable to 'false' when you dispose() the window through a button click as well as close the window by clicking 'X' option appears in the title bar. This can be done by adding a window listener for the inner frame and overriding the windowClosing() method. Hope this will solve your issue.
About | Sitemap | Contact