package 風景名勝查詢系統;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.ImageIcon;
class Login extends JFrame implements ActionListener
{
JTextField text1;
JPasswordField text2;
JButton btn_confirm,btn_register,btn_cancel;
public Login()
{
JPanel[] p = new JPanel[6];
setTitle("登錄窗口");
this.setBounds(400,300,390,350);
Container con = getContentPane();
((JPanel)con).setBorder(BorderFactory.createEmptyBorder(70,20,20,20));//設置組件與窗口邊緣的邊距
con.setLayout(new GridLayout(6,1,5,5));
p[0] = new JPanel();
p[0].add(new JLabel("用戶登錄"));
p[1] = new JPanel();
p[1].add(new JLabel("用戶名:"));
text1 = new JTextField(12);
p[1].add(text1);
p[2]= new JPanel();
p[2].add(new JLabel("密 碼:"));
text2 = new JPasswordField(12);
p[2].add(text2);
p[3] = new JPanel();
p[3].add(new JLabel("驗證碼:"));
JButton btn_vertify = new JButton("",new ImageIcon("E:\\U盤文件\\100PHOTO.jpeg"));
//btn_vertify.setMnemonic(KeyEvent.VK_F);
p[3].add(btn_vertify);
p[3].add(new JLabel());
p[4] = new JPanel();
btn_confirm = new JButton("確定");
btn_confirm.addActionListener(this);
btn_register = new JButton("注冊");
btn_register.addActionListener(this);
btn_cancel = new JButton("退出");
btn_cancel.addActionListener(this);
p[4].add(btn_confirm);
p[4].add(btn_register);
p[4].add(btn_cancel);
p[5] = new JPanel();
for(int i=0;i<6;i++)
con.add(p[i]);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Connection con=null;
Statement st =null;
ResultSet rs = null;
if(e.getActionCommand().equals("確定"));
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=wulei");
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery("select * from stuinf");
rs.last();
while(rs.previous())
{//根據執行查詢所返回的結果集rs,查找結果集中每條記錄所指定的列名對應的值,並與文本框的字符串比較,判斷是否相等。
String myname = rs.getString("stuNum");
String mypassword = rs.getString("stupwd");
if(myname.equals(text1.getText())&&mypassword.equals(text2.getText()));
{
JOptionPane.showMessageDialog(null," 登錄成功!","信息提示",JOptionPane.PLAIN_MESSAGE);
this.setVisible(false);
new LandScape();
}
}
rs.close();st.close();con.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null," 登錄失敗!","信息提示",JOptionPane.PLAIN_MESSAGE);
new LandScape();//假設連接數據庫不管成功與否都能進入主界面
}
}
if(e.getActionCommand().equals("退出"))
this.dispose();
}
}
public class LandScape extends JFrame implements ActionListener
{
public LandScape()
{
//JPanel[] p = new JPanel[6];
setTitle("旅行社查詢窗口");
this.setBounds(100,100,500,400);
Container con = getContentPane();
((JPanel)con).setBorder(BorderFactory.createEmptyBorder(10,5,5,10));//設置組件與窗口邊緣的邊距
con.setLayout(new GridLayout(2,1,5,5));
JPanel p_up = new JPanel();
p_up.setLayout(new GridLayout(3,1,5,5));
JPanel p_up1 = new JPanel();
p_up1.add(new JLabel("風景名勝信息查詢",JLabel.CENTER));
JPanel p_up2 = new JPanel();
p_up2.add(new JLabel("省市名: "));
p_up2.add(new JTextField(20));
p_up2.add(new JLabel("旅行月份:"));
p_up2.add(new JTextField(10));
p_up2.add(new JLabel("溫馨提示:5、10月是旺季,單價上浮10%"));
JPanel p_up3 = new JPanel();
p_up3.add(new JLabel("風景名勝:"));
p_up3.add(new JTextField(20));
p_up3.add(new JLabel("門票單價:"));
p_up3.add(new JTextField(10));
p_up3.add(new JLabel("1、2月是淡季,單價下浮10%。"));
p_up.add(p_up1);p_up.add(p_up2);p_up.add(p_up3);
JPanel p_down = new JPanel();
p_down.setLayout(new GridLayout(1,2,5,5));
JPanel p_down_left = new JPanel();
p_down_left.add(new JTextArea(300,250));
JPanel p_down_right = new JPanel();
p_down_right.setLayout(new GridLayout(6,2,3,3));
p_down_right.add(new JLabel("旅客類型"));
p_down_right.add(new JLabel("人數(人)"));
//p_down_right.add(new JLabel("老人:"));
p_down_right.add(new JRadioButton("老人:"));
p_down_right.add(new JTextField(10));
// p_down_right.add(new JLabel("學生:"));
p_down_right.add(new JRadioButton("學生:"));
p_down_right.add(new JTextField(10));
//p_down_right.add(new JLabel("小孩:"));
p_down_right.add(new JRadioButton("小孩:"));
p_down_right.add(new JTextField(10));
// p_down_right.add(new JLabel("成人:"));
p_down_right.add(new JRadioButton("成人:"));
p_down_right.add(new JTextField(10));
p_down_right.add(new JButton("提交"));
p_down_right.add(new JLabel());
p_down_right.add(new JButton("退出"));
p_down.add(p_down_left);p_down.add(p_down_right);
con.add(p_up);con.add(p_down);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e3)
{
}
public static void main(String[] args)
{
new Login();
}
}