package tes; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.ImageProducer; import java.net.URL; import java.util.Calendar; @SuppressWarnings("serial") public class ts1 extends Frame implements Runnable{ Image im = null; String[] week = new String[7]; static int yea; //年を入れる変数を宣言 static int mon; //月を入れる変数を宣言 static int day; //日を入れる変数を宣言 static int h; //時を入れる変数を宣言 static int m; //分を入れる変数を宣言 static int s; //秒を入れる変数を宣言 static int week_int; //曜日 boolean a = true; Calendar now = Calendar.getInstance(); public ts1(){ this.setSize(70,160); this.setBackground(new Color(0x00000000, true)); //Mac用背景透過 //this.setBackground(Color.BLUE); //Winならこっちにしてカラーは適当に弄って動くはず。 this.setUndecorated(true); //メニューとかの枠を消してやる。Winではデフォルトで移動させれるか不明だからfalseのほうが無難 new Thread(this).start(); URL url = this.getClass().getResource("/image2.png"); //imageは適当に用意してね! try { im = this.createImage((ImageProducer)url.getContent()); } catch(Exception ex){} //×ボタン用 this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent ev){ System.exit(0); } }); //ここまで×ボタン用 //常に最前表示 this.setAlwaysOnTop(true); //表示 this.setVisible(true); } public static void main(String[] args) { new ts1(); } public void paint(Graphics g){ //Show Image g.drawImage(im,0,25,this); //White Rectangle g.setColor(Color.white); //Make & Show Rectangle g.fillRect(0, 125, 80, 35); g.setColor(Color.black); //g.drawString(yea); //Show Year g.drawString(mon + "/" + day + " (" + week[week_int -1] + ")",0,138); g.drawString(h + ":" + m + ":" + s,0,155); } @SuppressWarnings("static-access") public void run() { while(a==true){ yea = now.getInstance().get(now.YEAR); //年を代入 mon = now.getInstance().get(now.MONTH); //月を代入 day = now.getInstance().get(now.DATE); //日を代入 h = now.getInstance().get(now.HOUR_OF_DAY); //時を代入 m = now.getInstance().get(now.MINUTE); //分を代入 s= now.getInstance().get(now.SECOND); //秒を代入 week[0] = "日"; week[1] = "月"; week[2] = "火"; week[3] = "水"; week[4] = "木"; week[5] = "金"; week[6] = "土"; week_int = now.get(now.DAY_OF_WEEK);//曜日を数値で取得 mon = mon + 1; //なぜかこれがないと月が(現在の月−1)になる。 if(h<9){ //日付の調整。 day = day - 1; week_int -= 1; } h -= 9; if(h == -1){ //時の調整。 h = 23; } else if(h == -2){ h = 22; } else if(h == -3){ h = 21; } else if(h == -4){ h = 20; } else if(h == -5){ h = 19; } else if(h == -6){ h = 18; } else if(h == -7){ h = 17; } else if(h == -8){ h = 16; } else if(h == -9){ h = 15; } repaint(); try{ Thread.sleep(1000); //スリープ1秒 }catch(InterruptedException e){ } } } }