Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Forked from Myoga1012/Calendar.java
Created January 30, 2023 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nia-TN1012/27493240b6dfdb060cd84893ea15dd36 to your computer and use it in GitHub Desktop.
Save Nia-TN1012/27493240b6dfdb060cd84893ea15dd36 to your computer and use it in GitHub Desktop.
Java(アプレット)でカレンダーを出力するソースコードです。
// 名前 : Nia Tomonaka
// Twitter : https://twitter.com/nia_tn1012
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-2023 Nia T.N. Tech Lab. / Chronoir.net.
//This software is released under the MIT License.
//http://opensource.org/licenses/mit-license.php
@Nia-TN1012
Copy link
Author

GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。

旧URL: https://gist.github.com/Myoga1012/95d58332b9bb690eb118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment