注: 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();
}
}
----------------解决方案--------------------------------------------------------
你把这个Loagin关键字换成别的试试。
----------------解决方案--------------------------------------------------------
楼上的解答肯定是错误的 并不是类名的问题
这个只是一个警告而已,你不要去管他,他只是告诉你你使用了已经过时的函数,不过不要紧,jdk是向下兼容的!
只要编译能通过就可以了
----------------解决方案--------------------------------------------------------