Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. Netbeans

Netbeans

Scheduled Pinned Locked Moved Java
question
8 Posts 3 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MallardsReach
    wrote on last edited by
    #1

    Hi I am looking at Netbeans and have in a button control the following code;

      int firstNum, answerNum = 0;
            for (firstNum = 1; firstNum <= 12; firstNum ++)
                answerNum = firstNum \* 2;
                 displayTable.setText(firstNum + " x 2  = " + answerNum);
    

    but in the textarea it only shows 13 x 2 = 24 does the for not work in netbeans? or does it have to be done differently.

    P L 2 Replies Last reply
    0
    • M MallardsReach

      Hi I am looking at Netbeans and have in a button control the following code;

        int firstNum, answerNum = 0;
              for (firstNum = 1; firstNum <= 12; firstNum ++)
                  answerNum = firstNum \* 2;
                   displayTable.setText(firstNum + " x 2  = " + answerNum);
      

      but in the textarea it only shows 13 x 2 = 24 does the for not work in netbeans? or does it have to be done differently.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      That's exactly what I'd expect. When firstNum is 12, answerNum is set to 24. Then the for is executed again, increments firstNum to 13, then the test fails, so it goes on to display what you see. Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      M 1 Reply Last reply
      0
      • P Peter_in_2780

        That's exactly what I'd expect. When firstNum is 12, answerNum is set to 24. Then the for is executed again, increments firstNum to 13, then the test fails, so it goes on to display what you see. Cheers, Peter

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        M Offline
        M Offline
        MallardsReach
        wrote on last edited by
        #3

        Thanks Peter, So my question is how do I get it to display in the Textarea as it does when i run it in the cmd Like this, 1 x 2 = 2 2 x 2 = 4 3 x 2 = 6 etc?

        1 Reply Last reply
        0
        • M MallardsReach

          Hi I am looking at Netbeans and have in a button control the following code;

            int firstNum, answerNum = 0;
                  for (firstNum = 1; firstNum <= 12; firstNum ++)
                      answerNum = firstNum \* 2;
                       displayTable.setText(firstNum + " x 2  = " + answerNum);
          

          but in the textarea it only shows 13 x 2 = 24 does the for not work in netbeans? or does it have to be done differently.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This is not netbeans (which is an IDE), it is Java code. You need to understand the difference. As to your question: You only have a single line being processed in the for loop. You need to put both lines inside a block thus:

          for (firstNum = 1; firstNum <= 12; firstNum ++) {
          answerNum = firstNum * 2;
          displayTable.setText(firstNum + " x 2 = " + answerNum);
          }

          It is good practice to use braces in all repeat blocks, even those with only a single line. It means if you ever add another line to the loop it will always be inside the block.

          M 1 Reply Last reply
          0
          • L Lost User

            This is not netbeans (which is an IDE), it is Java code. You need to understand the difference. As to your question: You only have a single line being processed in the for loop. You need to put both lines inside a block thus:

            for (firstNum = 1; firstNum <= 12; firstNum ++) {
            answerNum = firstNum * 2;
            displayTable.setText(firstNum + " x 2 = " + answerNum);
            }

            It is good practice to use braces in all repeat blocks, even those with only a single line. It means if you ever add another line to the loop it will always be inside the block.

            M Offline
            M Offline
            MallardsReach
            wrote on last edited by
            #5

            Thanks for the reply and advice it now works as I wanted it to. I changed the code as follows using "\n" to give me a new line each time it loops;

            private void twoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
                    int firstNum, answerNum = 0;
                    for (firstNum = 1; firstNum <=12; firstNum ++){
                        answerNum = firstNum \* 2;
                        displayTable.append(firstNum + " x 2  = " + answerNum +"\\n");
            }
            }
            

            In summing up then, Netbeans is developed by Apache and is just an environment to make it easier to develop Java with a windows style, similar to Visual Basic but using Java in the buttons action event. Yes?

            L 1 Reply Last reply
            0
            • M MallardsReach

              Thanks for the reply and advice it now works as I wanted it to. I changed the code as follows using "\n" to give me a new line each time it loops;

              private void twoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
                      int firstNum, answerNum = 0;
                      for (firstNum = 1; firstNum <=12; firstNum ++){
                          answerNum = firstNum \* 2;
                          displayTable.append(firstNum + " x 2  = " + answerNum +"\\n");
              }
              }
              

              In summing up then, Netbeans is developed by Apache and is just an environment to make it easier to develop Java with a windows style, similar to Visual Basic but using Java in the buttons action event. Yes?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              MallardsReach wrote:

              is just an environment to make it easier to develop

              Yes, it is an Integrated Development Environment, similar to Visual Studio, eclipse etc. It is designed to provide editors and debuggers for different languages, and automatic compilation. The actual final product does not need to beWindows style, although it helps if the IDE also has a visual design feature so you can see the layout of your form as you create it. In the old days you had to write all the Windows code by hand, build and run, before you could see what it looked like.

              M 1 Reply Last reply
              0
              • L Lost User

                MallardsReach wrote:

                is just an environment to make it easier to develop

                Yes, it is an Integrated Development Environment, similar to Visual Studio, eclipse etc. It is designed to provide editors and debuggers for different languages, and automatic compilation. The actual final product does not need to beWindows style, although it helps if the IDE also has a visual design feature so you can see the layout of your form as you create it. In the old days you had to write all the Windows code by hand, build and run, before you could see what it looked like.

                M Offline
                M Offline
                MallardsReach
                wrote on last edited by
                #7

                I did write code many years ago, Spectum, Amos and VB but so much has changed although still similar, I'm liking Java just need to get used to the syntax. The IDE does have a design feature so you can set up how it will look when run and then start placing the code in the buttons, checkboxes etc it even has preview design as well. No doubt I will be back at the forum again but in the mean time Thanks for all the help and guidance.

                L 1 Reply Last reply
                0
                • M MallardsReach

                  I did write code many years ago, Spectum, Amos and VB but so much has changed although still similar, I'm liking Java just need to get used to the syntax. The IDE does have a design feature so you can set up how it will look when run and then start placing the code in the buttons, checkboxes etc it even has preview design as well. No doubt I will be back at the forum again but in the mean time Thanks for all the help and guidance.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You're welcome. Maybe you will be answering questions in the future.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups