
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.Border;
import javax.swing.BorderFactory;
import javax.swing.*;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.sql.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Date;
public class add
{
String msg;
JFrame f;
JPanel p;
JTextField l=new JTextField();
JLabel l1=new JLabel("REG.NO");
JTextField t=new JTextField(6);
JLabel l2=new JLabel("NAME");
JTextField t1=new JTextField(15);
JLabel l3=new JLabel("COLLEGE NAME");
JTextField t2=new JTextField(35);
JLabel l4=new JLabel("CONTACT NO");
JTextField t3=new JTextField(11);
JLabel l5=new JLabel("EMAIL-ID ");
JTextField t4=new JTextField(20);
JLabel l6=new JLabel("PROJECT IN");
String project[]={"NETWORK","EMBEDDED","VLSI","HARDWARE","VB.NET","JAVA","ASP.NET","ECE"};
JLabel l7=new JLabel("COURSE");
String course[]={"EMBEDDED SYSTEM","VLSI DESIGN","PLC","PCB
DESIGN","C/C++","JAVA","J2EE","VB.NET","ASP.NET","PHP","NETWORKING","WIRELESS"};
JLabel l8=new JLabel("PROJECT TITLE");
JTextArea title=new JTextArea(3,60);
JLabel l9=new JLabel("AMOUNT");
JTextField t5=new JTextField(7);
JLabel l10=new JLabel("PAID");
JTextField t6=new JTextField(7);
JLabel l11=new JLabel("BALANCE");
JTextField t7=new JTextField(7);
JLabel l12=new JLabel("ADDRESS");
JTextArea address=new JTextArea(4,40);
JButton save=new JButton("SAVE");
JButton clear=new JButton("CLEAR");
JButton print=new JButton("PRINT");
JComboBox c4=new JComboBox(project);
JComboBox c5=new JComboBox(course);
public add()
{
f=new JFrame("ADD NEW STUDENT");
p=new JPanel();
p.setLayout(new GridLayout(0, 3));
l.setText("DATE:"+""+new Date().toString());
l.setForeground(Color.RED);
Border border=BorderFactory.createLineBorder(Color.BLUE,3);
l.setBorder(border);
p.add(l);
p.add(l1);
p.add(t);
p.add(l2);
p.add(t1);
p.add(l3);
p.add(t2);
p.add(l4);
p.add(t3);
p.add(l5);
p.add(t4);
p.add(l6);
p.add(c4);
p.add(l7);
p.add(c5);
p.add(l8);
p.add(title);
p.add(l9);
p.add(t5);
p.add(l10);
p.add(t6);
p.add(l11);
p.add(t7);
p.add(l12);
p.add(address);
p.add(save);
p.add(clear);
p.add(print);
clear.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
t.setText("");
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
address.setText("");
title.setText("");
}
});
save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String date=l.getText();
double regno=Double.parseDouble(t.getText());
String name=t1.getText();
String college=t2.getText();
double contactno=Double.parseDouble(t3.getText());
String email=t4.getText();
String project=c4.getSelectedItem().toString();
String course=c5.getSelectedItem().toString();
String Title=title.getText();
double amount=Double.parseDouble(t5.getText());
double paid=Double.parseDouble(t6.getText());
double balance=Double.parseDouble(t7.getText());
String Address=address.getText();
Connection con=null;
Statement st=con.createStatement();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student");
int query=st.executeUpdate("INSERT INTO student"
+"(date,regno,name,college,contactno,email,Project,course,Title,amount,paid,balance,Address)"+"VALUES(?,?,?,?,?,?
,?,?,?,?,?,?,?)");
JOptionPane.showMessageDialog(null, "Succesfully
Saved.","Information",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception eex)
{
eex.printStackTrace();
}
}
});
f.add(p, BorderLayout.CENTER);
f.add(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800,800);
f.setVisible(true);
}
public static void main(String[] args)
{
add a=new add();
}
}
when i run this program... it shows the given below errors.pls clear the errors and give me correct tutorial for my knowledge improving.pls anyone help me.
E:\>java add
java.lang.NullPointerException
at add$2.actionPerformed(add.java:143)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1
95)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.ja
a:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonMode
.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:24
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButton
istener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:457
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThr
ad.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread
java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
ad.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.