I am developing a small screen capture application in java.i found a example to select rectangular area from here.(this is that question).i used another jframe and add a toggle button to call the Rectangular selection class.i create a object of Rectangular selection class when the toggle button is selected . Now i have to questions,
I used following code to create the selection class object But if the selection object is exists it create a new object. How to stop this ?
if (sn == null) { if (btn_selection.isSelected()) { sn = new SnipIt(); } else { sn.frame.dispose(); } }
2.to close the selection class it use this code line,
SwingUtilities.getWindowAncestor(sl).dispose();
So i created a method called closeSelection and insert above code line.but when i call this method returns a nullpointexception,
public void closeSelection() {
SelectionPane sl=new SelectionPane();
SwingUtilities.getWindowAncestor(sl).dispose();
}
I know my code has many mistakes. So please show those and give me a solution.Highly appreciate your help ☺