jcombo getSelected in drag and drop - java

hi i wanted to ask how to use combo boxes because i need to change a check box caption.
i got nokia,samsung on the drop down. and then 3 check boxes. so if i clicked on nokia, i want to see 3 nokia chkboxes. and so on if samsung. i know that this is simple, but its hard to know the methods. i'm a visual basic user, so its kinda hard. pls make it simple, i am using DnD. also i used action perform.
here's my code for now. but its not working, it only shows samsung chk boxes
private void
phoneComboActionPerformed(java.awt.event.ActionEvent evt) {
String Nokia;
String Samsung;
Nokia = (String)phoneCombo.getSelectedItem();
checkBox1.setText("Nokia E71");
checkBox2.setText("Nokia E72");
checkBox3.setText("Nokia E79");
Samsung=(String)phoneCombo.getSelectedItem();
checkBox1.setText("Samsung D780");
checkBox2.setText("Samsung D880");
checkBox3.setText("Samsung F480");
} `

put a condition
if phoneCombo.getSelectedItem("Nokia) then // put your code here

Related

There are some method to use toggle buttons without need to create a lot of conditions

I'm developing a program in java for admin orders in a restaurant.
I have a screen like this.
Frame for admin orders.
I want to select any button from left and any button from right and clic in button "Agregar" later.
I'm thinking to do a method with a lot of conditions if and else if, for example.
if(buttonCombo1.isSelected() and buttonNumber1.isSelected()){
//Doing something
}else if(buttonCombo1.isSelected() and buttonNumber2.isSelected()){
//Doing something
}
I would have to do a lot of conditions, and I have no idea do otherwise.
If you can help me to find another way for do It, I would be grateful.
Note: I apologize for my bad english. I'm learning yet.
Thanks so much.
I don't remember if you can group simple buttons. But you can define a click function in each button to change the value of button in a Bollean Array (with lenght equals amount of button.)
In this case, you will have acess a boolean value directly for a index.

using DefaultListMethod to make custom buttons via showOptionDialog

I am just learning AWT / Swift / JavaFx recently and I feel like I have learned a lot but have barely scratched the surface. There might be a much easier way to do this BUT, I am trying to make a GUI button in eclipse that calculates the distance between two objects that the user creates. Lets call them Robots for now. So, I have one button that allows the user to create the Robots and it stores them in a DefaultListModel (listModel) and displays them in a Jlist (list) below the buttons. When the user then clicks on a robot, another button becomes actice and allows them to calculate the distance between them (one of the parameters of the robots is their location on a grid). I have all that worked out but my problem is that I am trying to make it to where they have to select two different Robots. At first I thought I could let them select two Robots and then make the computeDistance button becomes active, but I am not really sure how to do that because the only way I can select more than one object in the JList is to cntrl click and I don't want the user to have to know that trick.
My next idea was to allow the user to have one Robot selected and then give them a popup window displaying the other Robots and have them select one. Via showOptionsDialog, I have discovered how to make a custom JOptionPane, so I thought, why not make them buttons (probably will look awful, but I don't know how to make anything other than JOptionPane.showXxx at this point (like I said, only skin deep so far). Have tried consulting the javadocs, but right now that is a LOTTT to take in and have read a decent amount, I thought.
Ok, sorry if this is long, but is there a way, using my DefaultListMethod to make custom buttons? I tried a bunch of ways by creating Object[] options = {list.elements()}; etc but that doesn't work. Any help would be much appreciated!

Nesting a button group within a button group in android?

i am fairly experienced at coding in java but i am just learning to build graphical user interfaces in android environment. I have searched alot for the answer to this question but i wonder if im not searching for the right thing?
I want to be able to choose between 2 radio buttons, and if the first of these radio buttons is chosen then a group of 2 more radio buttons should be chosen from. Its hard to explain exactly what i mean so i hope this helps.....
Choice One
1.a choice one a
1.b choice one b
Choice Two
So, if 'choice one' is picked then the user MUST pick from choices 1a OR 1b, whereas if the user picks 'choice two' then the sub options (1a and 1b) are not even available (greyed out i suppose).
I thought i could just nest one RadioGroup inside another, but it doesnt seem to work this way.
If anybody can help me here id be really grateful.
you could create a popup and fill the data on OnCLickListener and then display it.
Have you trying to use show() and hide() for radio button? maybe using a boolean for the parameter show() and hide()

Operation translation from jCombobox in Java to Spinner in Eclipse

Asking a follow-up question here after solving some other problems I was having.
Essentially, I'm translating a working program from Java into Eclipse for development of an android app. I've whittled down the problems to a single block of code. In Java, it looked like this:
private void shapeDropDownActionPerformed(java.awt.event.ActionEvent evt) {
if(shapeDropDown.getSelectedIndex()==1)
diameterBox.setText("0");
if(shapeDropDown.getSelectedIndex()==1)
diameterBox.setEditable(false);
if(shapeDropDown.getSelectedIndex()==2)
widthBox.setText("0");
if(shapeDropDown.getSelectedIndex()==2)
widthBox.setEditable(false);
if(shapeDropDown.getSelectedIndex()==2)
heightBox.setText("0");
if(shapeDropDown.getSelectedIndex()==2)
heightBox.setEditable(false);}
Basically, if the user chooses a rectangle over a cylinder, the diameter input is set to "0" (so it is an integer) and is set to not editable. Or, if the user chooses cylinder, the height & width inputs were set to "0" and not editable.
However, I'm having difficulty with this method in Eclipse. Could you please show me how to implement this method in Eclipse? This is what I've got so far that is not working, thus making the entire app malfunction:
//Blank out the appropriate blanks:
private void setOnItemSelectedListener (new onItemSelectedListener() {
if (shapeDD.equals("Rectangle"))
txtDiameter.setText("0");
if (shapeDD.equals("Rectangle"))
txtDiameter.setEnabled(false);
if (shapeDD.equals("Cylinder"))
txtWidth.setEnabled(false);
if (shapeDD.equals("Cylinder"))
txtWidth.setText("0");
if (shapeDD.equals("Cylinder"))
txtHeight.setEnabled(false);
if (shapeDD.equals("Cylinder"))
txtHeight.setEnabled(false);
});
A secondary issue I'm having is with resetting the spinner once I'm done with it. In Java, it's simply:
jCombobox.setSelectedIndex(0).
What is the equivalent method in Eclipse for a Spinner?
I can answer to your second question: the equivalent method for the spinner is setSelection(index), for references see http://developer.android.com/reference/android/widget/AbsSpinner.html#setSelection(int)

Java dragging image and dropping on the point

I want to create interactive drag and drop. What I mean is that i have 10 slots and 5 buttons, I want to make that user can drag and drop a button on the slot he wants to. I made it with ComboBox and it works fine but I want to make it more interactive. Is it possible in an easy way or I need a hard code? If so any good help on coding would be appreciated.
//Edit. I made it with ComboBox using setLocation(); with saved every slot position
//Edit again with photo:
You can see several example of Drag and drop in Java here and decide which kind of drag and drop you would like to do:
http://docs.oracle.com/javase/tutorial/uiswing/examples/dnd/

Categories