| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 989 人关注过本帖
标题:请帮忙看下代码,连接数据库的课程设计,有错误改不过来,速求!!!
取消只看楼主 加入收藏
笔墨痕干
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2014-3-24
结帖率:84.21%
收藏
 问题点数:0 回复次数:1 
请帮忙看下代码,连接数据库的课程设计,有错误改不过来,速求!!!
package 界面设计;

import java.awt.Button;

public class Student extends JFrame {
    public Student() {
    }
   
    JMenuBar menubar;//菜单栏
    JMenu menu1,menu2,menu3;
    JMenuItem itme1,item2,item3;
    ImageIcon background;
    JTextArea jt;
   
    final Container con=this.getContentPane();
    /**
     * @wbp.nonvisual location=160,-13
     */
    private final Panel panel = new Panel();
    private JMenuItem menuItem;
    private JMenuItem menuItem_1;
    private JMenuItem menuItem_2;
    private User user;
   
    public void StudentShow(User user2) {
        // TODO Auto-generated method stub
        this.user=user2;
        init();
        
    }
    public void init(){
        // TODO Auto-generated method stub
        this.user=user;
        JLabel lab;
        this.setTitle("一般用户界面--张愉");
        //背景图片
        background = new ImageIcon("t.png");  
        // 把背景图片显示在一个标签里面  
        lab = new JLabel(background);  
        // 把标签的大小位置设置为图片刚好填充整个面板  
        lab.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  
        // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明  
        JPanel imagePanel = (JPanel) this.getContentPane();
        getContentPane().setLayout(new CardLayout(0, 0));
        imagePanel.setOpaque(false);  
        // 把背景图片添加到分层窗格的最底层作为背景  
        this.getLayeredPane().add(lab, new Integer(Integer.MIN_VALUE));
        
        menubar=new JMenuBar();
        this.setJMenuBar(menubar);
        menubar.setBackground(Color.gray);
        menu1=new JMenu("信息维护");
        menu2=new JMenu("\u6210\u7EE9\u67E5\u8BE2");//成绩查询菜单
        menu3=new JMenu("课程查询");
        itme1=new JMenuItem("信息更新");
        menu1.add(itme1);
        menubar.add(menu1);
        menubar.add(menu2);
        //按班级查询成绩
        menuItem = new JMenuItem("\u6309\u73ED\u7EA7\u67E5\u8BE2");
        menuItem.addActionListener(new ActionListener() {
            JLabel[] lab=new JLabel[9];
            JTextField[] txt=new JTextField[6];
            Button bt1,bt2;
            
            public void actionPerformed(ActionEvent e) {
                con.removeAll();
                JPanel jp=new JPanel();
                jp.setLayout(new BorderLayout());
                jp.setOpaque(false);
               
                JPanel jp1=new JPanel();
                jp1.setLayout(new GridLayout(10,1));
                jp1.setOpaque(false);
                lab[0]=new JLabel("按班级查询:");
                lab[0].setFont(new Font("隶书",0,30));
                lab[0].setForeground(Color.green);
                String s[]={"20060101","20070101","20070201","20070301","20070302","20070303","20070304",
                        "20070305","20070306","20070307","20070501","20070502","20070503","20070504"};
                JComboBox jc1=new JComboBox(s);
               
                lab[1]=new JLabel("按课程查询:");
                lab[1].setFont(new Font("隶书",0,30));
                lab[1].setForeground(Color.green);
                String s1[]={"DB_大学s英语","高等数学","思想品德教育","法律基础","电工基础","电子技术基础","电子线路基础",
                        "计算机文化基础","C语言程序设计与数据结构","软件工程","JAVA程序设计基础","JAVA高级程序设计","数据库原理及应用",
                        "计算机网络技术","网页制作技术","JAVA项目实训","JSP程序设计","计算机组装与维修"};
                JComboBox jc2=new JComboBox(s1);
               
                        
                lab[2]=new JLabel("按专业查询:");
                lab[2].setFont(new Font("隶书",0,30));
                lab[2].setForeground(Color.green);
                String s2[]={"电子工程专业","计算机工程专业","航空专业","金融专业","软件工程专业"};
                JComboBox jc3=new JComboBox(s2);
                jc3.setEnabled(false);
               
               
                JPanel jp2=new JPanel();
                jp2.setLayout(new FlowLayout(FlowLayout.LEFT));
                jp2.setOpaque(false);
                bt1=new Button("查询");
                bt2=new Button("取消");
                jp2.add(bt1);
                jp2.add(bt2);
               
                jp1.add(lab[0]);
                jp1.add(jc1);
                jp1.add(lab[1]);
                jp1.add(jc2);
                jp1.add(lab[2]);
                jp1.add(jc3);
                jp1.add(jp2);
                jp.add("West",jp1);
                con.add(jp);
                con.repaint();
                con.validate();
            }
        });
        menu2.add(menuItem);
        
        menuItem_1 = new JMenuItem("\u6309\u8BFE\u7A0B\u67E5\u8BE2");
        menu2.add(menuItem_1);
        
        menuItem_2 = new JMenuItem("\u6309\u4E13\u4E1A\u67E5\u8BE2");
        menu2.add(menuItem_2);
        menubar.add(menu3);
        
        //信息更新页面
        itme1.addActionListener(new ActionListener(){
            JLabel[] lab=new JLabel[9];
            JTextField[] txt=new JTextField[6];
            Button bt1,bt2;
            User user1;
            UserDao userdao=new UserImplement();
            @Override
            public void actionPerformed(ActionEvent e) {
                user1=userdao.SgetUser(user.getId());
                //user1==null,说明在student表中没有次学生的xin'xi
                if(user1==null){
                    
                Show(null,null,null);
                }
                else{
                    
                    //班级,学号,班级编号
                    String str1,str2,str3;
                    str1=user1.getClassName();
                    str2=user1.getId();
                    str3=user1.getNumber();
                    Show(str1,str2,str3);
                }
               
            }
            private void Show(String s1,String s2,String s3) {
                final String str1=s1;
                final String str2=s2;
                final String str3=s3;
                boolean flage=false;
                con.removeAll();
               
                JPanel jp=new JPanel();
                jp.setOpaque(false);
                jp.setLayout(null);
               
                lab[1]=new JLabel("姓名:");
                txt[0]=new JTextField();
                txt[0].setText(user.getName());
                txt[0].setEditable(flage);
                txt[0].setBounds(130, 38, 100, 25);
                lab[1].setFont(new Font("隶书",0,30));
                lab[1].setForeground(Color.green);
                lab[1].setBounds(50,-50, 200, 200);
                jp.add(lab[1]);
                jp.add(txt[0]);
               
                lab[2]=new JLabel("性别:");
                txt[1]=new JTextField();
                txt[1].setText(user.getSex());
                txt[1].setEditable(flage);
                txt[1].setBounds(410, 38, 100, 25);
                lab[2].setFont(new Font("隶书",0,30));
                lab[2].setForeground(Color.green);
                lab[2].setBounds(330,-50, 200, 200);
                jp.add(lab[2]);
                jp.add(txt[1]);
               
                lab[3]=new JLabel("出生日期:");
                txt[2]=new JTextField();
                txt[2].setEditable(flage);
                txt[2].setText(user.getBrithday()+"");
                txt[2].setBounds(710, 38, 100, 25);
                lab[3].setFont(new Font("隶书",0,30));
                lab[3].setForeground(Color.green);
                lab[3].setBounds(570,-50, 200, 200);
                jp.add(lab[3]);
                jp.add(txt[2]);
               
                lab[4]=new JLabel("班级:");
                txt[3]=new JTextField();
                txt[3].setEditable(flage);
                txt[3].setText(str1);//班级名   
                txt[3].setBounds(130, 138, 100, 25);
                lab[4].setFont(new Font("隶书",0,30));
                lab[4].setForeground(Color.green);
                lab[4].setBounds(50,50, 200, 200);
                jp.add(lab[4]);
                jp.add(txt[3]);
               
                lab[5]=new JLabel("学号:");
                txt[4]=new JTextField();
                txt[4].setEditable(false);
                txt[4].setText(str2);//学号
                txt[4].setBounds(410, 138, 100, 25);
                lab[5].setFont(new Font("隶书",0,30));
                lab[5].setForeground(Color.green);
                lab[5].setBounds(330,50, 200, 200);
                jp.add(lab[5]);
                jp.add(txt[4]);
               
                lab[6]=new JLabel("班级编号:");
                txt[5]=new JTextField();
                txt[5].setEditable(flage);
                txt[5].setText(str3);//班级班号
                txt[5].setBounds(710, 138, 100, 25);
                lab[6].setFont(new Font("隶书",0,30));
                lab[6].setForeground(Color.green);
                lab[6].setBounds(570,50, 200, 200);
                jp.add(lab[6]);
                jp.add(txt[5]);
               
                lab[7]=new JLabel("简介:");
                lab[7].setFont(new Font("隶书",0,30));
                lab[7].setForeground(Color.green);
                lab[7].setBounds(50, 130, 200, 200);
                jt=new JTextArea();
                jt.setEditable(flage);
                jt.setBackground(Color.darkGray);
                jt.setForeground(Color.white);
                jt.setFont(new Font("隶书",0,30));
                jt.setBounds(50,250,770,160);
                jp.add(lab[7]);
                jp.add(jt);
               
                bt1=new Button("保存");
                bt1.setBounds(300,420, 50, 30);
                bt1.setBackground(Color.green);
                bt2=new Button("编辑");
                bt2.setBounds(400,420, 50, 30);
                bt2.setBackground(Color.green);
                jp.add(bt1);
                jp.add(bt2);
//保存按钮的事件监听器
//                bt1.addActionListener(new ActionListener(){
//                    User user2;
//                    @Override
//                    public void actionPerformed(ActionEvent e) {
//                        // TODO Auto-generated method stub
//                        System.out.println("进去了");
//                        UserDao userdao=new UserImplement();
//                        user2=userdao.SgetUser(user.getId());
//                        if(user!=null){
//                            System.out.println("hao"+user2.getId());
//                            user2.setId(user.getId());
//                            user2.setName(txt[0].getText());
//                            user2.setSex(txt[1].getText());
//                            user2.setNumber(txt[5].getText());
//                            System.out.println(txt[5].getText());
//                            userdao.update(user2);
//                        }
//                        
//                    }
//                    
//                });
//编辑按钮添加事件监听器
                bt2.addActionListener(new ActionListener(){
                    
                    boolean flage=true;
                    public void actionPerformed(ActionEvent e) {
                        con.removeAll();
                        JPanel jp=new JPanel();
                        jp.setOpaque(false);
                        jp.setLayout(null);
                        
                        lab[1]=new JLabel("姓名:");
                        txt[0]=new JTextField();
                        txt[0].setText(user.getName());
                        txt[0].setEditable(flage);
                        txt[0].setBounds(130, 38, 100, 25);
                        lab[1].setFont(new Font("隶书",0,30));
                        lab[1].setForeground(Color.green);
                        lab[1].setBounds(50,-50, 200, 200);
                        jp.add(lab[1]);
                        jp.add(txt[0]);
                        
                        lab[2]=new JLabel("性别:");
                        txt[1]=new JTextField();
                        txt[1].setText(user.getSex());
                        txt[1].setEditable(flage);
                        txt[1].setBounds(410, 38, 100, 25);
                        lab[2].setFont(new Font("隶书",0,30));
                        lab[2].setForeground(Color.green);
                        lab[2].setBounds(330,-50, 200, 200);
                        jp.add(lab[2]);
                        jp.add(txt[1]);
                        
                        lab[3]=new JLabel("出生日期:");
                        txt[2]=new JTextField();
                        txt[2].setEditable(flage);
                        txt[2].setText(user.getBrithday()+"");
                        txt[2].setBounds(710, 38, 100, 25);
                        lab[3].setFont(new Font("隶书",0,30));
                        lab[3].setForeground(Color.green);
                        lab[3].setBounds(570,-50, 200, 200);
                        jp.add(lab[3]);
                        jp.add(txt[2]);
                        
                        lab[4]=new JLabel("班级:");
                        txt[3]=new JTextField();
                        txt[3].setText(str1);//班级名
                        txt[3].setBounds(130, 138, 100, 25);
                        lab[4].setFont(new Font("隶书",0,30));
                        lab[4].setForeground(Color.green);
                        lab[4].setBounds(50,50, 200, 200);
                        jp.add(lab[4]);
                        jp.add(txt[3]);
                        
                        lab[5]=new JLabel("学号:");
                        txt[4]=new JTextField();
                        txt[4].setEditable(flage);
                        txt[4].setText(str2);//学号
                        txt[4].setBounds(410, 138, 100, 25);
                        lab[5].setFont(new Font("隶书",0,30));
                        lab[5].setForeground(Color.green);
                        lab[5].setBounds(330,50, 200, 200);
                        jp.add(lab[5]);
                        jp.add(txt[4]);
                        
                        lab[6]=new JLabel("班级编号:");
                        txt[5]=new JTextField();
                        txt[5].setEditable(flage);
                        txt[5].setText(str3);//班级班号
                        txt[5].setBounds(710, 138, 100, 25);
                        lab[6].setFont(new Font("隶书",0,30));
                        lab[6].setForeground(Color.green);
                        lab[6].setBounds(570,50, 200, 200);
                        jp.add(lab[6]);
                        jp.add(txt[5]);
                        
                        lab[7]=new JLabel("简介:");
                        lab[7].setFont(new Font("隶书",0,30));
                        lab[7].setForeground(Color.green);
                        lab[7].setBounds(50, 130, 200, 200);
                        jt=new JTextArea();
                        jt.setEditable(flage);
                        jt.setBackground(Color.darkGray);
                        jt.setForeground(Color.white);
                        jt.setFont(new Font("隶书",0,30));
                        jt.setBounds(50,250,770,160);
                        jp.add(lab[7]);
                        jp.add(jt);
                        
                        bt1=new Button("保存");
                        bt1.setBounds(300,420, 50, 30);
                        bt1.setBackground(Color.green);
                        bt2=new Button("编辑");
                        bt2.setBounds(400,420, 50, 30);
                        bt2.setBackground(Color.green);
                        jp.add(bt1);
                        jp.add(bt2);
//保存按钮的事件监听器                        
                        bt1.addActionListener(new ActionListener(){

                        
                            User user2;
                            public void actionPerformed(ActionEvent e) {
                                // TODO Auto-generated method stub
                           
                                UserDao userdao=new UserImplement();
                                user2=userdao.SgetUser(user.getId());
                                
                                if(user2!=null){
                                    save();
                                    userdao.update(user2);
                                    }
                                else{
                                    System.out.println("1进去了");
                                    
                                    System.out.println("hao"+user.getId());
                                    
                                    System.out.println(txt[5].getText());
                                    save();//弟423
                                }
                            }
                            public void save(){
                                user2.setId(user.getId());//弟427行
                                user2.setName(txt[0].getText());
                                user2.setSex(txt[1].getText());
                                user2.setNumber(txt[5].getText());
                            }
                           
                        });
                        con.add(jp);
                        con.repaint();
                        con.validate();
                    }
                });
                con.add(jp);
                con.repaint();
                con.validate();
            }
        });
        this.setBounds(300, 100, 843,525);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at 界面设计.Student$2$1$1.save(Student.java:427)
    at 界面设计.Student$2$1$1.actionPerformed(Student.java:423)
    at java.awt.Button.processActionEvent(Button.java:409)
    at java.awt.Button.processEvent(Button.java:377)
    at java.(Component.java:4861)
    at java.(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
请帮忙看下,做课程设计连接数据库方面,许多代码没有优化都是临时起意,速求!!!
搜索更多相关主题的帖子: background package private 界面设计 连接数据库 
2015-01-15 08:48
笔墨痕干
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2014-3-24
收藏
得分:0 
回复 4楼 java小蚂蚁
谢谢了,这个当时我又看了一下已经更改过来了。
2015-01-26 14:47
快速回复:请帮忙看下代码,连接数据库的课程设计,有错误改不过来,速求!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024786 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved