2个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import java.awt.*;
import javax.swing.JList;
import java.util.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class Frame1 extends JFrame {
JPanel contentPane;
JComboBox jComboBox1 = new JComboBox();
JList jList1 = new JList();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jComboBox1.setBounds(new Rectangle(6, 46, 138, 18));
jComboBox1.addItemListener(new Frame1_jComboBox1_itemAdapter(this));
jComboBox1.addItem("山东");
jComboBox1.addItem("北京");
jList1.setBounds(new Rectangle(189, 42, 138, 119));
contentPane.add(jComboBox1, null);
contentPane.add(jList1);
}
public void jComboBox1_itemStateChanged(ItemEvent e) {
Vector v1=new Vector();
v1.add("a");
v1.add("b");
Vector v2=new Vector();
v2.add("c");
v2.add("d");
if(jComboBox1.getSelectedIndex()==0)
{
jList1.setListData(v1);
}
if(jComboBox1.getSelectedIndex()==1)
{
jList1.setListData(v2);
}
}
}
class Frame1_jComboBox1_itemAdapter implements ItemListener {
private Frame1 adaptee;
Frame1_jComboBox1_itemAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.jComboBox1_itemStateChanged(e);
}
}
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import java.awt.*;
import javax.swing.JList;
import java.util.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class Frame1 extends JFrame {
JPanel contentPane;
JComboBox jComboBox1 = new JComboBox();
JList jList1 = new JList();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jComboBox1.setBounds(new Rectangle(6, 46, 138, 18));
jComboBox1.addItemListener(new Frame1_jComboBox1_itemAdapter(this));
jComboBox1.addItem("山东");
jComboBox1.addItem("北京");
jList1.setBounds(new Rectangle(189, 42, 138, 119));
contentPane.add(jComboBox1, null);
contentPane.add(jList1);
}
public void jComboBox1_itemStateChanged(ItemEvent e) {
Vector v1=new Vector();
v1.add("a");
v1.add("b");
Vector v2=new Vector();
v2.add("c");
v2.add("d");
if(jComboBox1.getSelectedIndex()==0)
{
jList1.setListData(v1);
}
if(jComboBox1.getSelectedIndex()==1)
{
jList1.setListData(v2);
}
}
}
class Frame1_jComboBox1_itemAdapter implements ItemListener {
private Frame1 adaptee;
Frame1_jComboBox1_itemAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.jComboBox1_itemStateChanged(e);
}
}
展开全部
public void jComboBox1_itemStateChanged(ItemEvent e) {
int i = jComboBox1.getSelectedIndex();
jList1.setSelectedIndex(i);
}
大体思路就是这样,
前提是两个中的构造方法中的object[]是一样的
这是对于在同一个jframe中的可以这么办
不在同一个中吧
直接用一个frame作为参数来构造另一个frame
或者用observer
int i = jComboBox1.getSelectedIndex();
jList1.setSelectedIndex(i);
}
大体思路就是这样,
前提是两个中的构造方法中的object[]是一样的
这是对于在同一个jframe中的可以这么办
不在同一个中吧
直接用一个frame作为参数来构造另一个frame
或者用observer
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询