Why my program can't exit ?thanks

here is my code:
I want to exit it when I press "F1",but it don't have any response ,why?thanks!
import java.awt.*;
class myframe
     public boolean handleEvent(Event evt)
          if (evt.id==Event.F1) System.exit(0);
          return true;
     public static void main(String args[])
          Frame f=new Frame();
          Panel p[]=new Panel[5];
          int i;
          for (i=0;i<5;i++)
               p=new Panel();
               p[i].setVisible(true);
               p[i].setSize(80,80);
               p[i].setBackground(Color.yellow);
          f.setSize(400,400);
          f.add(p[0]);
          f.setLayout(null);
          f.setVisible(true);

In other words add this code to your application:
addKeyListener(new KeyAdapter(){
     public void keyPressed(KeyEvent e){
          if(e.getKeyCode() == KeyEvent.VK_F1)
               System.exit(0);
});You need to register a key listener with your frame in order to respond to events generated by pressing of a key. And than you have to check which key was pressed.

Similar Messages

  • Why this program can not update the datatbase?

    The database I used is MS SQL Server 2000.
    The program can run normally,but the table is not updated.
    import java.sql.*;
    public class BatchUpdate {
    public static void main(String args[]) {
    String url = "jdbc:mySubprotocol:myDataSource";
    Connection con;
    Statement stmt;
    try {
    Class.forName("myDriver.ClassName");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    try {
    con = DriverManager.getConnection(url, "myLogin", "myPassword");
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    con.setAutoCommit(false);
    stmt.addBatch("INSERT INTO COFFEES " + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES " + "VALUES('Hazelnut', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES " + "VALUES('Amaretto_decaf', 49, 10.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES " + "VALUES('Hazelnut_decaf', 49, 10.99, 0, 0)");
    int [] updateCounts = stmt.executeBatch();
    ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");
    System.out.println("Table COFFEES after insertion:");
    while (uprs.next()) {
    String name = uprs.getString("COF_NAME");
    int id = uprs.getInt("SUP_ID");
    float price = uprs.getFloat("PRICE");
    int sales = uprs.getInt("SALES");
    int total = uprs.getInt("TOTAL");
    System.out.print(name + " " + id + " " + price);
    System.out.println(" " + sales + " " + total);
    uprs.close();
    stmt.close();
    con.close();
    } catch(BatchUpdateException b) {
    System.err.println("SQLException: " + b.getMessage());
    System.err.println("SQLState: " + b.getSQLState());
    System.err.println("Message: " + b.getMessage());
    System.err.println("Vendor: " + b.getErrorCode());
    System.err.print("Update counts: ");
    int [] updateCounts = b.getUpdateCounts();
    for (int i = 0; i < updateCounts.length; i++) {
    System.err.print(updateCounts[i] + " ");
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    System.err.println("SQLState: " + ex.getSQLState());
    System.err.println("Message: " + ex.getMessage());
    System.err.println("Vendor: " + ex.getErrorCode());

    con.setAutoCommit(false);The changes are not comitted to the DB when you set autocommit to false.
    commit with
    con.commit();
    or dont set autocommit to false
    rgds

  • Why my program can only run once?

    I have a program that is already run for a long period. The program will move a axis backward to find index to
    set the zero position. But in these day, i don't know why it cannot find the index and the motor will be out of
    control. After i used a new motor control card to replace the old one, i can run the peogram once. But when
    i use the program again, it will have the same problem. I need to shutdown the computer first to run it again.

    Hi,
    There are a few things that could be causing the problem.  To help narrow the problem down try running
    the program and then go into MAX under 1D interactive (Device and
    Interfaces>>NI Motion Devices>>PCI
    XXXX>>Interactive>>1D Interactive) to see if you are getting an
    error there.   Run the code in highlight execution, and then watch
    MAX to see where the error occurs.  Let
    us know what axis status lights go on/off and when it happens.  
    Also if you could send a reduced sample of your code (one
    main VI that contains just enough sub vi’s to move the motor and then read it’s
    position) that still reproduces the same error then it would be easier to test
    here.  Let me know what you find out when
    you run the code in highlight execution.
    Have a great day,
    GG

  • Can someone else try to compile this and see why the program is returning..

    Can someone else try to compile this and see why the program is returning "false" when I try to delete the files on exit (at bottom of code)... I have the source code uploaded to the web as well as my 2 text test files inside a zip file(they need to be unzipped so you can try to test the program) and .class file... the program works the way i want it to, but i just can't seem to delete the 3 temporary files i use... why??? why does it return false???
    Thanks in advance,
    Disco Hristo
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.java
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.class
    http://www.holytrinity-holycross.org/DiscoHristo/tests.zip
    * Assemble.java 1.0 02/06/22
    * @author Disco Hristo
    * @version 1.0
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Assemble
         public static void main(String args[]) throws IOException
              if (args.length > 0) //     Checks to see if there are any arguments
                   printArgumentInfo ();
              else // if no arguments run the program
                   getInput ();
                   printToFile ();
                   deleteFiles ();
         public static void getInput () throws IOException
         //     Gets the input and then send it to 3 files according to Tags
              File head = new File ("head.chris");
    PrintStream headStream = new PrintStream (new FileOutputStream (head));
    File body = new File ("body.chris");
    PrintStream bodyStream = new PrintStream (new FileOutputStream (body));
    File foot = new File ("foot.chris");
    PrintStream footStream = new PrintStream (new FileOutputStream (foot));
    String input; //     String used to store input                
    File d = new File(".");
    String files[] = d.list();
    for (int n=0; n!=files.length; n++)
         if (files[n].endsWith(".txt") == true)
              String fileName = files[n];
              BufferedReader in = new BufferedReader (new FileReader(fileName));
                   while (true)
                   input = in.readLine();
                   if (input != null)
                        input = input.trim();
                        if (input == null) // if no more input                          
                             break;
                        else if ( (input.compareTo("<HEAD>")) == 0) // if start of <HEAD> text
                             do
                                  input = in.readLine();
                                       if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</BODY>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<HEAD>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <HEAD> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</HEAD>")) != 0) //if not end of tag
                                            headStream.println(input); //print to text file
                             while ( (input.compareTo("</HEAD>")) != 0);
                        else if ( (input.compareTo("<BODY>")) == 0) // if start of <BODY> text
                             do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<HEAD>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</HEAD>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<BODY>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <BODY> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</BODY>")) != 0) //if not end of tag
                                            bodyStream.println(input); //print to text file
                             while ( (input.compareTo("</BODY>")) != 0);
                             else if ( (input.compareTo("<FOOT>")) == 0) // if start of <FOOT> text
                                  do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                            ((input.compareTo("<HEAD>")) == 0) ||
                                                 ((input.compareTo("</BODY>")) == 0) ||
                                                 ((input.compareTo("</HEAD>")) == 0) ||
                                                 ((input.compareTo("<FOOT>")) == 0))
                                                 //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <FOOT> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</FOOT>")) != 0) //if not end of tag
                                                 footStream.println(input); //print to text file
                             while ( (input.compareTo("</FOOT>")) != 0);
                   else
                        break;
    public static void printToFile () throws IOException
    // Prints the text from head.txt, body.txt, and foot.txt to the output.log
         File head = new File ("head.chris");
         FileReader headReader = new FileReader(head);
              BufferedReader inHead = new BufferedReader(headReader);
              File body = new File ("body.chris");
              FileReader bodyReader = new FileReader(body);
              BufferedReader inBody = new BufferedReader(bodyReader);
              File foot = new File ("foot.chris");
              FileReader footReader = new FileReader(foot);
              BufferedReader inFoot = new BufferedReader(footReader);
              PrintStream outputStream = new PrintStream (new FileOutputStream (new File("output.log")));
              String output;     //string used to store output
              while (true)
                   output = inHead.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inBody.readLine();
                   if (output == null)// if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inFoot.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              //Close up the files
              inHead.close ();
              inBody.close ();
              inFoot.close ();
              outputStream.close ();     
         public static void printArgumentInfo () //     Prints argument info to screen
              System.out.println("");
              System.out.println("Disco Hristo");
              System.out.println("");
              System.out.println("Assemble.class is a small program that");
              System.out.println("takes in as input a body of text and then");
              System.out.println("outputs the text in an order according to");
              System.out.println("the tags that are placed in the input.");
         public static void deleteFiles ()
              File deleteHead = new File ("head.chris");
              File deleteBody = new File ("body.chris");
              File deleteFoot = new File ("foot.chris");
              deleteHead.deleteOnExit();
              deleteBody.deleteOnExit();
              deleteFoot.deleteOnExit();
    }

    I tired your program, it still gives false for files deleted. I tool the same functions you used in your program and ran it. The files get deleted. Tried this :
    <pre>
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class FileTest {
         public static void main(String args[]) {
              FileTest f = new FileTest();
              try {
                   f.createFile();
                   f.deleteFile();
              } catch(IOException ioe){
                   System.out.println(ioe.getMessage());
         public void createFile() throws IOException {
              System.out.println("In create file method...");
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              PrintStream testStream = new PrintStream (new FileOutputStream (test));
              PrintStream tstStream = new PrintStream (new FileOutputStream (tst));
              testStream.println("this is a test to delete a file");
              tstStream.println("this is the second file created");
              testStream.close();
              tstStream.close();          
         public void deleteFile() throws IOException {
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              System.out.println(test.delete());
              System.out.println(tst.delete());
    </pre>
    Also check the starting and closing braces for your if..else blocks.
    -Siva

  • Why can't the finder in Mountain Lion 10.8.2 find files that have successfully downloaded, or that other programs can find?

    Why can't the finder in Mountain Lion 10.8.2 find files that have successfully downloaded, or that other programs can find?
    This happens with maybe 1 out of 5 files. These are files that have either an ."aa" extention, or or are libraries that icloud can see, but finder can't.

    Files beginning with a period are invisible and library files are system files. Spotlight cannot find either unless configured to do so (btw, this is not a Finder issue but a Spotlight issue.)
    Get Spotlight to search system files (and more)
    Enter the search term in the Finder window's search field.
    Click the [+] button in the search bar to add a search option.
    In the first drop down menu choose Other.
    Choose “System Files” from the list that pops up (and check the box to place in drop down menu to avoid this step later,) click on the OK button.
    Now back in the Finder choose Include from the second drop down menu.

  • Why SAP Standard Program Can full screen in different  screen resolution ,but my own program can't?

          How to make my program can display full screen in the different screen resolution ? can you tell me ,
          Thanks  everyone!  eg. T-code: SOST

    It appears that the full-screen display will only work on the display that has the menu bar.
    You can switch the menu bar to your external display by going to Solid Apple -> System Preferences -> Displays, then Arrangement.
    Grab the menu bar and drop it on the icon representing your external display.
    When you full screen an app it should then full screen on the Cinema display.
    I wish it would just full screen on the display the window is on, but that is evidently not the way it was designed to work.

  • Why does I can't install the FORM6I DEMO program

    Hi :
    Why does I can't install the FORM6I DEMO program?
    Environment:WINDOWS98 ORACLE 817 single machine version FROM6i
    The FORM6i installs in the :D:\ FORM60
    The ORACLE817 installs in the D:\ORACLE 817
    While installing the DEMO, always hint is not an ORACLEHOME catalogue, two catalogues can't all install.
    Please the help!

    Hi Mountain Matt,
    Please make sure that you're logged in as an administrator, and that any antivirus software on your system is disabled. Then, trying downloading Acrobat from Download Acrobat products | Standard, Pro | XI, X, and run the installer.
    Please let us know how it goes. If you're still having trouble and need additional help, it will be very helpful to know what version of Windows you're using.
    Best,
    Sara

  • I want to download pages, it won't let me. Says it need os x 10.9 or later-I have os x 10.8.5-all updates have been done. Why is this? what can i do? Is there another pages app i can use? thanks

    I want to download pages, it won't let me. Says it need os x 10.9 or later…I have os x 10.8.5…all updates have been done. Why is this? what can i do? Is there another pages app i can use? thanks do i need to download maverick? thanks

    Pages 5 requires OSX 10.9, for some reason that only Apple knows. Many users will not be able to install Mavericks on their Macs or do not want to.
    It has simultaneously removed iWork '09/Pages '09 from the App Store.
    You could ask Apple why it does things like this, but it doesn't say.
    If you don't already have iWork '09 I believe you can still purchase it from Amazon.
    Peter

  • Why Can't I Thank The Guy Who Helped Me Solve My Problem

    A week or so ago, I posted a problem related to FFox not starting with my last session, when it's what I have saved in my preferences - - Well Thanks to cor-el (who is listed with an incredible 73,525 posts!) I checked http://kb.mozillazine.org/Preferences_not_saved & found I had 2! prefs.js files - naturally (thanks to MacroSloth) in 2 different locations, so as soon as I deleted the older 1 & restarted FFox, it immediately came back with my latest session, just the way I wanted
    I suggest if anybody has a similar problem with FFox not starting with their latest session (when it's what you have set), then you might find the perfect solution is to check whether you have 2 prefs.js files & to delete the older
    Anyway, I wanted to post my gratitude To Cor-El for the lead which led to the solution, but the mozilla support site kept telling me, after I jumped thru the hoops they set up, how I couldn't post the reply (namely these thanks to cor-el) I wanted, so I've had to resort to this work around, by posting this question : why couldn't I post my thanks on the thread itself?
    frebe
    == This happened ==
    Not sure how often
    == I tried to thank cor-el for his help

    Hi frebe.
    support.mozilla.org is being redesigned to fix these issues. You can always create a free account here to have unlimited access to the public forums. It's very easy, and you don't have to post as a guest anymore. It also makes it easy for you to answer other users' questions, if you want to help support.mozilla.org (SUMO, for short).
    Here's a link about the redesign:
    http://blog.mozilla.com/sumo/2010/05/11/check-out-mockups-for-the-new-support-forums/
    There's loads more stuff too. :)

  • After updating my apple pad 3 , i cant make video anymore! somebody can tell me why e what can i do? thanks so match

    after updating my apple pad 3 , i cant make video anymore! somebody can tell me why e what can i do? thanks so match

    Try sliding the words up/down to select the various modes.

  • I live in Mexico, buy the product in Mexico "creative cloud" $ 599.88 per year, I need to contact a representative of Mexico, the program can not be installed, they double charged me urgently.  Thank you.

    I live in Mexico, buy the product in Mexico "creative cloud" $ 599.88 per year, I need to contact a representative of Mexico, the program can not be installed, they double charged me urgently.
    Thank you.

    http://helpx.adobe.com/adobe-connect/adobe-connect-phone-numbers.html
    -orders, returns http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • My program delay on exit! Why?

    I don't know why some program such as Gimp, Deadbeef or Sublime-Text take about 1.5 or 2 seconds to close. I have tried to run it in terminal, there is not other error ouput except missing GTK theme "adwaita". My Arch is up to date and it work perfect except this problem! Could any one please tell me how to solve this problem?

    That could be absolutely normal. It's common for programs that they need to do some work before they close (e.g. some cleanup of temporary files, persisting the current session or configuration etc.). For me Gimp takes a second or two to close on every platform I've run it on so far. Sublime closes instantly for me most of the times, though. But I know that it persists it's current state on close, that could be the reason. Firefox also is known to take some time to completely shutdown (I think it hides the Window pretty fast, but it sometimes runs a few seconds in the background before it is finished).

  • Regarding how to find out a program is User Exit/executable

    Hi,
    Can anybody tell me how can we find wether a particular program is used in executable program (or) user exit program?
    One thing we can find out is wether the program type is 'I' or 'R' etc..
    Thanks in advance.
    Thanks,
    Deep.

    Hi...
    See the following links..
    it helps you a lot..
    how can we C the USER_EXITS in Z programs
    how can we find the list of user exits for a transaction
    How to find the active user exits in my client
    How to find user exits for a transaction
    Hope it helps you...
    Let me know if u have any more doubt...
    Reward points if useful......
    Suresh.......

  • When opening PS CC 2014 I get message "The program can't strt because ONCoreFoundation8.dll is missing from your computer. Try reinstalling the program to fix this problem".  I did and still get same message.

    when opening PS CC 2014 I get message "The program can't start because ONCoreFoundation8.dll is missing from your computer. Try reinstalling the program to fix this problem".  I did and still get same message.

    Win 7 64bit, have PS cs6, pscc. pscc2014. also Lightroom 5.5 (just upgraded to 5.6). Also the latest updates for all Adobe programs.   But still get
    But the program does start and seems to work well.  But annoying as hell!!!
    Also don't understand why there is pscc2014 rather than just updating pscc??
    Thanks,
    Bob Lurie

  • Why do we need  user exit number

    Hi,
    why do we need  user exit number?/
    what is the purpose of this user exit number??
    example (U22....)
    thanks
    Rama

    Hi Rama,
    Under a user exit number you can have multiple Exits/FMs. If you add this single number in CMOD for any project then you can make use of all the exits under this User Exit number.
    Hope i have answered your question.
    THnaks,
    Anil.

Maybe you are looking for

  • New 16:9 squeeze vs. 4:3 question (hopefully not a re-hash)

    first of all, i did numerous searches to find the answer to this...couldn't find it. if this has BEEN answered before, please either answer again or direct me to the proper thread. please be kind. flaming is not necessary. i work at a broadcast stati

  • Hard Disk issue with Toshiba Satellite P755-S5390

    Well, I'm at my wit's end on this one so after several months of searching for an answer I'm presenting this one to my fellow Toshiba users. I have a Toshiba Satellite P755  that I purchased around March of 2012 so it is well out of warranty unfortun

  • How do i get my adobe flash player up and running?

    I attend RioLearn through Rio Salado CC.. I need help accessing one of my assignments through my "myitlab". The screen that keeps popping up is telling me that I need to download the flash player, when i click on the link, the link is blank. the adob

  • Can iphone ios 8.2 get a trojan horse of some sort?

    I texted my sister telling her my daughter was invited to MV etc and when I went to open her reply, in the box it would say, "I want to go" as if I wrote that and I didn't. Another example is, I texted my sister this, "Rachael filed for divorce today

  • Remote Log in

    Hi I wanna remote log in a Linux server and compress/uncompress a file using my Java app Any suggestion regarding this ..............????