import javax.swing.*; import java.awt.*; import java.util.*; public class CalendarTest extends JPanel { public CalendarTest() { setPreferredSize(new Dimension(250, 100)); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Calendar now = Calendar.getInstance(); int day = now.get(Calendar.DAY_OF_WEEK); int hour = now.get(Calendar.HOUR_OF_DAY); int min = now.get(Calendar.MINUTE); if (day == Calendar.SUNDAY) { g.setColor(Color.RED); g.drawString("今日は日曜日です。", 30, 25); } if (hour < 12) { g.drawString("おはようございます。", 30, 75); } else if (hour < 18) { g.drawString("こんにちは。", 30, 75); } else { g.drawString("こんばんは。", 30, 75); } g.drawString("ただいま " + hour + "時 " + min + "分です。", 30, 50); // g.drawString(String.format( // "ただいま %d時 %d分です。", hour, min), // 30, 50); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(""); frame.add(new CalendarTest()); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }); } }