Java 今の時間を表示させる
更新日:2018.06.01
作成日:2008.05.31
Java勉強中ですー。自分のためにちゅくちょく書いたコードをブログに載せていこうと思う。
- 第一弾 今の時間を表示させる
import java.applet.*;
import java.util.*;
import java.awt.Button;
import java.awt.event.*;
import java.awt.Graphics;
public class time extends Applet implements ActionListener{
Button b = new Button("now time");
String moji;
public void init(){
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
moji = e.getActionCommand();
repaint();
}
public void paint(Graphics g){
Calendar time= Calendar.getInstance();
int y =time.get(Calendar.YEAR);
int M =time.get(Calendar.MONTH);
int d =time.get(Calendar.DAY_OF_MONTH);
int h =time.get(Calendar.HOUR_OF_DAY);
int m =time.get(Calendar.MINUTE);
int s =time.get(Calendar.SECOND);
if(moji =="now time"){
g.drawString(Integer.toString(y)+ "年",10,30);
g.drawString(Integer.toString(M)+ "月",10,50);
g.drawString(Integer.toString(d)+ "日",10,70);
g.drawString(Integer.toString(h)+ "時",10,90);
g.drawString(Integer.toString(m)+ "分",10,110);
g.drawString(Integer.toString(s)+ "秒",10,130);
}
}
}
Related contents

TECH
2008.11.28
processingによる可視化

TECH
2008.10.12
施設引き継ぎ資料

TECH
2008.08.30
文系的IT業と理系的IT業

TECH
2008.06.30
プログラム

TECH
2008.06.06
数理情報学4 pivot 枢軸選択つきガウスの消去法

TECH
2008.06.03
シュレディンガーの猫

TECH
2011.04.18
大阪EffectiveJava読書会 第1回に行ってきました!!

TECH
2010.09.23
GAEでデータストア登録 -サークルIT化のお手伝い