Prompt Title: Adding Date Picker.

Created 1 year ago
Votes 0
Views 426 times
0

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:

  1. Download the JDatePicker library jar file from the internet.
  2. Import the required classes in your code:
arduino
import org.jdatepicker.impl.JDatePanelImpl; import org.jdatepicker.impl.JDatePickerImpl; import org.jdatepicker.impl.SqlDateModel;
  1. Create an instance of the SqlDateModel class, which is used to set the date format:
java
SqlDateModel model = new SqlDateModel();
  1. Create an instance of the JDatePanelImpl class and pass the SqlDateModel object to it:
java
JDatePanelImpl datePanel = new JDatePanelImpl(model);
  1. Create an instance of the JDatePickerImpl class and pass the JDatePanelImpl object to it:
java
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
  1. Add the datePicker object to your GUI and set its position and size:
scss
datePicker.setBounds(350, 200, 200, 25); b.add(datePicker);
  1. To get the selected date, you can use the getValue() method of the SqlDateModel class:
scss
String date = model.getValue().toString();

Here is the modified code with a date picker added:

java
import 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
avatar
Mayur
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

0
0
OIDC token example
1 year ago 2023-03-21 07:53:49 Kim Donghyeon
0
0
Java Web Programming Basics.
1 year ago 2023-03-30 11:25:56 ashwani
0
0
Return byte from url
1 year ago 2023-03-30 11:38:15 MoiseGui
0
0
0
0
0
0
Lab sample management system.
1 year ago 2023-04-08 17:02:15 Boniface Chacha
0
0
Redeclaring Variables in Java.
1 year ago 2023-04-14 05:54:49 Rohit
0
0
Java work report.
1 year ago 2023-04-15 07:36:32 yincx
0
0
Data Exchange (UI to Controller)
1 year ago 2023-04-19 18:17:57 Teja
0
0
Ebook html
1 year ago 2023-04-21 05:07:11 darrat
0
0
Java Developer Summary.
1 year ago 2023-04-21 17:06:40 Himanashu
0
0
Matematika di Java
1 year ago 2023-05-16 02:38:06 mathjava2soal
0
0
Java Class Creation Methods
1 year ago 2023-07-02 08:19:52 Javokhir
0
0
Java syntax
1 year ago 2023-07-04 13:34:54 Dahbi Ayoub
0
0
Java Operators Overview.
1 year ago 2023-08-03 04:48:22 Bhanu Prakash
0
34
CountDownLatch
1 year ago 2023-09-20 07:49:16 qwerty