Skip to content

Instantly share code, notes, and snippets.

@Myoga1012
Last active January 30, 2023 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Myoga1012/95d58332b9bb690eb118 to your computer and use it in GitHub Desktop.
Save Myoga1012/95d58332b9bb690eb118 to your computer and use it in GitHub Desktop.
Java(アプレット)でカレンダーを出力するソースコードです。
// 名前 : Myoga Screw-bright (旧名:Myoga S. Tomonaka)
// Twitter : https://twitter.com/Myoga1012
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Calendar;
import java.util.Locale;
public class AppletCalendar extends Applet {
private static final long serialVersionUID = 1L;
private Calendar now;
private int first;
private int last;
public void init(){
// 現在の日付を取得し、1日の曜日と末日を求めます。
now = Calendar.getInstance();
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), 1);
Calendar next = (Calendar) now.clone();
next.setLenient(true);
first = now.get(Calendar.DAY_OF_WEEK) - 1; // SUNDAY : 1、MONDAY : 2、・・・
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), 1);
next.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), 0);
last = next.get(Calendar.DATE);
}
public void paint(Graphics g){
setBackground(Color.white);
g.drawString(String.format( Locale.US,"%1$tY %1$tB", now), 20, 20);
// カレンダーを出力します。
for( int seq = first, curDay = 1; curDay <= last; seq++, curDay++ ){
g.drawString(String.format("%1$2d", curDay), 20 + ( seq % 7 ) * 20, 50 + ( seq / 7 ) * 20);
}
}
}
// Calender.java( For Javaアプレット )
//Copyright (c) 2014 Myoga-TN.net All Rights Reserved.
//This software is released under the MIT License.
//http://opensource.org/licenses/mit-license.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment