Simple Programming (27) Create a form drop-down list

Source: Internet
Author: User

Create a form with two drop-down lists, one for the Academy drop-down list, and one for the professional drop-down list,

When the user is asked to select a department, the options in the Professional drop-down list are updated accordingly.

Software Institute: Software development, software testing, network engineering

Foreign Language Institute: English, Japanese, French

School of Management: Business Administration, accounting, marketing

<span style= "FONT-SIZE:24PX;" >import java.awt.container;import java.awt.dimension;import Java.awt.flowlayout;import java.awt.Toolkit;import Java.awt.event.containerevent;import Java.awt.event.itemevent;import Java.awt.event.itemlistener;import  Javax.swing.jcombobox;import Javax.swing.jframe;import Javax.swing.jlabel;public class Zuoye2 extends JFrame{private JComboBox xyjcombobox,zyjcombobox;private String xyname [] ={"Software Academy", "Foreign Language Academy", "School of Management"}; Private String Zyname [] ={{"Software development", "Software Test", "Network Engineering"},{"English", "Japanese", "French"},{"Business Administration", "Accounting", "Marketing"};p ublic Zuoye2 () {Toolkit Toolkit = Toolkit.getdefaulttoolkit ();D imension Dimension = Toolkit.getscreensize (); SetBounds (DIMENSION.WIDTH/4,     DIMENSION.HEIGHT/4,DIMENSION.WIDTH/4, DIMENSION.HEIGHT/4); Setdefaultcloseoperation (JFrame.EXIT_ON_CLOSE); Xyjcombobox=new JComboBox (xyname); Zyjcombobox=new JComboBox (zyname[0]); Container Container = This.getcontentpane (); Container.setlayout (new FlowLayout ()); Container.add (New JLabel ("College:")); Container.Add (Xyjcombobox); Container.add (New JLabel ("Professional:")); Container.add (Zyjcombobox); Xyjcombobox.additemlistener (new ItemListener () {public void itemstatechanged (ItemEvent arg0) {zyjcombobox.removeallitems (); int index= Xyjcombobox.getselectedindex (); for (int i=0;i<zyname[index].length;i++) {Zyjcombobox.additem (ZyName[index][i]) ;}}}); SetVisible (TRUE);} public static void Main (string[] args) {zuoye2 demo = new Zuoye2 ();}} </span>

Simple Programming (27) Create a form drop-down list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.