Results 1 to 5 of 5
  1. #1
    mildog1234 is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Question Button Problems D:

    Hello everyone,

    I am new to programming and I would like to know how can I make my buttons do what they say they do in my program?

    I have a copied version down below and I would like to make it so the "Start" button goes to the next and the other buttons do as they say...

    I have been all like and and I need help.


    Code:
    Java Code:
     import java.awt.Component;
    
    import javax.swing.Icon;
    import javax.swing.JOptionPane;
    
    
    public class GUI {
    
    	private static final Icon Castle = null;
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Object[] options = {"Help",
                    "Cancel",
                    "Start"};
    Component frame = null;
    Icon CastleRaid = null;
    JOptionPane.showOptionDialog(frame,
    "Castle Raid ",
    "Start Menu",
    JOptionPane.YES_NO_CANCEL_OPTION,
    JOptionPane.QUESTION_MESSAGE,
    CastleRaid,
    options,
    options[2]);
    
    
    Object[] possibilities = {"Human", "Elf", "Dwarf"};
    String s = (String)JOptionPane.showInputDialog(
                        frame,
                        "What is your race?",
                        "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE,
                        null, possibilities,
                        "ham");
    
    String s1 = (String)JOptionPane.showInputDialog(
                        frame,
                        "What is your name?",
                        "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE,
                        null, null,
                        "INSERT NAME");
    
    	}
    
    }
    Feel free to copy to try to make edits but don't use for your own game.

    You can also edit the code and post in a comment for me to use...

    Thank you!

    -Mildog
    Last edited by mildog1234; 11-07-2013 at 10:15 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Button Problems D:

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

    Where are there any buttons defined in the posted code?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mildog1234 is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Re: Button Problems D:

    Sorry about the code thing (account made not even 10 mins ago.) You have to download it trust me if you run it buttons in dialog boxes come up.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Button Problems D:

    The buttons on the dialog boxes talk to the dialog's code, not your code. When the user presses one of the buttons, the dialog code decides what data to return and returns that data in a String or int to the caller. It is up to the caller to look at the String or int that was returned to be able to determine what the user did when the dialog was shown.
    Read the API doc for the methods the code uses to see what is returned by the dialog code.
    Last edited by Norm; 11-07-2013 at 10:23 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    parranoia is offline Member
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Default Re: Button Problems D:

    What exactly have you had problems with? Specifically what do you want the program to do?

Similar Threads

  1. Button and ActionListner problems
    By reader34 in forum Java Applets
    Replies: 2
    Last Post: 04-28-2014, 11:52 AM
  2. Subframe, clear and exit button problems
    By dhiy0 in forum New To Java
    Replies: 1
    Last Post: 02-17-2013, 08:09 PM
  3. Replies: 7
    Last Post: 08-06-2011, 03:39 AM
  4. Make a button class that uses your button image.
    By eLancaster in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 11:32 AM
  5. Adding a sqrt button and percentage button to a calculator
    By Josie_Taylor in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 01:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •