To get through this tutorial, you must already be able to create a basic form with 3 or 4 radio buttons on it. We are going to go over making and using these buttons in a functional example. To start, I create a project selecting Java Application and then the Next button. I rename my application to “RadioButtons”, you may name it whatever you want to, I then deselect (uncheck) the “Create Main Class” option, followed by Finish.
- Right Click on Source Packages and New -> Java Package, I name this radiobuttons.
- Right Click radiobuttons (if you have named it the same as I have) -> New -> JFrame Form, which I name RadioButtons, and click finish.
- From the Right hand side (maybe different for you), drag Button Group anywhere in your square panel and drop it (you won’t see any changes here).
- Now place your radio buttons, using the Radio Button (next to your Button Group). I place four for this example. I then shift-click (to select all of them).
- Right click your selection -> Select Properties. This step is where you group them together. When you look at the properties, there is an option for button Grouping (seen below). This will group them for our purposes here, select your buttonGroup (that was created in step 3). Note: If you don’t see a selection, you can go back to 3 now and carry out that step
- At this stage, if you were to click “Play” or Run -> Main Project, you will see the radio buttons in a GUI that are grouped (allowing only 1 of the 4 to be selected at a time).
- Now, to put these radio buttons to use, we will add a button, with a click listener and a text area. (Just drag and drop from the right hand group of objects).
- To add the click listener to the button, Right Click the button, select Properties. At the top of the pop up dialogue, select events -> scroll down to mouseClicked and select the … on the right hand side. This will take you to the picture below, where I named my event and selected Ok to close out dialogues.
- This will take you into the code where you can create your code to do what you want it to do. In this example, I am simply setting the text box to the value of the radio button that is selected. And here is the corresponding code, below:
- Press Play now.
There are a few things to note. If you are using their text in a calculation, you will need to cast it properly. There is most likely a better way to do this, but for beginner I believe this will get you started. Feel free to comment, as always.
Bubble sorting a Java array is a very good way to get practice with arrays. It shows many techniques and here I will show one. It doesn’t give graphical representation, but it gets the job done. The compiler does a little extra work (as this is designed to be a beginning tutorial and answer to the basic bubble sort algorithm.) The basic concept behind a bubble sort is that we test each digit of the array once, swapping (hence moving) the higher digit to the right.we will do this one time for every digit in the array. The final result is a sorted array ascending.
Lets look at an array 2, 3, 1. It starts with 2, and tests it against 3. If 2 is greater than three it swaps them, but 2 isn’t greater… we just move on. It then tests 3 against 1, which is higher (hence swapping the 3 and 1). The resulting array is 2, 1, 3. We do this one more time, resulting in 1, 2, 3. Here is the code:
In plain English, the above example calls out a swap routine, sending the routine the array and the value which is going to get swapped with the one to the right of it in the array; it is also notable to see that we are returning the full array with the swapped values. Here is the function to swap, and therefore bubble sorting and that is:
And this is added directly below the main function. You can see that it also closes out the class. For added verification, you may want to print the array, but I will leave that for another day. In the next issue of Java programming, I will go over a better sorting routine that will not require this many steps.
Technorati Tags: Java
I really just want to release right now. In a couple hours, I will be teaching class and grading papers, and until then I want to write. Sometimes I just get into this mood. This writing mood can last for days, weeks and rarely months. It is a way for me to just release. I may not have the time to write, but when I do, I will blog it. The good thing about my paper, is it rarely talks back, it never laughs at me, and rarely does me wrong in general.
So many employers are laying off so many people these days that I guess I should just be sleepless all of the time. My employer announced huge layoffs this month (10,000 people), so how do I get through nights successfully. The short answer is Benadryl, though that only goes so far. For me, it works if I just stare at the back of my eyelids and shrug off any thoughts that come into my head about future layoffs. I felt really good though, when recently, I submitted my resume to a head hunter (who knows how he got my resume). So here are some tips that will you help you get through the nights leading up to getting laid off.
- I really wasn’t joking about Benadryl. I have massive allergies here in the mid-west and I must say that it helps me tremendously when I just can’t sleep. I figured out that it helped me sleep because when I went to the allergist, I found that I was allergic to my environment. My Allegra has taken over along with a nasal spray to help me get my full nights. The good thing about Benadryl is that it is non-habit forming and a very good short term answer to sleeplessness.
- The world will continue to revolve, evolve, and grow. This includes the economy, and looking at history (since it tends to repeat itself), you can see that we aren’t where we were in the early 80′s now; we aren’t in the depression of the 30′s. In short, the economy will grow and jobs will be created, so hang in there; don’t worry so much about losing one job.
- Plan your future. This you should always be doing, I personally re-evaluate my short term goals on a monthly basis and my long term goals not so often. Short term goals can change, but you should always focus on your long term goals and change these much less often since they are generally harder to achieve. A few years ago I decided to enter school this August, having a bachelors and a masters means that this goal is not mandatory; but since this has been one of my goals, I will continue to focus on this. It goes toward the longer term goals that I have.
- Stay positive. Even if you aren’t feeling positive you should try to reflect positive. If you constantly smile at those around you, they will start smiling back. It is a lot harder to rid a negative seed in any environment. So if you have anything negative to say, do those around you a favor, keep them to yourself. It also helps if you depersonalize any critique, which helps in the academic world.
- Smile. ‘nuf said.
- Smile some more. Possibly until your cheeks hurt.
These are just some of my suggestions if you might be in danger of getting laid off. If it does happen to you, and you lose that job, working for that employer that you love, then remember that there are other employers out there. Plan for a course of action, guide your short term decisions by the larger picture (your long term solutions). After all, that is what your employer is doing.