Hi,

I have checked examples and tutorials but never seem to get a direct answer to a couple of questions. When using a Gui with a JButton (Netbeans)where does the code for the array go in order to be displayed? Here is the code for the array and I just want to click the button and have it display. Where do I put it?(the code) This website has been extremely helpful to me as perhaps I am a slow learner and prefer not to copy and paste but I really want to learn the logic behind the code. Thanks in advance for any help. I do not need help with making the JButton but I do need help in having this display after pressing the button.

lynnajoe

int [] aryNums = new int [6];
        aryNums [0] = 10;
        aryNums [1] = 5;
        aryNums [2] = 6;
        aryNums [3] = 9;
        aryNums [4] = 7;
        aryNums [5] = 3;
        
        Arrays.sort(aryNums);

        int i;
        for (i =0; i <aryNums.length;i++) {
        
        System.out.println("number: " + aryNums[i]);
    }
    
    }

Have You learned about event listeners?
Check out ActionListener at the Java API, that's the class used for getting button clicks.

Hi,

I do know about ActionListeners. It is an easy question and I may sound lost because I tried the code in the Netbeans area where they say to place the code and it doesn't come up at all. The window shows but that's it. I only wanted to ask where it goes and not for code itself. If you see what I am saying. It is a basic question that's all. I wanted someone to explain it to me in plain language and not code.

lynnajoe

As a general rule you don't want to put code of that kind of complexity and context directly into an ActionListener. Best practice is to put it into a method in the appropriate class, then just call that method from a one-line ActionListener

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.