Prompt Detail:
To add a date picker in this code, you can use the JDatePicker library which provides a nice GUI-based date picker. Here are the steps to add a date picker in this code:
- Download the JDatePicker library jar file from the internet.
- Import the required classes in your code:
arduinoimport org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.SqlDateModel;
- Create an instance of the SqlDateModel class, which is used to set the date format:
javaSqlDateModel model = new SqlDateModel();
- Create an instance of the JDatePanelImpl class and pass the SqlDateModel object to it:
javaJDatePanelImpl datePanel = new JDatePanelImpl(model);
- Create an instance of the JDatePickerImpl class and pass the JDatePanelImpl object to it:
javaJDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
- Add the datePicker object to your GUI and set its position and size:
scssdatePicker.setBounds(350, 200, 200, 25);
b.add(datePicker);
- To get the selected date, you can use the getValue() method of the SqlDateModel class:
scssString date = model.getValue().toString();
Here is the modified code with a date picker added:
javaimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import java.sql.ResultSet;
import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.SqlDateModel;
public class DailyPurchaseReport extends JFrame implements ActionListener
{
JFrame jf;
JLabel b;
ImageIcon img;
JButton submit,clear;
JLabel l1,ln;
JTextField t1;
Font f;
Connection con;
PreparedStatement ps;
Statement stmt;
ResultSet rs;
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);
SqlDateModel dateModel = new SqlDateModel();
JDatePanelImpl datePanel = new JDatePanelImpl(dateModel);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
public DailyPurchaseReport()
{
jf=new JFrame();
img=new ImageIcon("images//61804.jpg");
b=new JLabel("",img,JLabel.CENTER);
b.setBounds(0,0,800,600);
jf.add(b);
//setVisible(true);
f = new Font("Arial",Font.BOLD,20);
b.setLayout(null);
ln = new JLabel("Daily purchase report");
ln.setFont(new Font("Arial",Font.BOLD,30));
ln.setForeground(Color.black);
ln.setHorizontalAlignment(JLabel.CENTER);
ln.setBounds(0,30,900,40);
ln.setForeground(Color.black);
b.add(ln);
l1 = new JLabel("Enter purchase report date");
l1.setFont(new Font("Arial",Font.BOLD,18));
l1.setHorizontalAlignment(JLabel.CENTER);
l1.setBounds(0,150,900,40);
l1.setForeground(Color.black);
b.add(l1);
l1.setForeground(Color.black);
datePicker.setBounds(350, 200, 200, 25);
b.add(datePicker);
submit = new JButton("Submit",new ImageIcon("images//open.png"));
submit.setBounds(285,250,135,35);
submit.setToolTipText("click to open daily purchase report");
b.add(submit);
submit.addActionListener(this);
clear = new JButton
Add a comment