我giao了这科颗二叉树 2018-12-26 20:01 采纳率: 0%
浏览 357

运行出来报了代码后面那段错误。解决不来。各位大哥棒棒忙。本人小白一枚。

package javaproject;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.ButtonGroup;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JTextField;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JRadioButton;

import java.awt.Font;

import javax.swing.SwingConstants;

import java.sql.*;

public class windos1 extends JFrame {

final String stu_name="ycb";
final String stu_pwd="1";
final String tea_name="王老师";
final String tea_pwd="1";
private JPanel contentPane;
private JTextField id;
private JTextField key;

ResultSet res;

static Connection con;
bookdb b;
/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        bookdb b=new bookdb();
        windos1 ui1=new windos1();
        public void run() {
            try {
                windos1 frame = new windos1();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public windos1() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 348, 310);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
    JButton login = new JButton("\u767B\u5F55");    

    login.setBounds(49, 205, 93, 23);
    contentPane.add(login);



    JButton canner = new JButton("\u53D6\u6D88");
    canner.setBounds(176, 205, 93, 23);
    contentPane.add(canner);

    id = new JTextField();
    id.setBounds(113, 79, 128, 18);
    contentPane.add(id);
    id.setColumns(10);

    key = new JTextField();
    key.setBounds(113, 120, 128, 18);
    contentPane.add(key);
    key.setColumns(10);

    JRadioButton choose1 = new JRadioButton("\u8001\u5E08");
    choose1.setBounds(84, 163, 69, 23);
    contentPane.add(choose1);

    JRadioButton choose2 = new JRadioButton("\u5B66\u751F");
    choose2.setBounds(162, 163, 61, 23);
    contentPane.add(choose2);

    JLabel label_1 = new JLabel("\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF");
    label_1.setFont(new Font("宋体", Font.PLAIN, 36));
    label_1.setBounds(53, 10, 238, 38);
    contentPane.add(label_1);

    JLabel lblNewLabel = new JLabel("\u8D26\u53F7");
    lblNewLabel.setBounds(71, 81, 35, 15);
    contentPane.add(lblNewLabel);

    JLabel label = new JLabel("\u5BC6\u7801"); //
    label.setBounds(71, 120, 35, 15);
    contentPane.add(label);

    ButtonGroup group=new ButtonGroup();
    group.add(choose1);
    group.add(choose2);

    this.setVisible(true);




login.addActionListener(new ActionListener() {    //确定按钮监听事件
    public void actionPerformed(ActionEvent e) {



        if (e.getActionCommand()=="登录"){
            if (choose1.isSelected()){  //判断选择的是choose1
                String sql="select * from teaid_key where id='"+id.getText()+"'"+"select  * from teaid_key where keytea='"+key.getText()+"'";
                    res=b.find(sql);

                try{
                    if (res.next()){

                        JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE);           
                        dispose();        
                        clear();            
                        windosteacher tec=new windosteacher();     //创建新界面  
                    }else{
                         JOptionPane.showMessageDialog(null,"用户名或者密码错误!\n请重新输入","提示消息",JOptionPane.ERROR_MESSAGE);  
                            //清空输入框  
                            clear();                
                    }

                }catch(Exception e1){
                e1.printStackTrace();   
                }

            }
            if (choose2.isSelected()){  //判断选择的是choose2
                stuchoose();    
            }
        }
    }
    //选择老师
    /*public void teachoose (){

        if(tea_name.equals(id.getText())&&tea_pwd.equals(key.getText()))  
        {            
            JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE);           
            dispose();        
            clear();            
            windosteacher tec=new windosteacher();     //创建新界面  
        }else if(id.getText().isEmpty()&&key.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入用户名和密码!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else if(id.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入用户名!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else if(key.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入密码!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else  
        {  
            JOptionPane.showMessageDialog(null,"用户名或者密码错误!\n请重新输入","提示消息",JOptionPane.ERROR_MESSAGE);  
            //清空输入框  
            clear();  
        } 

    }*/
    //选择学生
    public void stuchoose(){  

        if(id.equals(id.getText())&&stu_pwd.equals(key.getText()))  
        {            
            JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE);           
            dispose();        
            clear();                  
            new windosstudent();//创建新界面 

        }else if(id.getText().isEmpty()&&key.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入用户名和密码!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else if(id.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入用户名!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else if(key.getText().isEmpty())  
        {  
            JOptionPane.showMessageDialog(null,"请输入密码!","提示消息",JOptionPane.WARNING_MESSAGE);  
        }else  
        {  
            JOptionPane.showMessageDialog(null,"用户名或者密码错误!\n请重新输入","提示消息",JOptionPane.ERROR_MESSAGE);  
            //清空输入框  
            clear();  
        }  
    }
    //清空文本框
    private void clear() {
        // TODO 自动生成的方法存根
        id.setText("");  
        key.setText("");  
    } 

});

}
}

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javaproject.windos1$2.actionPerformed(windos1.java:124)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

  • 写回答

2条回答 默认 最新

  • jasondyoung 2018-12-26 12:32
    关注

    windos1.java:124//这个类124行空指针,其它不知道。

    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突