Results 1 to 3 of 3
  1. #1
    mallorz is offline Member
    Join Date
    Jan 2014
    Posts
    97
    Rep Power
    0

    Default Can someone help me understand this? - WindowListeners

    >>> Article

    I do not have a close button on my main frame, I'd like to just leave the user to use the top 'X' button. That said, however, I'd like to greet them with a Goodbye message upon exit. I found the article above, but I get an error when I try to implement it.

    I've highlighted it below. I must not fully understand what the above article is explaining and I can't seem to find much else on the internet.

    Words of wisdom for me?

    Java Code:
    public class StartProgram {
    
    	public static <T> void main(String[] args) {
    
    		SwingUtilities.invokeLater(new Runnable() {
    		
    			public void run() {
    				CustomerView<T> frame = new CustomerView<>(); // <T> = Generic data type, "raw"
    				frame.setTitle("Manage Customers"); // Title
    				frame.pack(); // Auto-size frame, hug contents
    				frame.setResizable(false); // Do not allow resizing
    				frame.setLocationRelativeTo(null); // Open in middle of screen
    				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    				frame.setResizable(false);
    				frame.addWindowListener(new WindowListener()); 
    //  **** Cannot instantiate the type WindowListener 
    				frame.setVisible(true); // Make visible
    			
    			} // End of run()
    
    		}); // End of SwingUtilities
    		
    	} // End of main()
    	
    	public void windowClosing(WindowEvent e) {
    		
                    // ****** Related question
    		// ... call to View for displayMessage() method?
    		// ... or enter it's own message dialog
    	}
    	
    } // End of StartProgram

  2. #2
    mallorz is offline Member
    Join Date
    Jan 2014
    Posts
    97
    Rep Power
    0

    Default Re: Can someone help me understand this? - WindowListeners

    Found an article that was much clearer:


    http://www.javabeginner.com/java-swing/java-jframe-class-example


    All is well. Thank you and I apologize again for another thread that was answered shortly after hitting submit. May help someone else out though. :-/

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Can someone help me understand this? - WindowListeners

    You need to create a class that implements the approrpriate WindowListener interface. It would be easiest to write your own class that extends the WindowAdapter class and then override the appropriate method.

    e.g.

    Java Code:
    class MyWindowListener extends WindowAdapter {
        // override appropropriate method(s) here.
    }
    then you would do a
    Java Code:
    addWindowListener(new MyWindowListener());
    Read more about it here --> How to Write Window Listeners (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. I want to understand this...
    By WHM2 in forum New To Java
    Replies: 6
    Last Post: 01-14-2014, 09:51 PM
  2. I cant understand OOP
    By eng_hyzoom in forum New To Java
    Replies: 4
    Last Post: 11-19-2010, 04:10 PM
  3. GUI help. Don t understand
    By s0meb0dy in forum AWT / Swing
    Replies: 2
    Last Post: 10-27-2010, 09:40 PM
  4. Trying to understand
    By ladykrimson in forum New To Java
    Replies: 20
    Last Post: 10-12-2010, 11:10 PM
  5. I don´t understand
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 02-22-2009, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •