Help with JOptionPane.showInputDialog

Hi!!
People here helped me before so trying my luck again:)
In order to get information from people I use JOptionPane.showInputdialog,
problem is if I need to get 2 different types of info I have to use
        naam = JOptionPane.showInputDialog(null, "Geef speler naam:");
        land = JOptionPane.showInputDialog(null, "Geef Land Speler:");Is there anyway to make this happen in 1 screen?
Or do I have to make a new frame for that with textfields and such?
if so, anyone got an example?

im new here:) so.. New to Java Technology suits me
well I guess.No it doesn't. New to Java forum is for classpath questions, simple compile time problems and lazy students to cross post their assigments into.
Swing questions, such as the one you asked, should be asked in the Swing forum because the people who answer questions in there are more knowledgeable about Swing. Plus you will almost 100% likely to find working example codes from previous posts in the Swing forum for Swing related questions.
Much more likely than in here anyway.

Similar Messages

  • Strange problem with JOptionPane.showInputDialog

    I have a strange problem with JOptionPane.showInputDialog in that when I run a program anything that is typed in is displayed backwards, for example: I type this character > and this < is what is displayed.
    I've uninstalled the sdk and reinstalled it twice but that hasn't solved my problem and the java plug-in in the control panel is displaying the same symptoms.
    I did a search before posting this but all I got really was posts from people who wanted to reverse their text.
    Thanks for your help on this.

    Is it just the < and > characters?

  • Help with JOptionPane - custom InputDialog

    I need a little help here because I am trying to build a custom JOptionPane that prompts the user to choose 3 values from 3 drop-down lists and then returns those three values in a string. Specifically, this dialog is a very simple date chooser (because I don't really want to use JDateChooser right now). How do I overwrite the showInputDialog() method or the paintComponent() method to make it display three drop-downs?

    Here's an example with multiple text fields. You should be able to modify it easily to use combo boxes:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class OptionPaneMultiple extends JFrame
         public OptionPaneMultiple()
              JTextField firstName = new JTextField(5);
              JTextField lastName = new JTextField(5);
              Object[] msg = {"First Name:", firstName, "Last Name:", lastName};
              Object[] options = {"Ok", "Cancel", "Whatever"};
              JOptionPane op = new JOptionPane(
                   msg,
                   JOptionPane.PLAIN_MESSAGE,
                   JOptionPane.OK_CANCEL_OPTION,
                   null,
                   options);
              JDialog dialog = op.createDialog(this, "Enter Name...");
              dialog.show();
              int result = JOptionPane.OK_OPTION;
              try {result = ((Integer)op.getValue()).intValue();}
              catch(Exception uninitializedValue){}
              if(result == JOptionPane.OK_OPTION)
                   System.out.println(firstName.getText() + " : " + lastName.getText());
              else
                   System.out.println("Canceled");
         public static void main(String[] args)
              JFrame frame = new OptionPaneMultiple();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • Help with JOptionPane -- Popup Dialog Boxes

    I need to create a popup dialog box that looks like this:
    http://img88.imageshack.us/img88/6900/jbuttonpm2.jpg
    red = JTextField (Where the user will input a number that I need to store)
    green = Drop Down List with 1,2,3 as choices
    blue = JButtons for OK and Cancel
    So yeah, I need an easy way to collect a bunch of information from the user, and this was the best way I could think to do it. The user has to enter a number for all of the fields, but is there any way for the field to have a value of 0 there by default?
    I read some of the Java tutorials for using the JOptionPane's showXXXDialog but I wasn't sure if that can't of method could create such a complex dialog box. Any help would be really appreciated. How can I make that dialog box and get all the input I need from it?

    Create a panel containing red and green and pass it as message to JoptionPane.showConfirmDialog with OK_CANCEL_OPTIONS to have blue. If it returns OK_OPTION read and use values from panel. That's it.

  • Need some help with JOptionPane

    Hi everyone. I want to create an OptionDialog with 3 textfields. So we have...
    String message1 = "The first Field";
    JTextField tf1 = new JTextField();
    String message2 = "The second Field";
    JTextField tf2 = new JTextField();
    String message3 = "The third Field";
    JTextField tf3 = new JTextField();
    Object o[] = {message 1, tf1, message2, tf2, message3, tf3};
    int result = JOptionPane.showOptionDialog(this, o, "A dialog", JOptionPane.OK_CANCEL_DIALOG,JOptionPane.QUESTION_MESSAGE, null, null, null);
    if(result == JOptionPane.OK_OPTION){
    Various actions here
    }However I want my dialog to focus in the first textfield, rather than, for example, in the OK button. I've tried a few alchemies but nothing actually worked. So I want your help :-). Is it possible to have the text indicator (you know that blinking | ) in the textfield? Can I do the same with a combo box too? I mean, how can I tell the programm to have selected the first option of the combobox when the dialog pops up?
    Thanx in advance

    Issue fixed.
    try
                String m1 = "One Field";
                String m2 = "Two Fields";
                String m3 = "Three fields";
                JTextPane tf1 = new JTextPane();
                JTextPane tf2 = new JTextPane();
                JTextPane tf3 = new JTextPane();
                Object o[] = {m1, tf1, m2, tf2, m3, tf3};
                JOptionPane pane = new JOptionPane(o, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, o[1]);
                JDialog dialog = pane.createDialog(this, "A new Dialog");
                dialog.setVisible(true);
                Object selectedValue = pane.getValue();
                if(((Integer)selectedValue).intValue() == JOptionPane.OK_OPTION)
                    <<VARIOUS ACTIONS HERE!>>
    catch(Exception e){ }Thnx everyone for stopping by!

  • Please help me! showInputDialog with specific Buttons

    Hi all,
    I'm from Germany and have some trouble with the JOptionPane package.
    Everything works fine, but I have a german operationsystem and i'm writing an 1.4 application in english.
    If I use a Optiondialog i can create my own buttontexts.
    String[] options = { "Yes", "No" };
    int n = JOptionPane.showOptionDialog(StartScreen.frame,
    "Do you really want to quit ?", // Fragetext
    "Are you sure ?", // Titel
    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, // Icon
    null, options, options[0]);
    if (n == JOptionPane.YES_OPTION) {
    Transfer.closeConnection();
    System.exit(0);
    That works, but here I see the german buttons, how can I choose specific Buttons here?
    String response = (String) JOptionPane.showInputDialog(
              contentpane, // parent
              "Who is your favorite chipmunk?", // message
              "Pick a Chipmunk", // dialog title
              JOptionPane.QUESTION_MESSAGE, // icon type
              null, // no explicit icon
              new String[] {                     // choices
                   "Alvin", "Simon", "Theodore"
              "Alvin"); // default choice
    Hope anyone can help me.
    Thanks

    in your main method :
    Locale.setDefault(Locale.UK);
    Then all default buttons will show in english.

  • Help with limiting JOptionPane output to 2 decimal places

    I don't seem to be able to figure out how to specify 2 decimal points in my output to a JOptionPane. I know how to do this in a standard program with no gui interface but I have been unsuccessful in my attempts with JOptionPane. I have included my code below and any assistance at all would be appreciated.
    import javax.swing.JOptionPane;
    public class Vehicleanalysis2
    public static void main( String args[] )
    String januaryRepairs =
         JOptionPane.showInputDialog( "Enter January's repair costs:" );
    String februaryRepairs =
         JOptionPane.showInputDialog( "Enter February's repair costs:" );
    String marchRepairs =
         JOptionPane.showInputDialog( "Enter March's repair costs:" );
    String aprilRepairs =
         JOptionPane.showInputDialog( "Enter April's repair costs:" );
    String mayRepairs =
         JOptionPane.showInputDialog( "Enter May's repair costs:" );
    String juneRepairs =
         JOptionPane.showInputDialog( "Enter June's repair costs:" );
    String julyRepairs =
         JOptionPane.showInputDialog( "Enter July's repair costs:" );
    String augustRepairs =
         JOptionPane.showInputDialog( "Enter August's repair costs:" );
    String septemberRepairs =
         JOptionPane.showInputDialog( "Enter September's repair costs:" );
    String octoberRepairs =
         JOptionPane.showInputDialog( "Enter October's repair costs:" );
    String novemberRepairs =
         JOptionPane.showInputDialog( "Enter November's repair costs:" );
    String decemberRepairs =
         JOptionPane.showInputDialog( "Enter December's repair costs:" );
    double january = Double.parseDouble(januaryRepairs );
    double february = Double.parseDouble(februaryRepairs );
    double march = Double.parseDouble(marchRepairs );
    double april = Double.parseDouble(aprilRepairs );
    double may = Double.parseDouble(mayRepairs );
    double june = Double.parseDouble(juneRepairs );
    double july = Double.parseDouble(julyRepairs );
    double august = Double.parseDouble(augustRepairs );
    double september = Double.parseDouble(septemberRepairs );
    double october = Double.parseDouble(octoberRepairs );
    double november = Double.parseDouble(novemberRepairs );
    double december = Double.parseDouble(decemberRepairs );
    double annualrepaircost = january + february + march + april + may + june + july + august + september + october + november + december;
    double payment = annualrepaircost / 12;
    if (annualrepaircost <= 3600 )
         JOptionPane.showMessageDialog(null, "          Keep your car.\n          Your monthly repair\n          costs only average\n           out to be: " + payment + "\n          Your annual repair costs\n          this year\n were: " + annualrepaircost, " Recommendation", JOptionPane.PLAIN_MESSAGE );
    else
         JOptionPane.showMessageDialog(null, "          You should consider purchasing a new\n          car if you can get a payment\n          for less than: " + payment + "\n          Your annual repair costs\n          this year\n          were: " + annualrepaircost,
         " Recommendation: ", JOptionPane.PLAIN_MESSAGE );
    }

    Hi,
    try the following:
    double payment;
    JOptionPane.showMessageDialog(null, String.format("Payment: %.2f ", payment));
    /Mattias

  • JOptionPane.showInputDialog Help!!!!

    Hello,
    I'm using JOptionPane.showInputDialog(Component parentComponent,
    Object message,
    String title,
    int messageType,
    Icon icon,
    Object[] selectionValues,
    Object initialSelectionValue ).
    which prompts the user to add some text and the same will be stored for later retrieval.
    In this case, JOptionPane pops up with a label, textfield,OK & Cancel buttons.
    Default focus is given to to the TextField.
    Is there anyway to get access to the TextField via code ?
    For example, if the user types "Hello World" in the given TextField, then I need to get the Text entered in
    the TextField in the following manner.
    String myStr = myJOptionPaneTextField().getText();
    System.out.println("Entered Text is "+ myStr);
    How can I Achieve the same ?
    Thanks in advance
    Regards
    vargav

    Why? At what point do you know you should manipulate the text? Usually, it would be when the user clicks OK, at which point it doesn't matter because the dialog is dismissed. So what kind of operations do you expect to be able to do?
    Aside from that, I'm not sure how to get the text field in the option pane, per se... It can be gotten by digging thru the pane's components til you find a text field. But you'd need to do that in a separate thread. So it's not really feasible to do that.... There is an alternative:
    The message is an object, and it can be an array of objects, which will all be added, and thus can include a message string and a text field...
    JTextField myfield = new JTextField();
    Object[] obj = new Object[2];
    obj[0] = "Enter some text here:";
    obj[1] = myfield;
    if(JOptionPane.showOptionDialog(obj, "Enter Text", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
       String value = myfield.getText();
    }Then you can do whatever you want with the text field... but the same problem is there, you have lost the dialog before you can do anything.

  • JOptionPane.showInputDialog with a JList?

    Is there any quick and easy way to use the JOptionPane.showInputDialog with a JList? the default is a drop down menu. Thanks!

    Is there any quick and easy way to use the
    JOptionPane.showInputDialog with a JList? the default
    is a drop down menu. Thanks!I have found a way to this. You need to write your own JOptionPane
    class MyJOptionPane
        public static Object showListInputDialog(Component parentComponent, Object message, String title, Object[] selecttionValues)
            Object defaultOptionPaneUI = UIManager.get("OptionPaneUI");
            UIManager.put("OptionPaneUI", "MyBasicOptionPaneUI");
            Object object = JOptionPane.showInputDialog(parentComponent, message, title, JOptionPane.PLAIN_MESSAGE, null,
                    selecttionValues, selecttionValues[0]);
            UIManager.put("OptionPaneUI", defaultOptionPaneUI);
            return object;
    }And then create your own MyBasicOptionPaneUI extending from javax.swing.plaf.basic.BasicOptionPaneUI with 2 methods overridden. The codes are copied from javax.swing.plaf.basic.BasicOptionPaneUI and modified to get rid of JComboBox.
    public class MyBasicOptionPaneUI extends BasicOptionPaneUI
        public MyBasicOptionPaneUI()
            super();
        public static ComponentUI createUI(JComponent x) {
             return new MyBasicOptionPaneUI();
        protected Object getMessage()
            inputComponent = null;
            if (optionPane != null) {
                if (optionPane.getWantsInput()) {
                    /* Create a user component to capture the input. If the
                       selectionValues are non null  with any size ,
                       it'll be a list, otherwise it'll be a textfield. */
                    Object message = optionPane.getMessage();
                    Object[] sValues = optionPane.getSelectionValues();
                    Object inputValue = optionPane
                            .getInitialSelectionValue();
                    JComponent toAdd;
                    if (sValues != null) {
                            JList list = new JList(sValues);
                            JScrollPane sp = new JScrollPane(list);
                            list.setVisibleRowCount(10);
                            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                            if (inputValue != null)
                                list.setSelectedValue(inputValue, true);
                            list.addMouseListener(new ListSelectionListener());
                            toAdd = sp;
                            inputComponent = list;
                    } else {
                        MultiplexingTextField tf = new MultiplexingTextField(20);
                        tf.setKeyStrokes(new KeyStroke[]{
                            KeyStroke.getKeyStroke("ENTER")});
                        if (inputValue != null) {
                            String inputString = inputValue.toString();
                            tf.setText(inputString);
                            tf.setSelectionStart(0);
                            tf.setSelectionEnd(inputString.length());
                        tf.addActionListener(new TextFieldActionListener());
                        toAdd = inputComponent = tf;
                    Object[] newMessage;
                    if (message == null) {
                        newMessage = new Object[1];
                        newMessage[0] = toAdd;
                    } else {
                        newMessage = new Object[2];
                        newMessage[0] = message;
                        newMessage[1] = toAdd;
                    return newMessage;
                return optionPane.getMessage();
            return null;
        private static class MultiplexingTextField extends JTextField
            private KeyStroke[] strokes;
            MultiplexingTextField(int cols)
                super(cols);
             * Sets the KeyStrokes that will be additional processed for
             * ancestor bindings.
            void setKeyStrokes(KeyStroke[] strokes)
                this.strokes = strokes;
            protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
                                                int condition, boolean pressed)
                boolean processed = super.processKeyBinding(ks, e, condition,
                        pressed);
                if (processed && condition != JComponent.WHEN_IN_FOCUSED_WINDOW) {
                    for (int counter = strokes.length - 1; counter >= 0;
                         counter--) {
                        if (strokes[counter].equals(ks)) {
                            // Returning false will allow further processing
                            // of the bindings, eg our parent Containers will get a
                            // crack at them.
                            return false;
                return processed;
        private class ListSelectionListener extends MouseAdapter
            public void mousePressed(MouseEvent e)
                if (e.getClickCount() == 2) {
                    JList list = (JList) e.getSource();
                    int index = list.locationToIndex(e.getPoint());
                    optionPane.setInputValue(list.getModel().getElementAt(index));
        private class TextFieldActionListener implements ActionListener
            public void actionPerformed(ActionEvent e)
                optionPane.setInputValue(((JTextField) e.getSource()).getText());
    }

  • HELP --JOPtionPane.showInputDialog

    I was developing a employee information system in swing.
    On the way of development,the major problem the is occuring
    is that two JOPtionPane.showInput Dialog boxes are appearing
    at a time.When I fetching the data to the JOPtionPane.showInput Dialog box and then clicking the "ok" option button,another JOPtionPane.showInput Dialog box appears making the program difficult to
    bug.
    Please suggest ways to solve this bug.

    It is more likely that your program has logical errors, just search for all JOptionPane.showInputDialog(...) statements and insert a println statement before it to trace the source of the problem.
    Visual Paradigm - http://visual-paradigm.com/

  • JOptionPane.showInputDialog with JTextarea?

    Hi,
    is it possible to put a JTextArea into a JOptionPane.showInputDialog?
    the reason i need to know is because my string is to long to fit into the current JOptionPane.showInputDialog.
    Greeting
    Grad_

    You could use your favorite component in other showXxxDialogs than the showInputDialog. Get the input on the component in an ActionListener or other appropriate event handler you've written for that component.

  • JOptionPane.showInputDialog with echo chars

    Is there any way to have use JOptionPane.showInputDialog() to have echo characters?
    so that when you type something in the dialog, you can only see ***** just like JPasswordField

    The [url http://java.sun.com/developer/JDCTechTips/]Beyond the Basics of JOptionPane article might give you some ideas..

  • Help with ArrayList...

    Hi Everyone:
    I have this java program that I'm doing for school and I need a little bit of insite on how to do certain things. Basically what I did was I read a text file into the program. Once I tokenized the text(by line), I created another object(we'll call it Throttle) and passed the values that was tokenized, then I stored the object(Throttle) into ArrayList. Now, my question is how to I access the object(Throttle) from the ArrayList and use the object's(Throttle) methods? Here's the code that I have currently:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class Project1 extends JFrame
    private JButton numOfThrottles, shiftThrottle, createThrottle, quit;
    private JPanel panel;
    private FileReader fr;
    private BufferedReader br;
    private FileWriter fw;
    private int tempTop;
    private int whatToShift;
    private int tempPosition;
    private ArrayList arrThrottles = new ArrayList();
    private String line;
    private Throttle myThrottle = null, daThrottle;
    private StringTokenizer st;
    public Project1()
    super ("Throttles - by Joe Munoz");
    panel = new JPanel();
    setContentPane(panel);
    panel.setLayout(null);
    //**button stuff
    numOfThrottles = new JButton("Number of Throttles");
    shiftThrottle = new JButton("Shift a Throttle");
    createThrottle = new JButton("Create New Throttle");
    quit = new JButton("Quit");
    panel.add(numOfThrottles);
    panel.add(shiftThrottle);
    panel.add(createThrottle);
    panel.add(quit);
    numOfThrottles.setBounds(5,7,150,25);
    shiftThrottle.setBounds(5,30,150,25);
    createThrottle.setBounds(5,50,150,25);
    quit.setBounds(5,70,150,25);
    numOfThrottles.addActionListener(new ClickDetector());
    shiftThrottle.addActionListener(new ClickDetector());
    createThrottle.addActionListener(new ClickDetector());
    quit.addActionListener(new ClickDetector());
    //window stuff
    setSize(170,135);
    show();
    try
    br = new BufferedReader(new FileReader("C:\\Storage.txt"));
    catch (FileNotFoundException ex)
    System.out.println ("File Not Found!");
    try
    line = br.readLine();
    while (line != null)
    st = new StringTokenizer(line, " ");
    tempTop = Integer.parseInt(st.nextToken());
    tempPosition = Integer.parseInt(st.nextToken());
    myThrottle = new Throttle(tempTop, tempPosition);
    arrThrottles.add(myThrottle);
    line = br.readLine();
    catch(Exception e)
    System.out.println("IO Exception!!!");
    System.exit(0);
    private class ClickDetector implements ActionListener
    public void actionPerformed(ActionEvent event)
    try
    if (event.getSource() == numOfThrottles)
    JOptionPane.showMessageDialog(null, "Number of Throttles is..." + myThrottle.getNumOfThrottles());
    if (event.getSource() == shiftThrottle)
    String shift = JOptionPane.showInputDialog("Please Choose a Throttle from 0 to " + (arrThrottles.size() - 1));
    whatToShift = Integer.parseInt(shift);
    System.out.println ("whatToShift = " + whatToShift);
    // Need help here
    if (event.getSource() == createThrottle)
    String inTop = JOptionPane.showInputDialog("Please Enter Top");
    tempTop = Integer.parseInt(inTop);
    String inPosition = JOptionPane.showInputDialog("Please Enter Position");
    tempPosition = Integer.parseInt(inPosition);
    myThrottle = new Throttle(tempTop, tempPosition);
    arrThrottles.add(myThrottle);
    JOptionPane.showMessageDialog(null, "The Throttle has been created");
    if (event.getSource() == quit)
    System.out.println ("you clicked quit");
    catch (Exception e)
    JOptionPane.showMessageDialog(null, "No Numbers inputted!");
    Any insite/suggestions on what to do? Thank You.
    Joe

    Hi,
    I have a question addition to this same question.
    If you have an object and there are 10 different objects with in the object ..
    tempTop = Integer.parseInt(st.nextToken());
    tempPosition = Integer.parseInt(st.nextToken());
    tempBottom = 10;
    Is this how you access( from the same example) each object value
    strTop= (Throttle)arrThrottles.get(i).tempTop;
    strPos= (Throttle)arrThrottles.get(i).tempPosition;
    strB= (Throttle)arrThrottles.get(i).tempBottom;
    ----I AM USING ARRAYS in a JAVABEAN
    Class test {
    public objectTEMP t[] = null;
    public void initialize(val1,al2) {
         t = redim(t,10,false); //To set the length of the array to 10
    public class T {
    String s1 = null;
    String s2 = null;
    int i1 = null;
    public void setS1(String inVal) {
              s1=inVal;
    public void setS2(String inVal) {
         s2=inVal;
    public void setI1(int inVal) {
         i1=inVal;
    public String getS1() {
              return s1;
    public String getS2() {
              return s2;
    public String getI1() {
              return i1;
    for (int i=0; i<t.length;i++) {
    System.out.println("t"+i+t.getS1());
    t.setS1("SOMESTRING");
    System.out.println("t"+i+t.getS1());
    Any use the setter and getter method from JSP to update or get the information.
    I want to change this to ArrayList as they are fast and they have resizing ability.
    How to I implement this in ARRAYLIST.
    Thanks a bunch

  • I need help with my for loop in this array

    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    import javax.swing.JOptionPane;
    public class Runner
        public static void main (String[] args)
            String timeStr;
            int time, again, optiStr;
            Inbound[] in = new Inbound[25];
             in[0]=new Inbound ("",0,"On Time num0");
             in[1]=new Inbound ("",2,"On Time num1");
             in[2]=new Inbound ("",3,"Delayed num2");
             in[3]=new Inbound ("",4,"On Time");
             in[4]=new Inbound ("",5,"On Time");
             in[5]=new Inbound ("",6,"Canceled");
             in[6]=new Inbound ("",1,"Canceled num6");
             in[7]=new Inbound ("",8,"On Time");
             in[8]=new Inbound ("",9,"Delayed");
             in[9]=new Inbound ("",10,"On Time");
             in[10]=new Inbound ("",11,"Delayed");
             in[11]=new Inbound ("",12,"On Time");
             in[12]=new Inbound ("",13,"Delayed");
             in[13]=new Inbound ("",14,"On Time");
             in[14]=new Inbound ("",15,"On Time");
             in[15]=new Inbound ("",16,"On Time");
             in[16]=new Inbound ("",17,"Canceled");
             in[17]=new Inbound ("",18,"On Time");
             in[18]=new Inbound ("",19,"On Time");
             in[19]=new Inbound ("",20,"Canceled");
             in[20]=new Inbound ("",21,"On Time");
             in[21]=new Inbound ("",22,"Delayed");
             in[22]=new Inbound ("",23,"On Time");
             in[23]=new Inbound ("",24,"Cancled");
             in[24]=new Inbound ("",7,"On Time num24");
            do{
                timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
                time = Integer.parseInt(timeStr);
                if (time<=0 || time>24)
                 JOptionPane.showMessageDialog (null, "Error");
                 optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
                if (optiStr==JOptionPane.YES_OPTION)
    //(ok this is the for loop i am talking about )
                    for (int index = 0; index < in.length; index++)
                      if ( time == Inbound.getTime())
                   JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    //               else JOptionPane.showMessageDialog (null, "else");
                }//temp return else if failed to find time asked for
    //             else
    //               if (optiStr==JOptionPane.CANCEL_OPTION)
    //                 JOptionPane.showMessageDialog(null,"Canceled");
    //              else
    //                {Outbound.run();
    //                JOptionPane.showMessageDialog (null, "outbound");}//temp
                  again=JOptionPane.showConfirmDialog(null, "Try again?");
            while (again==JOptionPane.YES_OPTION);
    }any help would be greatly appriciated.

    rumble14 wrote:
    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    >//(ok this is the for loop i am talking about )
    for (int index = 0; index < in.length; index++)
    if ( time == Inbound.getTime())
    JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
    Edited by: darb on Mar 26, 2008 11:12 AM

  • New to Java and need help with this program..please!

    I'd really appreciate any helpful comments about this program assignment that I have to turn in a week from Friday. I'm taking a class one night a week and completely new to Java. I'd ask my professor for help, but we can't call him during the week and he never answers e-mails. He didn't tell us how to call from other classes yet, and I just can't get the darn thing to do what I want it to do!
    The assignment requirements are:
    1. Change a card game application that draws two cards
    and the higher card wins, to a Blackjack application
    2. Include a new class called Hand
    3. The Hand class should record the number of draws
    4. The application should prompt for a number of draws
    5. The game is played against the Dealer
    6. The dealer always draws a card if the dealer's hand total is <= 17
    7. Prompt the player after each hand if he wants to quit
    8. Display the total games won by the dealer and total and the total games wond by the player after each hand
    9. Display all of the dealer's and player's cards at the
    end of each hand
    10. Player has the option of drawing an additional card after the first two cards
    11. The Ace can have a value of 11 or 1
    (Even though it's not called for in the requirements, I would like to be able to let the Ace have a value of 1 or an 11)
    The following is my code with some comments about a few things that are driving me nuts:
    import java.util.*;
    import javax.swing.*;
    import java.text.*;
    public class CardDeck
    public CardDeck()
    deck = new Card[52];
    fill();
    shuffle();
    public void fill()
    int i;
    int j;
    for (i = 1; i <= 13; i++)
    for (j = 1; j <= 4; j++)
    deck[4 * (i - 1) + j - 1] = new Card(i, j);
    cards = 52;
    public void shuffle()
    int next;
    for (next = 0; next < cards - 1; next++)
    int rand = (int)(Math.random()*(next+1));
    Card temp = deck[next];
    deck[next] = deck[rand];
    deck[rand] = temp;
    public final Card draw()
    if (cards == 0)
    return null;
    cards--;
    return deck[cards];
    public int changeValue()
    int val = 0;
    boolean ace = false;
    int cds;
    for (int i = 0; i < cards; i++)
    if (cardValue > 10)
    cardValue = 10;
    if (cardValue ==1)     {
    ace = true;
    val = val + cardValue;
    if ( ace = true && val + 10 <= 21 )
    val = val + 10;
    return val;
    public static void main(String[] args)
    CardDeck d = new CardDeck();
    int x = 3;
    int i;
    int wins = 1;
    int playerTotal = 1;
    do {
    Card dealer = (d.draw());
    /**I've tried everything I can think of to call the ChangeValue() method after I draw the card, but nothing is working for me.**/
    System.out.println("Dealer draws: " + dealer);
    do {
    dealer = (d.draw());
    System.out.println(" " + dealer);
    }while (dealer.rank() <= 17);
    Card mine = d.draw();
    System.out.println("\t\t\t\t Player draws: "
    + mine);
    mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
    do{
    String input = JOptionPane.showInputDialog
    ("Would you like a card? ");
    if(input.equalsIgnoreCase("yes"))
         mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
         playerTotal++;
         else if(input.equalsIgnoreCase("no"))
    System.out.println("\t\t\t\t Player stands");
         else
    System.out.println("\t\tInvalid input.
    Please try again.");
    I don't know how to go about making and calling a method or class that will combine the total cards delt to the player and the total cards delt to the dealer. The rank() method only seems to give me the last cards drawn to compare with when I try to do the tests.**/
    if ((dealer.rank() > mine.rank())
    && (dealer.rank() <= 21)
    || (mine.rank() > 21)
    && (dealer.rank() < 22)
    || ((dealer.rank() == 21)
    && (mine.rank() == 21))
    || ((mine.rank() > 21)
    && (dealer.rank() <= 21)))
    System.out.println("Dealer wins");
    wins++;
         else
    System.out.println("I win!");
    break;
    } while (playerTotal <= 1);
    String stop = JOptionPane.showInputDialog
    ("Would you like to play again? ");
    if (stop.equalsIgnoreCase("no"))
    break;
    if (rounds == 5)
    System.out.println("Player wins " +
    (CardDeck.rounds - wins) + "rounds");
    } while (rounds <= 5);
    private Card[] deck;
    private int cards;
    public static int rounds = 1;
    public int cardValue;
    /**When I try to compile this nested class, I get an error message saying I need a brace here and at the end of the program. I don't know if any of this code would work because I've tried adding braces and still can't compile it.**/
    class Hand()
    static int r = 1;
    public Hand() { CardDeck.rounds = r; }
    public int getRounds() { return r++; }
    final class Card
    public static final int ACE = 1;
    public static final int JACK = 11;
    public static final int QUEEN = 12;
    public static final int KING = 13;
    public static final int CLUBS = 1;
    public static final int DIAMONDS = 2;
    public static final int HEARTS = 3;
    public static final int SPADES = 4;
    public Card(int v, int s)
    value = v;
    suit = s;
    public int getValue() { return value; }
    public int getSuit() { return suit;  }
    public int rank()
    if (value == 1)
    return 4 * 13 + suit;
    else
    return 4 * (value - 1) + suit;
    /**This works, but I'm confused. How is this method called? Does it call itself?**/
    public String toString()
    String v;
    String s;
    if (value == ACE)
    v = "Ace";
    else if (value == JACK)
    v = "Jack";
    else if (value == QUEEN)
    v = "Queen";
    else if (value == KING)
    v = "King";
    else
    v = String.valueOf(value);
    if (suit == DIAMONDS)
    s = "Diamonds";
    else if (suit == HEARTS)
    s = "Hearts";
    else if (suit == SPADES)
    s = "Spades";
    else
    s = "Clubs";
    return v + " of " + s;
    private int value; //Value is an integer, so how can a
    private int suit; //string be assigned to an integer?
    }

    Thank you so much for offering to help me with this Jamie! When I tried to call change value using:
    Card dealer = (d.changeValue());
    I get an error message saying:
    Incompatible types found: int
    required: Card
    I had my weekly class last night and the professor cleared up a few things for me, but I've not had time to make all of the necessary changes. I did find out how toString worked, so that's one question out of the way, and he gave us a lot of information for adding another class to generate random numbers.
    Again, thank you so much. I really want to learn this but I'm feeling so stupid right now. Any help you can give me about the above error message would be appreciated.

Maybe you are looking for

  • Access to On-Prem Data Source Forbidden

    In Power BI preview site... Successfully downloaded the gateway and created a connection to an on-prem SQL database.  Data source in Power BI admin says "ready".  I can see tables and views.  Works fine. I click on the data source in power BI and cut

  • Download Alv into excel sheet according to variant fields

    Hi All, I have more than 100 fields in the ALV report, now i want to download the report according to the fields are choosen in the variant. I am getting all the fields in excel sheet but i need some fileds that is selected in the variant. Thanks in

  • Skype Number subscription was cancelled and will e...

    hi, My skype account notes ---- Your Skype Number subscription was cancelled. It will expire on April 22, 2013. There is a link for Get a new Skype Number . But I wanna contiune using the old skype number. how to renew the subscription and skype numb

  • Realtek Audio v 6.0.1.7040 - 5.10.0.7040 - gga109ww

    Hi friends, I m T430 and Win8.1 x64 and after installed this update "Realtek Audio v 6.0.1.7040 - 5.10.0.7040 - gga109ww" I do not see the Dolby Advanced Audio v2 anymore.! I tried to installed Dolby Advanced Audio v2 manually but it seems not to be

  • I can't get wifi in my ipod touch 3g

    Dear all, I have a problem with the surfing through wifi. The device shows the signal icon completly, but I can't surf in internet. I have the rigth pass and the ipo shows a message like "Safari cannot open the page because it is not conectedto the i