Instructions
Requirements and Specifications
Source Code
FIRST APP
import java.awt.Font;
import java.awt.event.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import javax.swing.*;
public class App {
public static void main(String[] args) throws Exception {
JFrame f = new JFrame();
JLabel label = new JLabel("");
label.setBounds(250, 10, 300, 100);
label.setFont(new Font("Arial", Font.BOLD, 60));
// add button
JButton button = new JButton("Is it Christmas?");
button.setBounds(200, 200, 200, 100);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get current date
LocalDateTime now = LocalDateTime.now();
// Get day from date
int day = now.getDayOfMonth();
// Get month from date
Month month = now.getMonth();
// Check if it is 24 of December
if(day == 24 && month == Month.DECEMBER)
label.setText("YES");
else
label.setText("NO");
}
});
f.add(label);
f.add(button);
f.setSize(580,350);
f.setLayout(null);
f.setVisible(true);
}
}
SECOND APP
import java.awt.Font;
import java.awt.event.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import javax.swing.*;
public class App {
public static void main(String[] args) throws Exception {
JFrame f = new JFrame();
JLabel label = new JLabel("");
label.setBounds(250, 10, 300, 100);
label.setFont(new Font("Arial", Font.BOLD, 60));
// add button
JButton button = new JButton("Is it Christmas?");
button.setBounds(200, 200, 200, 100);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get current date
LocalDateTime now = LocalDateTime.now();
// Get day from date
int day = now.getDayOfMonth();
// Get month from date
Month month = now.getMonth();
// Check if it is 24 of December
if(day == 24 && month == Month.DECEMBER)
label.setText("YES");
else
label.setText("NO");
}
});
f.add(label);
f.add(button);
f.setSize(580,350);
f.setLayout(null);
f.setVisible(true);
}
}