⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchdialog.java

📁 基于java的BUPT自习室查询系统。可以查询符合要求的自习室
💻 JAVA
字号:
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;


public class SearchDialog extends JDialog {

	private JComboBox room;
	private JComboBox build;
	private MyData data;
	/**
	 * Launch the application
	 * @param args
	 */
	
	public static void main(String args[]) {
		try {
			SearchDialog dialog = new SearchDialog();
			dialog.addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent e) {
					System.exit(0);
				}
			});
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog
	 */
	public SearchDialog() {
		super();
		getContentPane().setLayout(null);
		setResizable(false);
		setTitle("请选择教室");
		setBounds(100, 100, 371, 109);

		final JLabel label = new JLabel();
		label.setText("教学楼:");
		label.setBounds(10, 10, 60, 15);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("教室号:");
		label_1.setBounds(191, 10, 60, 15);
		getContentPane().add(label_1);

		build = new JComboBox();
		build.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				try {
					room.setModel(new DefaultComboBoxModel(data.room(build.getSelectedIndex()+1)));
				} catch (SQLException e1) {
					// TODO 自动生成 catch 块
					e1.printStackTrace();
				}
			}
		});
		build.setModel(new DefaultComboBoxModel(new String[] {"教一", "教二", "教三", "教四", "图书馆"}));
		build.setBounds(76, 7, 86, 21);
		getContentPane().add(build);

		room = new JComboBox();
		room.setBounds(257, 7, 86, 21);
		getContentPane().add(room);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				showresult();
			}
		});
		button.setText("确定(Y)");
		button.setMnemonic('y');
		button.setBounds(74, 47, 80, 21);
		getContentPane().add(button);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
			}
		});
		button_1.setText("取消(C)");
		button_1.setMnemonic('c');
		button_1.setBounds(220, 47,80, 21);
		getContentPane().add(button_1);
		//
	}
	private void close(){
		this.dispose();
	}
	public void init(MyData mydata){
		data = mydata;
		try {
			room.setModel(new DefaultComboBoxModel(data.room(build.getSelectedIndex()+1)));
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
	private void showresult(){
		ResultDialog rd = new ResultDialog();
		try {
			Vector info = new Vector();
			data.byroom(build.getSelectedIndex()+1, Integer.parseInt(room.getSelectedItem().toString()), info);
			//System.out.println(info);
			rd.init(info, build.getSelectedIndex()+1, Integer.parseInt(room.getSelectedItem().toString()));;
			rd.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
			rd.setLocation(this.getLocation());
			rd.setVisible(true);
			
		} catch (NumberFormatException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -