Java Reference
In-Depth Information
it requires, and the time to start up your application also increases with the number
of classes.
Deleting Elements
Let's take another easy element operation next — deleting an element. All that's involved here is calling
remove() for the sketch object. Let's give it a try.
TRY IT OUT: Deleting Elements
You can add the following method to the SketcherView class to delete an element:
private void deleteElement() {
if(highlightElement != null) {
if(!theApp.getModel().remove(highlightElement)) {
JOptionPane.showMessageDialog(
SketcherView.this,"Element not found to
remove.",
"Remove Element from Sketch",
JOptionPane.ERROR_MESSAGE);
}
}
}
Directory "Sketcher 8 with delete element operation"
Now you can change the listener for the Delete menu item in the SketcherView constructor to call this
method:
deleteItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
deleteElement();
}
});
Directory "Sketcher 8 with delete element operation"
Search WWH ::




Custom Search