展开全部
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
/* * ComboBox.java * * Created on 2010-8-2, 18:45:43 */package DEMO;
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JComboBox;
/** * * @author wlp */public class ComboBox extends javax.swing.JFrame { private JComboBox s = new JComboBox(); /** Creates new form ComboBox */ public ComboBox() { initComponents();
s = this.jComboBox2; INFO_SHOW actionListener = new INFO_SHOW(); this.jComboBox1.addActionListener(actionListener);
}
class INFO_SHOW implements ActionListener {
public void actionPerformed(ActionEvent evt) { JComboBox jComboBox1 = (JComboBox) evt.getSource(); if(jComboBox1.getSelectedItem().toString().equals("江苏")){ s.addItem("南京"); s.addItem("泰州"); s.addItem("扬州"); }
} }
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() {
jLabel1 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); jComboBox2 = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("省:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "请选择e69da5e6ba9062616964757a686964616f31333332643235", "江苏" }));
jLabel2.setText("市:");
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "请选择" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(75, 75, 75) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBox1, 0, 122, Short.MAX_VALUE)) .addContainerGap(59, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(25, 25, 25) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(49, Short.MAX_VALUE)) );
pack(); }//
/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { new ComboBox().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration}
本回答被网友采纳
已赞过
已踩过<
你对这个回答的评价是?
评论
收起