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 6 of 6

Thread: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Location
    Dublin, IRE
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    Can anyone help me with a minor bump? I'm using NetBeans and I'm doing an assignment in a JPanel/JFrame application. I need to know how to make a letter necessary for a log in page.
    For example: to enter the page, you've to enter your I.D number; x12345678.
    I'd like to know how to enter this in an if statement

    Here's a line of code from a button action when clicked to show an error message:
    private void submitBtnClicked(java.awt.event.ActionEvent evt) {                                  
           if(nameTf.getText().length() == 0){
                JOptionPane.showMessageDialog(null, "Invalid Name");
            }
     
            if(studentTf.getText().length() == 0){
                JOptionPane.showMessageDialog(null, "Invalid Student Number");
            }
        }

    Can anyone help me, please?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    how to enter this in an if statement
    Are you asking how to compare the contents of a String variable to a String literal?
    aStrVar.equals("A literal")
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Location
    Dublin, IRE
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    I have a JTextField called studentTf();
    What I am looking for is an if statement to make the letter 'x' necessary inside that JTextField


    Also, how would I make a JButton submit all of the content of that and open up a new JPanel page, showing the name and number of the student?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    The text field has a method to get the data out of the textfield into a String.
    The String class has methods to test the contents of the String.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Location
    Dublin, IRE
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    Could you show me an example? I've only started doing JFrames and Interfaces in college, and I'm a n00b at it haha

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Help with NetBeans App using JPanel/JFrame with JButton (if statements)

    First read the API doc for the text field class and find the method to get the text out of it.
    Then read the API doc for the String class and find a method that will find an occurrence of the specified substring.

    This task has nothing to do with JFrames or interfaces.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Adding JPanel using Jbutton, Expanding JFrame as needed.
    By ShadowMystic in forum AWT / Java Swing
    Replies: 1
    Last Post: February 24th, 2013, 09:13 AM
  2. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  3. netbeans JTable Jbutton
    By Mr.President in forum AWT / Java Swing
    Replies: 6
    Last Post: July 19th, 2010, 09:37 AM
  4. JButton on JPanel
    By JavaLearner in forum AWT / Java Swing
    Replies: 4
    Last Post: March 26th, 2010, 08:46 AM
  5. need help with JButton and switch statements
    By jjoubert in forum AWT / Java Swing
    Replies: 5
    Last Post: October 28th, 2009, 10:13 AM

Tags for this Thread