Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners JComboBox Event Handling
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vandana
JComboBox Event Handling
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners



Advertisement
View Answers

July 1, 2009 at 5:51 PM


Hi Friend,

Try the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Compare extends JFrame implements ItemListener
{
JComboBox combo,lcombo;
JTextField number;

public Compare()
{
setLayout(null);
String a[]={"Select","First","Second"};

combo=new JComboBox(a);combo.setBounds(50,50,100,20);
combo.addItemListener(this);
add(combo);

lcombo=new JComboBox();
lcombo.addItemListener(this);lcombo.setEnabled(false);
add(lcombo);lcombo.setBounds(50,100,100,20);

number=new JTextField(5);number.setEditable(false);
add(number);number.setBounds(50,150,100,20);
setSize(300,300);
}

public void itemStateChanged(ItemEvent e) {
String b[]={"Select","One","Two"};
String c[]={"Select","Three","Four"};
if(e.getSource() == combo) {
if(combo.getSelectedItem().equals("Select"))
{
lcombo.setEnabled(false);
number.setEditable(false);
}
else if(combo.getSelectedItem().equals("First"))
{

lcombo.setEnabled(true);
number.setEditable(true);

for(int i=0;i<b.length;i++)
{
lcombo.removeItem(b[i]);
lcombo.removeItem(c[i]);

lcombo.addItem(b[i]);

}

}

else if(combo.getSelectedItem().equals("Second"))
{

lcombo.setEnabled(true);
number.setEditable(true);

for(int i=0;i<c.length;i++)
{
lcombo.removeItem(c[i]);
lcombo.removeItem(b[i]);

System.out.println(c[i]);
lcombo.addItem(c[i]);

}
}
}
else if(e.getSource() == lcombo) {
if(lcombo.getSelectedItem().equals("Select"))
{
number.setText("");number.setEditable(false);
}
else if(lcombo.getSelectedItem().equals("One"))
{
number.setText("1");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Two"))
{
number.setText("2");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Three"))
{


number.setText("3");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Four"))
{
number.setText("4");number.setEditable(true);
}
}
}
public static void main(String args[])
{
(new Compare()).setVisible(true);
}
}
Thanks


Related Tutorials/Questions & Answers:
JComboBox Event Handling - Java Beginners
JComboBox Event Handling  Hi, I have problem with event handling here.There are Two JComboBox and a JTextField.When I select an item in first... Compare extends JFrame implements ItemListener { JComboBox combo,lcombo
event handling
event handling  diff btwn event handling in ASP.net and in HTML
Advertisements
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
Event handling on an image
Event handling on an image  I want to divide an image into frames and want to do event handling on the frames
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
javascript event handling examples
javascript event handling examples  javascript event handling examples   var handleClick = function(e) { // Older IEs set the `event... event listeners. document.attachEvent('onclick', handleClick); } else
Event handling - Java Beginners
Event handling  Hi, This is a similar kind of question i had asked before, with a little difference. Two JCombobox and a JtextField. When I select... ItemListener { JComboBox combo,lcombo; JTextField number; public Compare
event handling in jsp
event handling in jsp  i am developing a web application. i am getting a problem in event handing in jsp. in this web application there is a file... to generate event on each row of retrieved row from the database
Java event handling
Java event handling  What event results from the clicking of a button
Java event handling
Java event handling  What is the purpose of the enableEvents() method
KEY EVENT HANDLING
KEY EVENT HANDLING  I am trying to write a program that receives every key stroke even when the window is not active or it's minimized. Is there anyway to do
Event Handling - Java Beginners
Event Handling  import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Calculator extends JFrame { JLabel lblNumber=new JLabel("Number"); JLabel lblSquareRoot=new JLabel("Square Root
Event Handling In Java
Event Handling In Java In this section you will learn about how to handle.... In Java event handling may comprised the following four classes : Event Sources... that happens and your application behaves according to that event. For example
Understanding the jQuery event handling mechanism
Understanding the jQuery event handling mechanism... handling mechanism First of all , you need to know -What is an event... these event. Event handling methods basically associates an event with 
What are events? Explain how Event handling in Java?
What are events? Explain how Event handling in Java?  What are events? Explain how Event handling in Java?   Hi, The Events..., and introduces us to AWT event handling. For Details about Event Handling in Java
how to add audio clip in swings with event handling
how to add audio clip in swings with event handling  hello dear, i wanna to play audio clip in java program in JFrame in swings by event handling ,it should be like when i click on a button , audio clip should play , plz tell me
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jcombobox
jcombobox  hi i have developed a form and i have jcombobox in which data is retrieved from ms access but the problem is that if we pressed the down key the last 5 data are not showed only the other data can be pressed
JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you
JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from... change the selected item in JComboBox. Thank you.   import java.sql....); JLabel lab=new JLabel("Select"); final JComboBox combo=new JComboBox
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth devices and i also made a refresh button.when i click on the refresh button i
J2ME Event Handling Example
J2ME Event Handling Example       In J2ME programming language, Event Handling are used to handle certain... event like selecting an item from a list And low level events like pressing a key
Handling Key Press Event in Java
Handling Key Press Event in Java   ... the handling key press event in java. Key Press is the event is generated when you press any key to the specific component. This event is performed by the KeyListener
how to open a web page using proxy in java and handling button event in that web page..?
how to open a web page using proxy in java and handling button event in that web page..?  Sir, what i need is a code which uses proxy address and opens a web page i.e for example and then clicks a "yes" button in that page
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
jComboBox with database
jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two comboboxes, the third combobox automatically retrieve data of a particular column from
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
Handling Mouse Clicks in Java
Handling Mouse Clicks in Java       Introduction In this section, you will learn about handling the mouse click event in the awt application. This program simply implements
Changing JLabel with a jcombobox - Java Beginners
listener event of JComboBox put JLabel.setText("Put yourtext here
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox and when click onto the "search" button, the selected category (example "new york") all the each new york picture and detail will be seen. But how to grab
Advertisements
 

 

 

DMCA.com