import javax.swing.* ;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.Calendar;
import java.util.*;
import java.text.*;
/*
<applet code="gui.class" width=250 height=100>
</applet>
*/
class gui extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4,t5;
JLabel l1,l2,l3,l4,l5,l6;
JButton b1,b2;
Calendar c1,c2,c3;
JPanel p,p1,p2;
Date sd,sd1;
SimpleDateFormat sdf;
public void init()
{
SimpleDateFormat sdf = new SimpleDateFormat(“DD/MM/YYYY");
final JTextField t1 = new JTextField(1000);
final JTextField t2 = new JTextField(1000);
final JTextField t3 = new JTextField(1000);
final JTextField t4 = new JTextField(1000);
final JTextField t5 = new JTextField(1000);
JLabel l6 = new JLabel("");
JLabel l1 = new JLabel("Book Name");
JLabel l2 = new JLabel("Author Namae");
JLabel l3 = new JLabel("Issue Date");
JLabel l4 = new JLabel("Last Date");
JLabel l5 = new JLabel("Submitted Date");
JButton b1=new JButton("Issue");
JButton b2=new JButton("Clear");
setLayout(new BorderLayout());
JPanel P=new JPanel();
p.add(l1);
p.add(l2);
p.add(l3);
p.add(l4);
p.add(l5);
JPanel P1=new JPanel();
p1.add(t1);
p1.add(t2);
p1.add(t3);
p1.add(t4);
p1.add(t5);
add(p,BorderLayout.WEST);
add(p1,BorderLayout.EAST);
JPanel P2=new JPanel();
p2.add(b1);
p2.add(b2);
add(p2,BorderLayout.SOUTH);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s,s1,s2,s3;
s=e.getActionCommand();
if(s.equals("Issue"))
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
}
else
{
s2=t4.getText();
s3=t5.getText();
try{
sd=sdf.parse(s2);
sd1=sdf.parse(s3);
long day1=(sd1.getTime() - sd.getTime()) ;
long day=day1/(24*60*60*1000) ;
if(day <= 0)
{
l6.setText("no fine");
}
else
{
l6.setText("fine of Rs" +day);
}
} //try close
catch (ParseException se)
{
System.out.println("Exception :"+se);
}
} //else close
}
}
**Java.lang.NullpointerException
at gui.init<gui.java:49>
at sun.applet.Appletpanel.run<Appletpanel.java:434
at java.lang.thread.run<Thread.java:722> ** **I WILL BE VERY THANKFULL IF ANY ONE HELP ME OUT IN THIS PLZ HELP ME TO SOLVE THIS PROBLEM**
import javax.swing.* ;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.Calendar;
import java.util.*;
import java.text.*;
/*
<applet code="gui.class" width=250 height=100>
</applet>
*/
class gui extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4,t5;
JLabel l1,l2,l3,l4,l5,l6;
JButton b1,b2;
Calendar c1,c2,c3;
JPanel p,p1,p2;
Date sd,sd1;
SimpleDateFormat sdf;
public void init()
{
SimpleDateFormat sdf = new SimpleDateFormat(“DD/MM/YYYY");
final JTextField t1 = new JTextField(1000);
final JTextField t2 = new JTextField(1000);
final JTextField t3 = new JTextField(1000);
final JTextField t4 = new JTextField(1000);
final JTextField t5 = new JTextField(1000);
JLabel l6 = new JLabel("");
JLabel l1 = new JLabel("Book Name");
JLabel l2 = new JLabel("Author Namae");
JLabel l3 = new JLabel("Issue Date");
JLabel l4 = new JLabel("Last Date");
JLabel l5 = new JLabel("Submitted Date");
JButton b1=new JButton("Issue");
JButton b2=new JButton("Clear");
setLayout(new BorderLayout());
JPanel P=new JPanel();
p.add(l1);
p.add(l2);
p.add(l3);
p.add(l4);
p.add(l5);
JPanel P1=new JPanel();
p1.add(t1);
p1.add(t2);
p1.add(t3);
p1.add(t4);
p1.add(t5);
add(p,BorderLayout.WEST);
add(p1,BorderLayout.EAST);
JPanel P2=new JPanel();
p2.add(b1);
p2.add(b2);
add(p2,BorderLayout.SOUTH);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s,s1,s2,s3;
s=e.getActionCommand();
if(s.equals("Issue"))
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
}
else
{
s2=t4.getText();
s3=t5.getText();
try{
sd=sdf.parse(s2);
sd1=sdf.parse(s3);
long day1=(sd1.getTime() - sd.getTime()) ;
long day=day1/(24*60*60*1000) ;
if(day <= 0)
{
l6.setText("no fine");
}
else
{
l6.setText("fine of Rs" +day);
}
} //try close
catch (ParseException se)
{
System.out.println("Exception :"+se);
}
} //else close
}
}
**Java.lang.NullpointerException
at gui.init<gui.java:49>
at sun.applet.Appletpanel.run<Appletpanel.java:434
at java.lang.thread.run<Thread.java:722> ** **I WILL BE VERY THANKFULL IF ANY ONE HELP ME OUT IN THIS PLZ HELP ME TO SOLVE THIS PROBLEM**
anandschiru
-1
Light Poster
Recommended Answers
Jump to PostLine 47 & 54, you declare variable P and P1 (capital letters), but then later on you use p and p1 (lower case letters) which is going to be null. In Java, variable name is case-sensitive. In other words, capital P is not equal to lower case letter p. You …
Jump to PostWhat EXACTLY happens when you try to type in which text field?
Jump to PostI am guessing that your setup for JTextfield is too large. Look at line 29~33, you set its column value to 1000!!! When you add it in your display, the cursor is on the right most in the field but is already way off (hidden) from the display. As a …
All 9 Replies
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
anandschiru
-1
Light Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
anandschiru
-1
Light Poster
Taywin
312
Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.