我按照书上写的编译了一个项目,包括五个文件,第一个是登录界面,有一个警告是不是可以正常运行了呢,可是我没看到MAIN函数,那要怎么运行阿。指点一下吧,谢谢阿。
以下是登录窗口的文件
package app;import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.lang.Object;/**
* <p>Title: 个人日常事务管理系统</p>
* <p>Description: 用于个人管理</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class LogFrame extends JFrame {
private XYLayout xYLayout1 = new XYLayout();
private JLabel jLabel_name = new JLabel();
private JLabel jLabel_password = new JLabel();
private JTextField jTextField_name = new JTextField();
private JLabel jLabel1 = new JLabel();
private JPasswordField jPasswordField = new JPasswordField();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
protected String user,password,password_from;
AppFrame frame;
public LogFrame(AppFrame frame1) {
frame = frame1;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle("登录窗口");
this.getContentPane().setLayout(xYLayout1);
jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel_name.setText("请输入用户名:");
jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel_password.setText("请输入密码:");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel1.setText("个 人 日 常 事 务 管 理 系 统");
jButton1.setFont(new java.awt.Font("Dialog", 0, 14));
jButton1.setText("确 认");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton2.setText("取 消");
jButton2.setFont(new java.awt.Font("Dialog", 0, 14));
jTextField_name.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
jTextField_name_focusLost(e);
}
});
jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
jPasswordField_focusLost(e);
}
});
this.getContentPane().add(jLabel_password, new XYConstraints(52, 148, 91, 28));
this.getContentPane().add(jLabel_name, new XYConstraints(51, 101, 99, -1));
this.getContentPane().add(jTextField_name, new XYConstraints(160, 95, 155, 28));
this.getContentPane().add(jLabel1, new XYConstraints(84, 20, 220, 38));
this.getContentPane().add(jPasswordField, new XYConstraints(159, 143, 156, 32));
this.getContentPane().add(jButton1, new XYConstraints(77, 205, 88, 33));
this.getContentPane().add(jButton2, new XYConstraints(218, 206, 88, 33));
} void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
} void jTextField_name_focusLost(FocusEvent e) { } void jPasswordField_focusLost(FocusEvent e) {
password = jPasswordField.getText();
} void jButton1_actionPerformed(ActionEvent e) {
Connection con;
String url="jdbc:odbc:grrc";
Statement stmt;
user = jTextField_name.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,"","");
String sql="SELECT PASSWORD from sys_safe where NAME ='"+user+"'";
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
password_from = rs.getString("PASSWORD");
if(password_from.endsWith(password)){
JOptionPane.showMessageDialog(this,"密码正确!","登录信息",JOptionPane.INFORMATION_MESSAGE);
this.setVisible(false);
frame.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int h = screenSize.height;
int w = screenSize.width;
frame.setSize(w,h);
Dimension frameMainSize = frame.getSize();
// Center the Window
if (frameMainSize.height > screenSize.height) {
frameMainSize.height = screenSize.height;
}
if (frameMainSize.width > screenSize.width) {
frameMainSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameMainSize.width) / 2, (screenSize.height - frameMainSize.height) / 2);
}
else{
JOptionPane.showMessageDialog(this,"密码和用户名不符,请重新输入密码!","登录信息",JOptionPane.INFORMATION_MESSAGE);
}
con.close();
}catch(Exception ex){
System.out.println("A problem occurred during the establishment of th connection: "+ex);
} }}
以下是登录窗口的文件
package app;import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.lang.Object;/**
* <p>Title: 个人日常事务管理系统</p>
* <p>Description: 用于个人管理</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class LogFrame extends JFrame {
private XYLayout xYLayout1 = new XYLayout();
private JLabel jLabel_name = new JLabel();
private JLabel jLabel_password = new JLabel();
private JTextField jTextField_name = new JTextField();
private JLabel jLabel1 = new JLabel();
private JPasswordField jPasswordField = new JPasswordField();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
protected String user,password,password_from;
AppFrame frame;
public LogFrame(AppFrame frame1) {
frame = frame1;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle("登录窗口");
this.getContentPane().setLayout(xYLayout1);
jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel_name.setText("请输入用户名:");
jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel_password.setText("请输入密码:");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel1.setText("个 人 日 常 事 务 管 理 系 统");
jButton1.setFont(new java.awt.Font("Dialog", 0, 14));
jButton1.setText("确 认");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton2.setText("取 消");
jButton2.setFont(new java.awt.Font("Dialog", 0, 14));
jTextField_name.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
jTextField_name_focusLost(e);
}
});
jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
jPasswordField_focusLost(e);
}
});
this.getContentPane().add(jLabel_password, new XYConstraints(52, 148, 91, 28));
this.getContentPane().add(jLabel_name, new XYConstraints(51, 101, 99, -1));
this.getContentPane().add(jTextField_name, new XYConstraints(160, 95, 155, 28));
this.getContentPane().add(jLabel1, new XYConstraints(84, 20, 220, 38));
this.getContentPane().add(jPasswordField, new XYConstraints(159, 143, 156, 32));
this.getContentPane().add(jButton1, new XYConstraints(77, 205, 88, 33));
this.getContentPane().add(jButton2, new XYConstraints(218, 206, 88, 33));
} void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
} void jTextField_name_focusLost(FocusEvent e) { } void jPasswordField_focusLost(FocusEvent e) {
password = jPasswordField.getText();
} void jButton1_actionPerformed(ActionEvent e) {
Connection con;
String url="jdbc:odbc:grrc";
Statement stmt;
user = jTextField_name.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,"","");
String sql="SELECT PASSWORD from sys_safe where NAME ='"+user+"'";
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
password_from = rs.getString("PASSWORD");
if(password_from.endsWith(password)){
JOptionPane.showMessageDialog(this,"密码正确!","登录信息",JOptionPane.INFORMATION_MESSAGE);
this.setVisible(false);
frame.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int h = screenSize.height;
int w = screenSize.width;
frame.setSize(w,h);
Dimension frameMainSize = frame.getSize();
// Center the Window
if (frameMainSize.height > screenSize.height) {
frameMainSize.height = screenSize.height;
}
if (frameMainSize.width > screenSize.width) {
frameMainSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameMainSize.width) / 2, (screenSize.height - frameMainSize.height) / 2);
}
else{
JOptionPane.showMessageDialog(this,"密码和用户名不符,请重新输入密码!","登录信息",JOptionPane.INFORMATION_MESSAGE);
}
con.close();
}catch(Exception ex){
System.out.println("A problem occurred during the establishment of th connection: "+ex);
} }}
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<APPLET CODE="LogFrame" WIDTH="700" HEIGHT="450">
</APPLET>
</BODY>
</HTML>
public static void main(String[] args){LogFrame log=new LogFrame();}
LogFrame f = new LogFrame();
f.setSize(…);
f.show();
…
}