wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes problem with exit on close operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with exit on close operation" Watch "problem with exit on close operation" New topic
Author

problem with exit on close operation

Es Tresidder
Greenhorn

Joined: Aug 11, 2010
Posts: 16
hi there

I'm working my way through the head first book. On page 355 there is a "building your first GUI" section. When I copy the code on the page into a text editor, save as a java file, and try and compile it from the command prompt I get the following message;

C:\Program Files\Java\javac SimpleGui1.java
SimpleGui1.java:9: cannot find symbol
symbol : variable EXIT_ON_CLOSE
location: class javax.swing.JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

1 error

I have checked and double checked my code, which was typed directly from the book. What am I doing wrong. Any help much appreciated! Original code below:

import javax.swing.*;

public class SimpleGui1 {
public static void main (String[] args) {

JFrame frame = new JFrame();
JButton button = new JButton("click me");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_ClOSE);

frame.getContentPane().add(button);

frame.setSize(300,300);

frame.setVisible(true);
}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Check the case of EXIT_ON_ClOSE. You've made a mistake there. And please UseCodeTags next time.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Rob Prime wrote:. . . You've made a mistake there. And please UseCodeTags next time.
You really ought to post your exact code and error messages. You wrote EXIT_ON_CLOSE in one place and EXIT_ON_ClOSE in another, so you haven't copied your error message exactly.
Es Tresidder
Greenhorn

Joined: Aug 11, 2010
Posts: 16
Hi Rob and Ritchie

First of all sorry for the lack of code tags and for not posting my exact error message. I'm not able to copy and paste out of a command prompt window, so I typed it out. How do I get around that problem?

Ritchie - both versions of "EXIT_ON_CLOSE" looked exactly the same on my browser, but I went back and re-typed the code with the caps lock down rather than just pressing shift, and this seemed to fix it. Is there a difference in java between typing letters with the shift key depressed and with the caps lock on?

Thanks for your help.

Es
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Es Tresidder wrote:First of all sorry for the lack of code tags and for not posting my exact error message. I'm not able to copy and paste out of a command prompt window, so I typed it out. How do I get around that problem?

Right-click on the title bar, then select Edit -> Mark. You can then start dragging to select what you want to copy. Press Enter or right-click and select Edit -> Copy to copy the current selection to the clipboard.

Ritchie - both versions of "EXIT_ON_CLOSE" looked exactly the same on my browser, but I went back and re-typed the code with the caps lock down rather than just pressing shift, and this seemed to fix it. Is there a difference in java between typing letters with the shift key depressed and with the caps lock on?

Only the fact that with Shift you may accidentally release it temporarily, causing you to type a lowercase character.
Es Tresidder
Greenhorn

Joined: Aug 11, 2010
Posts: 16
Hi Rob

Thanks for the tip on copying in command prompt.

I see my error now, in the original code. Doh!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Rob Prime wrote: . . . you may accidentally release it temporarily, . . .
Only if you want upper-case characters. I found it really difficult to write EXIT_ON_ClOSE
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with exit on close operation