GUI
package Trial;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.toedter.calendar.JDateChooser;
class Demo {
JButton jb1;
JDateChooser c1,c2;
JTextField noofdaystxt;
JButton btn;
Demo() {
JFrame frame = new JFrame();
frame.setTitle("Hancie e-Learning Studio");
frame.setLayout(null);
frame.setSize(600, 500);
frame.setLocationRelativeTo(null);
c1 = new JDateChooser();
c1.setDateFormatString("yyyy-MM-dd");
c1.setBounds(160, 10, 210, 35);
c1.setBorder(BorderFactory.createLineBorder(Color.white, 1));
c1.setFont(new Font("Verdana", Font.PLAIN, 18));
frame.add(c1);
c2 = new JDateChooser();
c2.setDateFormatString("yyyy-MM-dd");
c2.setBounds(160, 60, 210, 35);
c2.setBorder(BorderFactory.createLineBorder(Color.white, 1));
c2.setFont(new Font("Verdana", Font.PLAIN, 18));
frame.add(c2);
noofdaystxt = new JTextField();
noofdaystxt.setBounds(160, 140, 210, 35);
noofdaystxt.setFont(new Font("Verdana", Font.BOLD, 18));
frame.add(noofdaystxt);
btn = new JButton("Calculate");
btn.setBounds(160, 200, 210, 35);
btn.setBorder(BorderFactory.createLineBorder(Color.white, 1));
btn.setFont(new Font("Verdana", Font.BOLD, 18));
frame.add(btn);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
String fromdate = ((JTextField) c1.getDateEditor().getUiComponent()).getText();
String todate = ((JTextField) c2.getDateEditor().getUiComponent()).getText();
LocalDate fday = LocalDate.parse(fromdate);
LocalDate tday = LocalDate.parse(todate);
Long day_gap = ChronoUnit.DAYS.between(fday, tday);
noofdaystxt.setText(String.valueOf(day_gap));
}
catch(Exception ex) {
System.out.println("Error"+ex.getMessage());
}
}
});
frame.setVisible(true);
}
public static void main(String args[]) {
new Demo();
}
}
Output