Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to output information entered in JOptionPane Dialogue Boxes?

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to output information entered in JOptionPane Dialogue Boxes?

    Hi everyone, I understand the basics of using the JOptionPane Message boxes, but how do i take the information that is entered and store it as a file, or print it. I'm in my 6th week of class, and this happens to be maintenance related.

    Any help or guidance would be greatly appreciated.

    Thanks!!!!!!!

    ----------------------------------------------------------------------------------------------------------------------------------------------


     
     
     
    import javax.swing.JOptionPane;
     
    public class Example_Maintenance_System{
     
      public static void main (String [] args)
      {
     
        //Operator Name Input
        String operator_name;
        operator_name = JOptionPane.showInputDialog("Please scan your barcode");
     
     
     
        //Machine Number Input
        String temp_machine_number;
        double machine_number;
        temp_machine_number = JOptionPane.showInputDialog("Please scan machine barcode");
        machine_number = Double.parseDouble(temp_machine_number);
     
     
     
     
        //Coolant Tank
        String coolant_level;
        Object [] possibilities = {"1/4","1/2","3/4","Full"};
        coolant_level = (String)JOptionPane.showInputDialog(null,"Please enter coolant tank level: ", "Coolant Level", JOptionPane.PLAIN_MESSAGE,null, possibilities, "1/4") ;
     
     
                    if (!(coolant_level.equals("3/4")||(coolant_level.equals("Full"))))
                         JOptionPane.showMessageDialog (null, "Coolant Level Too Low!\n" + "Please Refill", "Alert: Low Coolant", JOptionPane.ERROR_MESSAGE);
                    else
                         JOptionPane.showMessageDialog(null, "Coolant Level is Acceptable", "Acceptable", JOptionPane.PLAIN_MESSAGE);
     
     
     
     
        //Dilution - Refractometer Reading
        String temp_refract_reading;
        double refract_reading;
        temp_refract_reading = JOptionPane.showInputDialog("Please enter refract reading");
        refract_reading = Double.parseDouble(temp_refract_reading);
     
                     if ((refract_reading > 2.6)||(refract_reading < 1.8))
                          JOptionPane.showMessageDialog (null, "Refract reading is unsatisfactory!\n" + "Please Correct", "Alert", JOptionPane.ERROR_MESSAGE);
                     else
                          JOptionPane.showMessageDialog(null, "Refract reading is acceptable", "Acceptable", JOptionPane.PLAIN_MESSAGE);
     
     
     
     
        //pH level
        String temp_ph_reading;
        double ph_reading;
        temp_ph_reading = JOptionPane.showInputDialog("Please enter pH reading");
        ph_reading = Double.parseDouble(temp_ph_reading);
     
                   if ((ph_reading > 9.5)||(ph_reading < 8.5))
                        JOptionPane.showMessageDialog (null, "pH reading is unsatisfactory!\n" + "Please Correct", "Alert", JOptionPane.ERROR_MESSAGE);
                   else
                        JOptionPane.showMessageDialog(null, "pH reading is acceptable", "Acceptable", JOptionPane.PLAIN_MESSAGE);
     
     
     
     
        //Way Lube Level
        String way_lube_level;
        way_lube_level = (String)JOptionPane.showInputDialog(null,"Please enter way lube level: ", "Way Lube Level", JOptionPane.PLAIN_MESSAGE,null, possibilities, "1/4") ;
     
                  if (!(way_lube_level.equals("3/4")||(way_lube_level.equals("Full"))))
                     JOptionPane.showMessageDialog (null, "Way Lube Level Too Low!\n" + "Please Refill", "Alert: Low Way Lube", JOptionPane.ERROR_MESSAGE);
                  else
                     JOptionPane.showMessageDialog(null, "Way Lube Level is Acceptable", "Acceptable", JOptionPane.PLAIN_MESSAGE);
     
     
     
      }
    }
    Last edited by Norm; February 25th, 2014 at 03:05 PM. Reason: Better formatting; added ] to code tag


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to output information entered in JOptionPane Dialogue Boxes?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    do i take the information that is entered and store it
    Many of the JOptionPane methods return values that should be stored in a variable for the program to use.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to output information entered in JOptionPane Dialogue Boxes?

    Quote Originally Posted by StaffordEmpire View Post
    how do i take the information that is entered and store it as a file, or print it.
    As Norm has rightly said, JOptionPane (for input dialogs) simply gives you a value ... what you do with this value is up to you. JOptionPane doesn't know anything about files or standard-output on console, etc...

    If you want to use the basic, standard, I/O, you need to understand the content of the java.io package.
    Please see Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. boxes
    By keepStriving in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 8th, 2013, 05:59 PM
  2. JOptionPane output assistance
    By dtooth71 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 10th, 2012, 10:59 AM
  3. Parsing information from a Custom Dialogue Box
    By MXA92 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 23rd, 2012, 06:48 PM
  4. Replies: 1
    Last Post: December 4th, 2010, 05:26 PM
  5. how to write an if statement which evaluates 3 dialogue boxes
    By humdinger in forum Loops & Control Statements
    Replies: 6
    Last Post: January 14th, 2010, 01:28 PM

Tags for this Thread