LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2006, 04:31 AM   #1
Fredstar
Member
 
Registered: Jul 2004
Location: Rochester, NY
Distribution: Fedora9::FreeBSD7.1
Posts: 296

Rep: Reputation: 30
reading JOptionPane when cancel is hit


Sorry for asking a question i could probably find in the api, but i gotta get some sleep before class tomorrow!!

Im trying find out how i could find out if the cancel button is hit in JOptionPane. does it give a null?

like if i was to do the following

String someText =JOptionPane.showInputDialog(null, "enter some stuff");

and the cancel button was hit how would i know?

thanks
 
Old 03-18-2006, 07:25 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Yeah, it will return null if you click cancel. If you click OK without typing anything, then you will get an empty String, which is not null. Test this:

Code:
import javax.swing.*;

public class MainClass {

    public static void main(String[] args) {

        String someText = JOptionPane.showInputDialog(null, "Enter some stuff");
        System.out.println(someText);

        if (someText != null) {
            System.out.println("You've entered: " + someText);
        } else {
            System.out.println("someText was null");
        }

    }
}
 
Old 03-18-2006, 07:31 AM   #3
Fredstar
Member
 
Registered: Jul 2004
Location: Rochester, NY
Distribution: Fedora9::FreeBSD7.1
Posts: 296

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Mega Man X
Yeah, it will return null if you click cancel. If you click OK without typing anything, then you will get an empty String, which is not null. Test this:

Code:
import javax.swing.*;

public class MainClass {

    public static void main(String[] args) {

        String someText = JOptionPane.showInputDialog(null, "Enter some stuff");
        System.out.println(someText);

        if (someText != null) {
            System.out.println("You've entered: " + someText);
        } else {
            System.out.println("someText was null");
        }

    }
}
Thing is that

String someText = JOptionPane.showInputDialog(null, "hit cancel");

!=null

or better put

String st1, st2;

st1 = new String("null"); //which is how JOptionPane will store it
st2 = new String(null);

st1 != st2

which is what im trying to get arround.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto Cancel Subscription Gato Azul Slackware 3 10-04-2005 09:04 PM
Cancel printing jobs Imerion Linux - Software 3 01-12-2005 03:07 PM
Can't cancel a print job........ soujrnr Linux - Software 0 10-03-2004 08:52 PM
Cancel All Scheduled Jobs? Rv5 Programming 1 09-17-2004 08:39 PM
cancel shutdown kc8tbe Linux - General 3 06-02-2003 08:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration