import java.util.Calendar; public class TimeThread extends Frame implements Runnable { int year; int month; int day; int h; int m; int s; boolean a = true; Calendar now = Calendar.getInstance();
public void Timethread(){ } public void run(){ while(a==true){ year = Calendar.getInstance().get(Calendar.YEAR); month = Calendar.getInstance().get(Calendar.MONTH); month = month+1; day = Calendar.getInstance().get(Calendar.DATE); h = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); m = Calendar.getInstance().get(Calendar.MINUTE); s= Calendar.getInstance().get(Calendar.SECOND); try{ Thread.sleep(1000); //スリープ1秒 }catch(InterruptedException e){ } } } public int getYear(){ return year; } public int getMonth(){ return month; } public int getDay(){ return day; } public int getH(){ return h; } public int getM(){ return m; } public int getS(){ return s; } } ==================================================== import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame;
public class PanelMain { static TimeThread f = new TimeThread(); static Thread th = new Thread(f); static int year; static int month; static int day; static int h; static int m; static int s; public static void main(String[] args) { JFrame frame = new JFrame("フレームタイトル"); frame.setBounds(100, 100, 700, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);