| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:注: Loagin.java使用或覆盖了已过时的 API。怎么修改啊?求高手指点?
取消只看楼主 加入收藏
chen521125ll
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-7
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
注: Loagin.java使用或覆盖了已过时的 API。怎么修改啊?求高手指点?
package wangqinglei;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;


public class Loagin extends JFrame implements ActionListener{

    /**
     * @param args
     */
    JLabel label1;
    JLabel label2;
    JLabel label3;
    JComboBox combo;
    JPasswordField textfield2;
    JButton button1;
    JButton button2;
    Connection conn;
    Object person[]={"tom","sara","jerry"};
    JPanel panel1=new JPanel();
    JPanel panel2=new JPanel();
    JPanel panel3=new JPanel();
   
    public Loagin(){
        setTitle("用户登录");
        setBounds(300,200,300,220);
        setVisible(true);
        //setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.setLayout(new BorderLayout());
        c.add(panel1,BorderLayout.NORTH);
        c.add(panel2,BorderLayout.CENTER);
        c.add(panel3,BorderLayout.SOUTH);
        //c.setBackground(Color.pink);
        //c.setLayout(new FlowLayout(1,3,10));
        label1=new JLabel("                   ");
        label1.setFont(new Font("华文行楷",Font.TYPE1_FONT,30));
        panel1.add(label1);
        panel2.setLayout(new FlowLayout(1,5,18));
        label2=new JLabel("           用户名:");
        panel2.add(label2);
        combo=new JComboBox(person);
        //combo.addItem(person);
        combo.setEditable(true);
        panel2.add(combo);
        label3=new JLabel("              码:");
        panel2.add(label3);
        textfield2=new JPasswordField(12);
        panel2.add(textfield2);
        button1=new JButton("登陆");
        button1.addActionListener(this);
        panel3.add(button1);
        button2=new JButton("清空");
        button2.addActionListener(this);
        panel3.add(button2);
        
        ProgressPanel propanel=new ProgressPanel();
        propanel.add(new JLabel("wait a second...."));
        //JScrollPane jsp=new JScrollPane(propanel);
        setGlassPane(propanel);
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==button2){
            //textfield1.setText("");
            //combo.removeAllItems();
            textfield2.setText("");
        }
        if(e.getSource()==button1){
            if(combo.getSelectedItem().equals("")){
                new JOptionPane().showMessageDialog(null,"用户名不能为空");
            }
            else if(textfield2.getText().equals("")){
                new JOptionPane().showMessageDialog(null, "密码不能为空");
            }
            else{
                String s1=(String) combo.getSelectedItem();
                String s2=textfield2.getText();
               
                try{
                    Class.forName("com.mysql.jdbc.Driver");
                    
                    conn = DriverManager.getConnection("jdbc:mysql://localhost/studentmanager?user=root&password=wql");
                    //System.out.print("745");
                    Statement stmt=conn.createStatement();
                    String sql="select * from user where username='"+s1+"' and password='"+s2+"'";
                    ResultSet rs = stmt.executeQuery(sql);
                    
                    if(rs.next()){
                        //System.out.print("Sucessfull");
                        getGlassPane().setVisible(true);
                        this.setVisible(false);
                        new MainPart();
                        
                    }
                    else{
                        new JOptionPane().showMessageDialog(null,"账号不存在,请检查后再输入!");
                    }
                           
                }catch(Exception e1){
                    System.err.print(e1.getMessage());
                }
               
            }
        }
        
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Loagin();

    }

}

搜索更多相关主题的帖子: package person Object public 
2013-01-08 13:26
快速回复:注: Loagin.java使用或覆盖了已过时的 API。怎么修改啊?求高手指点?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017870 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved