Ask AI on The Internet
Ask Another Question Browse Other QuestionsQuestion: Write a java program that has a button that you can push
when you want to find the number of days since 1/1/2001 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; import javax.swing.*; public class DaysSince { public static void main(String[] args) { JFrame frame = new JFrame("Days Since 1/1/2001"); JButton btn = new JButton("Find Number of Days Since 1/1/2001"); btn.setBounds(150,100,200, 40); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Date startDate = new Date(2001,1,1); Date endDate = new Date(); long startTime = startDate.getTime(); long endTime = endDate.getTime(); long diffTime = endTime - startTime; long diffDays = diffTime / (1000 * 60 * 60 * 24); JOptionPane.showMessageDialog(frame, "Number of Days Since 1/1/2001: " + diffDays); } }); frame.add(btn); frame.setSize(500,500); frame.setLayout(null); frame.setVisible(true); } }
Feb. 8, 2023, 10:08 a.m.
Think your answer is better than the AI's? Post it below.
Question Tags
If you want your question answered by an AI, click here.
Comment Section
Please log in or sign up to post a comment.