DOC PREVIEW
DePaul IS 313 - GUI III

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

GUI IIIOutlineEvent HandlingEvent handlingMenu item exampleButton exampleGetting a value backMouseListener exampleAnonymous classAnonymous class diagramMouse example againAccess to External ValuesAccess to ValuesMouseListener interfaceEvent handling strategiesRecommendationEvent handling threadExampleGUI IIIIS 3135.6.03Outline Quiz #2 Homework #2 questions? Event handlingEvent HandlingEvent handlingMenu item exampleJMenu fileMenu = new JMenu ("File");JMenuItem exitItem = new JMenuItem ("Exit");exitItem.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent e){System.exit(0);}});Button examplecancelButton.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){ListDialog.dialog.setVisible(false);}});Getting a value backbutton.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String selectedName = ListDialog.showDialog(null, name.getText());name.setText(selectedName);}});MouseListener exampleblankArea.addMouseListener(new MouseAdapter (){public void mouseClicked(MouseEvent e) {MouseEventDemo2.this.saySomething("Mouse clicked (# of clicks: " +e.getClickCount() + ")", e);}});Anonymous classnew ActionListener (){ public void actionPerformed (ActionEvent e){System.exit(0);}}Anonymous class diagramFoo$1ActionListener«implements»Mouse example againblankArea.addMouseListener(new MouseAdapter (){public void mouseClicked(MouseEvent e) {MouseEventDemo2.this.saySomething("Mouse clicked (# of clicks: " +e.getClickCount() + ")", e);}});Access to External Values Instance variables of enclosing class Final variables in creating methodAccess to Valuespublic class MyImagePanel{ String m_baz;public void foo (){ ... method body ...}... rest of class ...public void addImageLabel (String caption){ JLabel lbl = new JLabel (caption);final MyImage img = new MyImage (caption);lbl.addMouseListener (new MouseAdapter (){public void mouseClicked (MouseEvent e){ // need to access the outer classbar(MyImagePanel.this);// need to call outer class method// access final variable// access instance variableMyImagePanel.foo (img, m_baz);}});...MouseListener interfacevoid mouseClicked(MouseEvent e) void mouseEntered(MouseEvent e) void mouseExited(MouseEvent e) void mousePressed(MouseEvent e) void mouseReleased(MouseEvent e)Event handling strategies Location of EH code external component class named inner class anonymous inner class Base class or interface used Implement XxxListener Extend XxxAdapterRecommendation Use anonymous inner class unless EH is large, then used named inner class Extend Adapter unless all interface methods needed Note: no ActionAdapter classEvent handling thread Can only process one event at a time Time-consuming event handlers tie up the interface no other actions


View Full Document

DePaul IS 313 - GUI III

Download GUI III
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view GUI III and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view GUI III 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?