File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with exit on close operation

 
Es Tresidder
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the case of EXIT_ON_ClOSE. You've made a mistake there. And please UseCodeTags next time.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob

Thanks for the tip on copying in command prompt.

I see my error now, in the original code. Doh!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic