- 论坛徽章:
- 0
|
通常用 applet 产生的文件在folder builder下。但我以下的程序怎么没有生成。
- import javax.swing.*;
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.sql.Timestamp;
- public class dbJava extends JApplet implements ActionListener{
- public String login;
- public String pwd;
- private boolean isStandalone=false;
- private JTextField jtfuser=new JTextField(5);
- private JTextField jtfpwd =new JTextField(5);
-
- private JPanel jpanel1;
- private JButton jbtLogin=new JButton("Login");
- public Statement state, db2state;
- // private medicalform newMf;
- public static JFrame frame;
-
- /** Creates a new instance of dbJava */
- public dbJava() {
-
- }
-
- //initialize applet
- public void init(){
-
-
- initialize();
- jtfpwd=new JTextField(5);
- // jtfpwd.setEchoChar('*');
-
- jpanel1=new JPanel();
- jpanel1.add(new JLabel("User name"));
- jpanel1.add(jtfuser);
- jpanel1.add(new JLabel("Password"));
- jpanel1.add(jtfpwd);
- jpanel1.add(jbtLogin);
-
- getContentPane().setLayout(new FlowLayout());
- getContentPane().add(jpanel1, BorderLayout.NORTH);
-
- jbtLogin.addActionListener(this);
-
-
-
- }
- private void initialize(){
-
- try{
-
- //load jbc driver
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Driver Loaded");
-
- //Establish connection
- Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/books","root","000405");
-
- System.out.println("Database connected");
- //create statement
- state=connection.createStatement();
-
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
-
- }
-
- public void actionPerformed(ActionEvent e){
-
- login=jtfuser.getText();
- pwd=jtfpwd.getText();
- try{
- String query="select firstName, lastName from authors " + "where firstName = '" + login +"' and lastName = '"+pwd +"' ";
-
- ResultSet rset=state.executeQuery(query);
- if(rset.next()){
- String user=rset.getString(1);
- String pswd=rset.getString(2);
- jpanel1.removeAll();
-
- initialzeSecondDB();
-
- }else
- //Display if user not found
- JOptionPane.showMessageDialog(null, "User not found");
- }
- catch(SQLException ex){
- ex.printStackTrace();
- }
- }
- void initialzeSecondDB(){
- try{
- close();
- medicalform newMf=new medicalform();
-
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
-
- }
- public void close(){
-
- frame.setVisible(false);
-
- }
-
- public void init2(){
-
-
- initialize();
-
- jtfpwd=new JTextField(5);
- // jtfpwd.setEchoChar('*');
-
- jpanel1=new JPanel();
- jpanel1.add(new JLabel("User name"));
- jpanel1.add(jtfuser);
- jpanel1.add(new JLabel("Password"));
- jpanel1.add(jtfpwd);
- jpanel1.add(jbtLogin);
-
- jbtLogin.addActionListener(this);
- // this.getContentPane().add(jpanel1, BorderLayout.NORTH);
-
- frame=new JFrame();
- dbJava applet=new dbJava();
-
- applet.isStandalone=true;
-
- // frame.getContentPane().add(applet, BorderLayout.NORTH);
-
- applet.init();
- // applet.start();
-
-
-
- frame.setTitle("Medical Database");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(400,100);
- frame.setVisible(true);
-
- }
- public static void main(String args[]){
- //create frame
- frame=new JFrame();
- dbJava applet=new dbJava();
-
- applet.isStandalone=true;
-
- frame.getContentPane().add(applet, BorderLayout.EAST);
-
- applet.init();
- // applet.start();
-
-
- frame.setTitle("Medical Database");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(400,100);
- frame.setVisible(true);
-
-
- }
- }
复制代码 |
|