能编译过去,运行就不出!高手看看啊!谢谢,把连数据库的注释了也不行,提示:java.lang.NullPointerException哪不对啊?不胜感激!!!import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;
public class StudentDataUpdate extends JFrame// implements KeyListener,ActionListener
{
String title[]={"班级","学号","姓名","性别","出生日期","团员否","家庭住址","简历"};
JComboBox ClassId=new JComboBox();
JTextField txtNo;
JTextField txtName;
JTextField txtBirthday;
JTextField txtAddress;
JTextArea resume;
JRadioButton sexM=new JRadioButton("男");
JRadioButton sexF=new JRadioButton("女");
JCheckBox member=new JCheckBox("",false);
JButton ok=new JButton("保存");
JButton cancle=new JButton("取消");
// Container conn=getContentPane();
// conn.setLayout(new BorderLayout(0,5));
Statement stmt;
ResultSet rs;
int No;
public StudentDataUpdate(int No)
{
setSize(450,390);
setVisible(true);
this.No=No;
if(No==-1) setTitle("添加学生信息窗口");
else setTitle("修改学生信息窗口"); //conn.setLayout(new BorderLayout(1,8));
try{
Container conn=getContentPane();
conn.setLayout(new BorderLayout());
Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序
String url="jdbc:odbc:stuinfo";//指定数据库
con=DriverManager.getConnection(url);//通过驱动管理器建立连接
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//创建一个对象将SQL语句发送到数据库
String sqlstmt="select * from student ";
rs=stmt.executeQuery(sqlstmt);
/* while(rs.next())
{ClassId.addItem(rs.getString(1));} */
ClassId.addItem("10601D1");
ClassId.addItem("10601D2");
ClassId.addItem("10601D3");
ButtonGroup sex=new ButtonGroup();
sex.add(sexM);
sex.add(sexF); JPanel []p1=new JPanel[7];
for(int i=0;i<7;i++)
{
p1[i]=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2));
p1[i].add(new Label(title[i]));
}
p1[0].add(ClassId);
p1[1].add(txtNo);
p1[2].add(txtName);
p1[3].add(sexM);
p1[3].add(sexF);
p1[4].add(txtBirthday);
p1[5].add(member);
p1[6].add(txtAddress);
JPanel pane=new JPanel(new GridLayout(7,1,0,5));
for(int i=0;i<7;i++)
pane.add(p1[i]);
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2));
JScrollPane jp=new JScrollPane(resume,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jp.setPreferredSize(new Dimension(370,80));
p2.add(new Label(title[7]));
p2.add(jp);
JPanel p3=new JPanel(new FlowLayout(FlowLayout.CENTER,2,2));
p3.add(ok);
p3.add(cancle);
conn.add(pane,"North");
conn.add(p2,"Center");
conn.add(p3,"South");
conn.add(new JButton("是"));
}catch(Exception e){
System.out.println(e.toString());
}
setVisible(true);
//show();
}
public static void main(String []args)
{
/* JFrame.setDefaultLookAndFeelDecorated(true);
Font font=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()){
Object key=keys.nextElement();
if(UIManager.get(key) instanceof Font) UIManager.put(key,font);
} */
StudentDataUpdate main1=new StudentDataUpdate(2);
}
}
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;
public class StudentDataUpdate extends JFrame// implements KeyListener,ActionListener
{
String title[]={"班级","学号","姓名","性别","出生日期","团员否","家庭住址","简历"};
JComboBox ClassId=new JComboBox();
JTextField txtNo;
JTextField txtName;
JTextField txtBirthday;
JTextField txtAddress;
JTextArea resume;
JRadioButton sexM=new JRadioButton("男");
JRadioButton sexF=new JRadioButton("女");
JCheckBox member=new JCheckBox("",false);
JButton ok=new JButton("保存");
JButton cancle=new JButton("取消");
// Container conn=getContentPane();
// conn.setLayout(new BorderLayout(0,5));
Statement stmt;
ResultSet rs;
int No;
public StudentDataUpdate(int No)
{
setSize(450,390);
setVisible(true);
this.No=No;
if(No==-1) setTitle("添加学生信息窗口");
else setTitle("修改学生信息窗口"); //conn.setLayout(new BorderLayout(1,8));
try{
Container conn=getContentPane();
conn.setLayout(new BorderLayout());
Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序
String url="jdbc:odbc:stuinfo";//指定数据库
con=DriverManager.getConnection(url);//通过驱动管理器建立连接
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//创建一个对象将SQL语句发送到数据库
String sqlstmt="select * from student ";
rs=stmt.executeQuery(sqlstmt);
/* while(rs.next())
{ClassId.addItem(rs.getString(1));} */
ClassId.addItem("10601D1");
ClassId.addItem("10601D2");
ClassId.addItem("10601D3");
ButtonGroup sex=new ButtonGroup();
sex.add(sexM);
sex.add(sexF); JPanel []p1=new JPanel[7];
for(int i=0;i<7;i++)
{
p1[i]=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2));
p1[i].add(new Label(title[i]));
}
p1[0].add(ClassId);
p1[1].add(txtNo);
p1[2].add(txtName);
p1[3].add(sexM);
p1[3].add(sexF);
p1[4].add(txtBirthday);
p1[5].add(member);
p1[6].add(txtAddress);
JPanel pane=new JPanel(new GridLayout(7,1,0,5));
for(int i=0;i<7;i++)
pane.add(p1[i]);
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2));
JScrollPane jp=new JScrollPane(resume,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jp.setPreferredSize(new Dimension(370,80));
p2.add(new Label(title[7]));
p2.add(jp);
JPanel p3=new JPanel(new FlowLayout(FlowLayout.CENTER,2,2));
p3.add(ok);
p3.add(cancle);
conn.add(pane,"North");
conn.add(p2,"Center");
conn.add(p3,"South");
conn.add(new JButton("是"));
}catch(Exception e){
System.out.println(e.toString());
}
setVisible(true);
//show();
}
public static void main(String []args)
{
/* JFrame.setDefaultLookAndFeelDecorated(true);
Font font=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()){
Object key=keys.nextElement();
if(UIManager.get(key) instanceof Font) UIManager.put(key,font);
} */
StudentDataUpdate main1=new StudentDataUpdate(2);
}
}
解决方案 »
- LinkedHashSet的问题
- Swing实现鼠标动态调整面板大小
- Java 和visualc/c++相比, 哪一个更难一些????
- tomcat java 现在配置出了点问题,大家帮我看看,在线等,急!!!!!!!!!!!!!
- 问一个对于大家来说很简单的Socket问题
- 《Struts in action》 非常全面的Struts教程下载
- oracle的jdbc驱动必须安装?还是只要在ClassPath里指定了几个.jar包 就可以用了?
- 学校要做公开课大家说我讲集合框架时,必须要讲哪几个类和接口,在开发中比较常用的,感谢大家
- 我们一般在java中会常用到哪些数据结构啊?
- 如何读取一个inputstream两遍
- arraylist 去除相同值问题!!!!
- 为什么jcreator3.5装了用不了!! 急求解决!!
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
import java.text.*;class InterestCalculator extends JFrame implements ActionListener{
JLabel l1=new JLabel("本金");
JLabel l2=new JLabel("利率");
JLabel l3=new JLabel("存款年数");
JLabel l4=new JLabel("每年年终金额总计");
JTextField t1=new JTextField(7);
JTextField t2=new JTextField(7);
JTextField t3=new JTextField(7);
Container contentPane=getContentPane();
JTextArea ta=new JTextArea(5,15);
JScrollPane sp=new JScrollPane(ta);
JButton b=new JButton("计算");
JPanel p=new JPanel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
JPanel p6=new JPanel();
InterestCalculator(){
sp.setBounds(16,160,300,92);
contentPane.add(sp);
p.setLayout(new BorderLayout());
p.add(p1,BorderLayout.NORTH);
p.add(p2,BorderLayout.CENTER);
p1.setLayout(new GridLayout(4,1));
p1.add(p3);
p1.add(p4);
p1.add(p5);
p1.add(p6);
p3.add(l1);
p3.add(t1);
p3.add(b);
p4.add(l2);
p4.add(t2);
p5.add(l3);
p5.add(t3);
p6.add(l4);
p2.add(contentPane);
ta.setEditable(false);
b.addActionListener(this);
this.setContentPane(p);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("利息计算器");
this.setSize(200,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource().equals(b))
{
int i;
double s;
DecimalFormat df=new DecimalFormat("0.00");
ta.setText("年份\t年终金额");
for(i=1;i<=Integer.parseInt(t3.getText());i++)
{
s=Integer.parseInt(t1.getText())*Math.pow((1+0.1),i);
ta.setText(ta.getText()+"\n"+ i +"\t" + "RMB" + df.format(s));
}
}
}
public static void main(String[] args){
new InterestCalculator();
}
}[/code]