Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Event handling
Expert:vandana
Hi,
This is a similar kind of question i had asked before, with a little difference.
Two JCombobox and a JtextField.
When I select an Item from the first Combo(i.e.,Select,First,Second or Third),the set of items in the second combo should change(i.e.,when "Select" is selected 2nd combo and textfield is disabled,
when "First" is selected 2nd combo should have -[Select,One,Two,Three],
when "Second" is selected 2nd combo should have -[Select,Two,Three],
when "Third" is selected 2nd combo should have -[Select,Three]).
Now when I select One,Two,Three from second combo, the textfield should display 1,2,3 respectively.
I have given my code below in which the 2nd combo changes according to first.But the textfield is displaying nothing.I have commented the part I have problem with.
public class Compare extends JFrame implements ItemListener
{
JComboBox combo,lcombo;
JTextField number;

public Compare()
{
setLayout(null);
String a[]={"Select","First","Second","Third"};
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) {
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);
String b[]={"Select","One","Two","Three"};
lcombo.removeAllItems();
for(int i=0;i<b.length;i++)
{
lcombo.addItem(b[i]);
}
}
else if(combo.getSelectedItem().equals("Second"))
{
lcombo.setEnabled(true);
number.setEditable(true);
String b[]={"Select","Two","Three"};
lcombo.removeAllItems();
for(int i=0;i<b.length;i++)
{
lcombo.addItem(b[i]);
}
}
else if(combo.getSelectedItem().equals("Third"))
{
lcombo.setEnabled(true);
number.setEditable(true);
String b[]={"Select","Three"};
lcombo.removeAllItems();
for(int i=0;i<b.length;i++)
{
lcombo.addItem(b[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);
}
}*/
}
public static void main(String args[])
{
(new Compare()).setVisible(true);
}
}
Answers
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.