A java Exception has occurred怎么解决?

FleetingTiming 2014-10-20 07:57:13
运行java连接access的通讯录时,出现A java Exception has occurred,好像是BeginFrame对象有问题,可是检查不出来,请大家帮帮忙~~~谢谢啦~~~
这是BeginFrame类:
import java.awt.*;
import javax.swing.*;
public class BeginFrame extends JFrame{
private static final long serialVersionUID = 1L;
JLabel label;
Container contentPane;
public BeginFrame() {
super("PB");
this.setJMenuBar(new CreateMenu().menubar); //创建一个菜单条
label = new JLabel(new ImageIcon("balloon.jpg"));//通过label添加背景图片
contentPane=this.getContentPane(); //创建一个新面板
contentPane.add(label,BorderLayout.CENTER); //将label放到中间
contentPane.setBackground(Color.cyan);//设置背景颜色

Toolkit tool=getToolkit();//得到一个Toolkit对象
Image image=tool.getImage("balloon.jpg");//由tool获取图像
this.setIconImage(image);
this.setLocation(430, 230); //设置窗口大小
this.setSize(500, 400);//设置窗口位置
this.setVisible(true); //设置是否可见
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//仅在应用程序中使用,结束应用程序
}
}

这是与它相关的一个类,错好像是从这儿出来的:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
public class CreateMenu implements ActionListener{
JMenuBar menubar=new JMenuBar();
JMenuItem menuitem1,menuitem2,menuitem3,menuitem4,menuitem21,menuitem22,menuitem23,menuitem24,menuitem31;
public CreateMenu() {

menuitem1.addActionListener(this);
menuitem2.addActionListener(this);
menuitem3.addActionListener(this);
menuitem4.addActionListener(this);


menuitem1.setForeground(Color.red);
menuitem1.setBackground(Color.cyan);//设置背景颜色
menuitem2.setForeground(Color.red);
menuitem2.setBackground(Color.cyan);//设置背景颜色
menuitem3.setForeground(Color.red);
menuitem3.setBackground(Color.cyan);//设置背景颜色
menuitem4.setForeground(Color.red);
menuitem4.setBackground(Color.cyan);//设置背景颜色


JMenu menu2=new JMenu("电话本管理(W)");
menu2.setMnemonic('W');

menuitem21=new JMenuItem("添加信息");
menuitem22=new JMenuItem("修改信息");
menuitem23=new JMenuItem("删除信息");
menuitem24=new JMenuItem("统计联系人");
menuitem21.addActionListener(this);
menuitem22.addActionListener(this);
menuitem23.addActionListener(this);
menuitem24.addActionListener(this);

menuitem21.setEnabled(false);
menuitem22.setEnabled(false);
menuitem23.setEnabled(false);
menuitem24.setEnabled(false);
menuitem4.setEnabled(false);

menu2.add(menuitem21);
menu2.add(menuitem22);
menu2.add(menuitem23);
menu2.add(menuitem24);
menubar.add(menu2);

menu2.setForeground(Color.blue);
menuitem21.setForeground(Color.red);
menuitem21.setBackground(Color.cyan);//设置背景颜色
menuitem22.setForeground(Color.red);
menuitem22.setBackground(Color.cyan);//设置背景颜色
menuitem23.setForeground(Color.red);
menuitem23.setBackground(Color.cyan);//设置背景颜色
menuitem24.setForeground(Color.red);
menuitem24.setBackground(Color.cyan);//设置背景颜色

JMenu menu3=new JMenu("关于(L)");
menu3.setMnemonic('L');
menuitem31=new JMenuItem("关于作者");
menu3.add(menuitem31);
menuitem31.addActionListener(this);
menubar.add(menu3);

menu3.setForeground(Color.blue);//设置前景颜色
menuitem31.setForeground(Color.red);//设置前景颜色
menuitem31.setBackground(Color.cyan);//设置背景颜色

menubar.setBackground(Color.yellow);//设置背景颜色


}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==menuitem4) {System.exit(0);}
else if(e.getSource()==menuitem21){new ButtonPanel.Add().actionPerformed(e);}
else if(e.getSource()==menuitem22){modify(e);}
else if(e.getSource()==menuitem23){new ButtonPanel.Del().actionPerformed(e);}
else if(e.getSource()==menuitem24){JOptionPane.showMessageDialog(null,"本通讯录共有"+NamePanel.length+"条记录!","统计",JOptionPane.INFORMATION_MESSAGE);}
else if(e.getSource()==menuitem31){JOptionPane.showMessageDialog(null,"本软件作者:李富强!","关于作者",JOptionPane.INFORMATION_MESSAGE);
}
}
private void modify(ActionEvent event) {
if(NamePanel.nameList.isSelectionEmpty()){
JOptionPane.showMessageDialog(null,"必须先选定才能修改!","提示",JOptionPane.INFORMATION_MESSAGE);
}
else{
MainFrame.centerPanel1.setFieldEditable(true,false);
ButtonPanel.modifybutton.setText("保存修改");

if(event.getActionCommand().equals("保存修改")){

String selectName = NamePanel.getSelectedText();
String inputPhone1 = MainFrame.centerPanel1.getPhonenum1Text();
String inputPhone2 = MainFrame.centerPanel1.getPhonenum2Text();
String inputHomePhone = MainFrame.centerPanel1.getHomenumText();

String inputMail = MainFrame.centerPanel1.getMailText();
String inputQQ = MainFrame.centerPanel1.getQQText();
String inputWorkunit = MainFrame.centerPanel1.getWorkunitText();
String inputAddress = MainFrame.centerPanel1.getAddressText();

String sql="update phonetable set phoneNumber1='"+inputPhone1+"',phoneNumber2='"+inputPhone2+"',homeNumber='"+inputHomePhone+"',mail='"+inputMail+"',qq='"+inputQQ+"',workUnit='"+inputWorkunit+"',address='"+inputAddress+"' where name='"+selectName+"' ";

ConnectionData conObject=new ConnectionData();//建立连接
int result=0;
result=conObject.UpdateData(sql);
if(result!=0){
JOptionPane.showMessageDialog(null,"用户["+selectName+"]的信息更新成功!","提示",JOptionPane.INFORMATION_MESSAGE);
NamePanel.refresh(); //////////////////////////////刷新面板//////////////////////
}
conObject.closeData(); //断开连接
ButtonPanel.modifybutton.setText("修改");
MainFrame.centerPanel1.setFieldEditable(false,false);
}
}
}
}
...全文
297 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,503

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧