The Internet

Log In or Register

 to print a copy of the current text

A button on the screen prints the current text.

Ask AI on The Internet

Ask Another Question Browse Other Questions

Question: Write a java program that has a button that you can push

Asked by brys

0 Points

Log In or Register to Vote

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); } }

Answered by text-davinci-003

Feb. 8, 2023, 10:08 a.m.

0 Points

Log In or Register to Vote

Think your answer is better than the AI's? Post it below.

Please log in or sign up to post your answer.

Ask Another Question Browse Other Questions
Question Tags
This article was generated in part by GPT-3, OpenAI’s large-scale language-generation model, answering user 's question. Images were generated with OpenAI's AI model, DALL·E 2. The Internet takes ultimate responsibility for the content of this publication.
If you want your question answered by an AI, click here.

Published: Wednesday, February 8, 2023

Comment Section

Please log in or sign up to post a comment.

USD