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



Home Answers Viewqa Java-Beginners JComboBox Event Handling

Have Programming Question? Ask it here!
 
 
 


vandana
JComboBox Event Handling
1 Answer(s)      5 years and a month 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
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
JComboBox with AccessDatabase - Java Beginners
JComboBox with AccessDatabase  Hello Sir I have Created Course... on Student Admission Form when I select Course Name from JComboBox on Student..."); JComboBox combo1=new JComboBox(); JComboBox combo2=new JComboBox
About jcombobox - Swing AWT
About jcombobox  Hi all, I am new to this forum. Can we do auto suggest jcombobox in swing? If yes is there any jar file for that or any code... JTextField tf; private final JComboBox combo = new JComboBox(); private
Link To Database with JComboBox - Java Beginners
course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate with taht course on combobox item changed event. eg when i select MCA the fees
Create a JComboBox Component in Java
of the JComboBox class. The event is generated when you select item from the combo... Create a JComboBox Component in Java       In this section, you will learn about the JComboBox
Event handling in Java AWT
Event handling in Java AWT     ... related to the event handling through this example and used methods through which you can implement the event driven application. This example shows you how to handle
delegation event model
delegation event model  What is delegation event model?   delegation event model In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event
problem with addactionlistener on JComboBox - Java Beginners
[] = { "A", "B", "C"}; JFrame frame = new JFrame(); JComboBox combo = new JComboBox(st); frame.add(combo); ActionListener actionListener = new
Event on Slide bar In Java
Event on Slide bar In Java       Introduction In this section, you will learn about the event handling for a swing component named Slide bar. This section provides a complete
JComboBox Display Problem - Java Beginners
JComboBox Display Problem  I am create one program that contain two...,ItemListener { Container c; JLabel lblstart,lblend; JComboBox cmbstart..."); lblend=new JLabel("End Date"); cmbstart=new JComboBox(); cmbend=new
Event management
Event management   Hi, I want event management application like maintaining email notifications while task creation and update in broader way using spring java
Event in flex
Event in flex  Hi..... can you tell me about that How do you make component participate in event mechanism? Thanks   Ans: Extend EventDispatcher or any subclass of it or implement IEventDispatcher
Flex event
Flex event  Hi.... please tell me about How does Flex event system works? Thanks  Ans: When event are triggered there are three...: In the capturing phase, Flex examines an event target?s ancestors in the display list to see
Event in flex
Event in flex  Hi..... I want to know about What does calling preventDefault() on an event do? How is this enforced? please give me an example for that Thanks   Ans: The methods of the Event class can be used
Flex event
Flex event  hi...... How to capture and event if the component is disabled? please give an example..... Thanks in advance
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
Flex event
Flex event  Hi... please give me the answer with example What is event Bubbling? Thanks in advance  Event Bubbling: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex starts
How to store JComboBox item into database
How to store JComboBox item into database   import... DefaultComboBoxModel(labels); final JPanel TypeTF = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setEditable(false
exception handling
exception handling  explain about exception handling
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter... JFrame(); f.getContentPane().setLayout(null); final JComboBox combo = new
Click event
Click event  hi............ how to put a click event on a particular image, so that it can allow to open another form or allow to display result in tabular form????????/ can u tell me how to do that????????/ using java swings
 

 

 

DMCA.com