importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.*;importjava.util.Vector;importjavax.swing.JButton;importjavax.swing.JFrame;impo...
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.event.WindowAdapter;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
public class xuanzechengshi {
private JFrame frame;
private JPanel panel;
private JLabel label_l1;
private JComboBox jComboBox1;
private JButton jbt_Run;
private JButton jbt_Exit;
public String selectCity(){
frame = new JFrame("城市选择");
panel=new JPanel();
label_l1=new JLabel("欢迎来到景点信息系统");
jComboBox1=null;
jbt_Run=new JButton("下一步");
jbt_Exit=new JButton("退出系统");
Vector v = new Vector(14);
v.add("北京");
v.add("西安");
v.add("上海");
v.add("深圳");
v.add("杭州");
v.add("重庆");
v.add("苏州");
v.add("丽江");
v.add("拉萨");
v.add("香港");
v.add("澳门");
v.add("青岛");
v.add("天津");
v.add("洛阳");
this.jComboBox1 = new JComboBox(v);
jComboBox1.setBorder(BorderFactory.createTitledBorder("请选择城市"));
jComboBox1.setMaximumRowCount(14);
int size = v.size ();
for (int i = 0; i < size; i++)
{
jComboBox1.addItem(v.get(i));
}
panel.add(this.jComboBox1);
this.frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0){
System.exit(1);
}
});
frame.setSize(400,400);
frame.add(panel);
panel.setLayout(null);
panel.add(label_l1);
label_l1.setBounds(50,75,200,20);
panel.add(jComboBox1);
jComboBox1.setBounds(50,175,200,60);
panel.add(jbt_Run);
jbt_Run.setBounds(50, 320, 90, 20);
panel.add(jbt_Exit);
jbt_Exit.setBounds(250, 320, 90, 20);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jComboBox1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
}
});
jbt_Run.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
xuanzejingdian d=new xuanzejingdian();
int index=jComboBox1.getSelectedIndex();
String obj = (String) jComboBox1.getSelectedItem();
d.selectScenery(obj, index);
//添加按钮事件“下一步”
}
});
jbt_Exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
int index=jComboBox1.getSelectedIndex();
String obj = (String) jComboBox1.getSelectedItem();
xuanzejingdian d=new xuanzejingdian();
d.selectScenery(obj, index);
return obj;
}
}
展开