• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

problem with exit on close operation

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the case of EXIT_ON_ClOSE. You've made a mistake there. And please UseCodeTags next time.
 
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic