代码如下,只是按钮等都显示不出来,请问是什么原因?请帮助我。不胜感激:
package PasswordManeger;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class LogInWindows extends JFrame implements ActionListener
{
private Function functionclass=new Function();
private String urlofimagetoshow="C:\\Users\\lenovo\\Desktop\\信息管理器\\show.jpg";
private String urloficon="C:\\Users\\lenovo\\Desktop\\信息管理器\\login.jpg";
private Image icon;
private Image imagetoshow;
private JLabel idlabel;
private JLabel passwordlabel;
private JTextField idtextfield;
private JTextField passwordtextfield;
private JButton loginbutton;
private Container container;
public LogInWindows()
{
super("密码管理器");
container=new Container();
container=getContentPane();
container.setLayout(null);
icon=getToolkit().getImage(urloficon);
setIconImage(icon);
imagetoshow=getToolkit().getImage(urlofimagetoshow);
setVisible(true);//if you don't add it,there will a mistake when show the login window
Graphics graphics=this.getGraphics();
idlabel=new JLabel("账号");
idlabel.setBounds(100,200,50,20);
container.add(idlabel);
passwordlabel=new JLabel("密码");
passwordlabel.setBounds(100,250,50,20);
container.add(passwordlabel);
idtextfield=new JTextField();
idtextfield.setBounds(200,200,100,20);
container.add(idtextfield);
passwordtextfield=new JTextField();
passwordtextfield.setBounds(200,250,100,20);
container.add(passwordtextfield);
loginbutton=new JButton("登录");
loginbutton.setBounds(220,270,30,20);
loginbutton.addActionListener(this);
container.add(loginbutton);
paint(graphics);// is it right?
setSize(500,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
boolean idexist=false;
String sql="select * from INFORMATIONOFUSER;";
String dbdriver="oracle.jdbc.driver.OracleDriver";
String dburl="jdbc:oracle:thin:@localhost:1521:orcl";
String dbuser="scott";
String dbpassword="123456";
String passwordofuser="";
try {
Class.forName(dbdriver);
Connection dataconnection=DriverManager.getConnection(dburl, dbuser, dbpassword);
Statement statement=dataconnection.createStatement();
ResultSet result=statement.executeQuery(sql);
do
{
if(result.getString(1)==idtextfield.getText())
{
idexist=true;
passwordofuser=result.getString(2);
break;
}
}while(result.next());
if(idexist==true||passwordtextfield.getText()==passwordofuser)
{
functionclass.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this,"账号或者密码错误");
}
}
catch (ClassNotFoundException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
public void paint(Graphics g)
{
g.drawImage(imagetoshow, 0, 0,500,150,this);
}
}
------解决思路----------------------
22行
private Function functionclass=new Function();Function是什么类?