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**

Line 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 need to fix that part.

Edited 4 Years Ago by Taywin

everything is working fine but i cant type in the textfield wat is the problem please help me out

Edited 4 Years Ago by anandschiru: mistake

normaly if u click on the any textfield u wl see cursor right but in this i cant even see the cursor and cant even type in texfiled plz help me no james

That's very strange. I can't see anything in the code you posted that would cause that problem. Maybe someone else has a suggestion...?

I 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 result, you don't see a cursor when you click on it or type. Reduce the number to 100 or less and see how it works.

my program is not giving proper output oly. if i click issue button all the text filed should be cleared but its not working like tat and if i click clear button it should take the last date and submitted date input and should find the difference between them. plz help me to solve the problem.

my program is not giving proper output oly. if i click issue button all the text filed should be cleared but its not working like tat and if i click clear button it should take the last date and submitted date input and should find the difference between them. plz help me to solve the problem.taywin

if i click issue button all the text filed should be cleared but its not working

I need to see your latest code you have. In your original code, you have declared text fields in both the class arguments & the init() method arguments. Because of that, the objects added to the panel is from the local variable, not the class arguments you are looking for.

This article has been dead for over six months. Start a new discussion instead.