import javax.swing.* ;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.Calendar;
import java.util.*;
import java.text.*;
import java.util.Date;
/*
<applet code="gui.class" width=250 height=100>
</applet>
*/
public class gui1 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(10);
final JTextField t2 = new JTextField(10);
final JTextField t3 = new JTextField(10);
final JTextField t4 = new JTextField(10);
final JTextField t5 = new JTextField(10);
JLabel l6 = new JLabel("fine");
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.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
p.add(l1);
p.add(l2);
p.add(l3);
p.add(l4);
p.add(l5);
JPanel p1=new JPanel();
p1.setLayout(new BoxLayout(p1,BoxLayout.Y_AXIS));
p1.add(t1);
p1.add(t3);
p1.add(t2);
p1.add(t4);
p1.add(t5);
add(p,BorderLayout.WEST);
add(p1,BorderLayout.EAST);
JPanel p2=new JPanel();
p2.add(b1);
p2.add(b2);
p2.add(l6);
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("");
}
if(s.equals("Clear"))
{
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
}
}
This is my new code i have just added the card layout tats all sir **taywin**
Recommended Answers
Jump to PostUpdate lines 30~34 (remove the part
final JTextField
) because they are local & you added these local variables instead of the class variables.// should look similar to below t1 = new JTextField(10); t2 = new JTextField(10); t3 = new JTextField(10); t4 = new JTextField(10); …
Jump to PostPlease explain what "not working" whenever you ask a question. Often times, I won't know what the meaning of "not working" and it is difficult to assume.
Now, my assumption from your "not working" is from many causes.
1) Line 28, the pattern string of a SimpleDateFormat does NOT have …
Jump to PostPlease look at my previous post and adjust your code accordingly. Your SimpleDateFormat should throw an exception while running because it doesn't recognize the format "DD/MM/YYYY" because the "Y" does not exist in its string pattern list.
Also, I'm guessing that your t5 field is the last date and the …
Jump to PostThe parsing will throw exception if the values in t4 and t5 do not follow the format. For example, you want 14 November, 2011 to be the value of t4 and 1 December, 2011 to be in t5, you must enter 14112011 in t4 field and 01122011 in t5. If …
Jump to PostIn your original posted code, between line 100 and 101, insert this line of code to see whether the string from getText() from your text field object is correct.
System.out.println("T4: "+s2+" | T5: "+s3);
After you run and tried it, look in the command window (the …
All 29 Replies
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
anandschiru
-1
Light Poster
Taywin
312
Posting Virtuoso
jalpesh_007
commented:
nice example
+2
anandschiru
-1
Light Poster
anandschiru
-1
Light Poster
stultuske
1,116
Posting Maven
Featured Poster
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
anandschiru
-1
Light Poster
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
anandschiru
-1
Light Poster
anandschiru
-1
Light Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured 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
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
anandschiru
-1
Light Poster
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.