rsanchez-wsu / fa15-ceg3120

11 stars 2 forks source link

Problem with windowClosing from WindowAdapter #11

Closed pquackenbush closed 9 years ago

pquackenbush commented 9 years ago

Does anyone have a clue why this would give the error: The method windowClosing(WindowEvent) of type new WindowAdapter(){} must override or implement a supertype method?

I checked the compiler compliance for the project and that doesn't seem to be the issue, and on top of that, WindowAdapter has been around since 1.1. The method header was copied straight from the WindowAdapter source. So it's not like I'm trying to override a method that doesn't exist. I've used something similar before, so I'm completely at a loss here. Any ideas would be awesome. custFrame is a JFrame obj.

custFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
custFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
        int result = JOptionPane.showConfirmDialog(null,
            "Do you really wish to exit?", "Title",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if(result != 0){
            //release any network/file resources
        }
    }
});
pquackenbush commented 9 years ago

Resolved... eclipse in it's infinite wisdom imported com.sun.glass.events.WindowEvent instead of java.awt.event.WindowEvent

Fixed the import, fixed the issue.

rsanchez-wsu commented 9 years ago

@pquackenbush, when you let Eclipse's auto-complete help you out sometimes it grabs the wrong one. I have had this happen where I need to import List and Eclipse suggests java.awt.List and java.util.List and I will accidentally click on java.awt.List and be left wondering why things aren't working how I expect.