package com.wangluo08.design; import java.io.*; import java.util.*; import javax.swing.*; import java.awt.event.*; public class Tips extends JFrame { /** * Var * */ String tips=""; File tipFile=new File("tip.txt"); /** * Methods * */ //构造方法 public Tips(File tipFile) { this.tipFile=tipFile; } //增加tip public void addTips() { } //清除tip public void clearTips(){ //如果所有tips都过期则清除文件内容 } public String readTips() { String tips=this.tips; return tips; } //初始化 public void init(){ } } /** * XML * */ package lab; public class Lab1_1 extends Thread { int count=0; String[] array={"tree","flower","grass","leaf","plant"}; public static void main(String[] args) { Lab1_1 th=new Lab1_1(); //创建线程 th.start(); //启动线程 } public void run() //执行方法 { while (true) { try {sleep(500);} //主线程休眠500毫秒 catch(InterruptedException e){} System.out.println(array[count++]); if(count>4) count=0; } } } package lab; public class Lab1_2 implements Runnable { Thread th; int count=0; String[] array={"tree","flower","grass","leaf","plant"}; public Lab1_2() { th=new Thread(this); //创建线程 th.start(); //启动线程 } public static void main(String[] args) { new Lab1_2(); } public void run() //执行方法 { while (true) { try {th.sleep(500);} //主线程休眠500毫秒 catch(InterruptedException e){} System.out.println(array[count++]); if(count>4) count=0; } } } package lab; public class Lab2_1 extends Thread { int count1=0,count2=0; String[] array1={"tree","flower","grass","leaf","plant"}; String[] array2={"sun","star","moon","sky"}; public static void main(String[] args) { Lab2_1 th1=new Lab2_1(); //创建线程 Lab2_1 th2=new Lab2_1(); th1.setName("thread1"); //命名线程 th2.setName("thread2"); th1.start(); //启动线程 th2.start(); } public void run() //执行方法 { while (true) { try {sleep(2000);} //主线程休眠500毫秒 catch(InterruptedException e){} if((Thread.currentThread().getName()).equals("thread1")) { System.out.println(array1[count1++]); if(count1>4) count1=0; } else { System.out.println(array2[count2++]); if(count2>3) count2=0; } } } }