急!Java问题,动态下拉列表的实现?

在Jsp页面中有两个下拉列表,省:<selectname="省"size="1"onChange="fun2()"><option>河北省</option></selec... 在Jsp页面中有两个下拉列表,
省: <select name="省" size="1" onChange="fun2()">
<option >河北省</option> </select>
市:<select name="市" size="1" onChange="fun2()">
<option >沧州市</option> </select>

请问如何动态的实现选择不同的省,在市的下拉列表中出现该省的所有市?谢谢大家!最好使用hibernate实现!
展开
 我来答
py405564727
2008-09-07
知道答主
回答量:27
采纳率:0%
帮助的人:13.6万
展开全部
import java.awt.Frame;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class seleinclassDialog extends JDialog {
JPanel panel1 = new JPanel();
JPanel jPanel1 = new JPanel();
Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(148, 145, 140));
JLabel jLabel1 = new JLabel();
JComboBox classmingzi = new JComboBox();
JComboBox smaclass = new JComboBox();
JTextField numclass = new JTextField();
JTextArea jTextArea1 = new JTextArea();
JButton yes = new JButton();
public seleinclassDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}

public seleinclassDialog() {
this(new Frame(), "按类别查找资源", false);
}

private void jbInit() throws Exception {
panel1.setLayout(null);
jPanel1.setBorder(border1);
jPanel1.setBounds(new Rectangle(7, 9, 700, 200));
jPanel1.setLayout(null);
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
jLabel1.setText("类别名");
jLabel1.setBounds(new Rectangle(7, 9, 59, 21));
classmingzi.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
classmingzi.setBounds(new Rectangle(49, 8, 76, 21));
classmingzi.addActionListener(new
seleinclassDialog_classmingzi_actionAdapter(this));
smaclass.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
smaclass.setBounds(new Rectangle(129, 8, 77, 21));
smaclass.addActionListener(new seleinclassDialog_smaclass_actionAdapter(this));
numclass.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
numclass.setText("");
numclass.setBounds(new Rectangle(217, 7, 50, 22));
jTextArea1.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
jTextArea1.setBounds(new Rectangle(13, 37, 566, 144));
yes.setBounds(new Rectangle(291, 7, 73, 23));
yes.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
yes.setText("确定");
yes.addActionListener(new seleinclassDialog_yes_actionAdapter(this));
getContentPane().add(panel1);
panel1.add(jPanel1);
jPanel1.add(jLabel1);
jPanel1.add(classmingzi);
jPanel1.add(jTextArea1);
jPanel1.add(yes);
jPanel1.add(smaclass);
jPanel1.add(numclass);
classmingzi.addItem("办公外设");
classmingzi.addItem("计算机");
classmingzi.addItem("数码产品");
}

public void classmingzi_actionPerformed(ActionEvent e) {
String bg="办公外设";
String jsj="计算机";
String sm="数码产品";
if(bg==classmingzi.getSelectedItem()){
smaclass.removeAllItems();
smaclass.addItem("传真机");
smaclass.addItem("打印机");
smaclass.addItem("复印机");
}else if(jsj==classmingzi.getSelectedItem()){
smaclass.removeAllItems();
smaclass.addItem("笔记本电脑");
smaclass.addItem("台式机");
smaclass.addItem("服务器");

} else {
smaclass.removeAllItems();
smaclass.addItem("数码相机");
smaclass.addItem("投影仪");
}

}

public void smaclass_actionPerformed(ActionEvent e) {
String cz="传真机";
String dy="打印机";
String fy="复印机";
String bb="笔记本电脑";
String dn="台式机";
String fw="服务器";
String smxj="数码相机";
String ty="投影仪";

if(cz.equals(smaclass.getSelectedItem())){
numclass.setText("1001");
}
if(dy.equals(smaclass.getSelectedItem())){
numclass.setText("1002");
}
if(fy.equals(smaclass.getSelectedItem())){
numclass.setText("1003");
}
if(bb.equals(smaclass.getSelectedItem())){
numclass.setText("3001");
}
if(dn.equals(smaclass.getSelectedItem())){
numclass.setText("3002");
}
if(fw.equals(smaclass.getSelectedItem())){
numclass.setText("3003");
}
if(smxj.equals(smaclass.getSelectedItem())){
numclass.setText("2001");
}
if(ty.equals(smaclass.getSelectedItem())){
numclass.setText("2002");
}

}

public void yes_actionPerformed(ActionEvent e) {
jTextArea1.setText("");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ce){
System.out.println(ce);
}
try{
String url="jdbc:odbc:chwxyz";
Connection con= DriverManager.getConnection(url);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * from zichan where 小类别='"+numclass.getText()+"'");
while(rs.next()){

jTextArea1.setText(rs.getString(1)+","+rs.getString(2)+","+rs.getString(3)+","+rs.getString(4)+","+rs.getString(5)+","+rs.getString(6)+","+rs.getString(7)+","+rs.getString(8)+","+rs.getString(9)+"");
}
}catch(SQLException ce){
System.out.println(ce);
}
}
}

class seleinclassDialog_yes_actionAdapter implements ActionListener {
private seleinclassDialog adaptee;
seleinclassDialog_yes_actionAdapter(seleinclassDialog adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.yes_actionPerformed(e);
}
}

class seleinclassDialog_smaclass_actionAdapter implements ActionListener {
private seleinclassDialog adaptee;
seleinclassDialog_smaclass_actionAdapter(seleinclassDialog adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.smaclass_actionPerformed(e);
}
}

class seleinclassDialog_classmingzi_actionAdapter implements ActionListener {
private seleinclassDialog adaptee;
seleinclassDialog_classmingzi_actionAdapter(seleinclassDialog adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.classmingzi_actionPerformed(e);
}
}
这是我以前练习时写的一个你只需要改动几下就可以啦 呵呵 不好意思我懒的去重写啦不过你看看影该会明白他怎么用的。……不好意思
pa...4@qq.com
2008-09-06 · TA获得超过556个赞
知道小有建树答主
回答量:462
采纳率:0%
帮助的人:285万
展开全部
这种东西用js做啊,网上多的是,干什么用java做?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式