多線程技術是非常實用的技術
package rick_demo;
import java
import java
import java
import ncurrent
import ncurrent
import ncurrent
import ncurrent
import ncurrent
import java
import javax
public class Test extends JFrame {
private static final long serialVersionUID =
private String[] str=new String[
String bin = new String();
JTextField jf;
JTextArea ja;
JScrollPane jp;
JButton jButton
private static short coin=
JButton jButton
Calendar now;
int hour;
int hourEnd;
int minute;
int minutend;
int second;
int secondend;
int hourend;
int minutePlus;
int secondPlus;
Thread t;
boolean right = true;
public Test() {
setSize(
jf = new JTextField(
ja = new JTextArea(
//ja
jp =new JScrollPane(ja);
jp
jp
for(int i=
str[i] = new String();
jf
jButton
jButton
Container container = getContentPane();
container
container
container
container
container
//獲取系統剛開始運行的初始值
now = Calendar
hourEnd = now
minutePlus = now
secondPlus = now
t = new Thread(new Runnable() {
public void run() {
while (true) {
while (right) {
try {
Thread
jf
} catch (InterruptedException e) {
e
}
}
}
}
});
t
jButton
public void actionPerformed(ActionEvent event) {
right = true;
}
});
jButton
public void actionPerformed(ActionEvent g) {
right = false;
}
});
setVisible(true);
}
public String CalTime() {
now = Calendar
hour = now
minute = now
second = now
if (hourEnd >= hour) {
hourend = hourEnd
secondend =
minutend =
}
return
+
}
public String[] work(){ //多線程關鍵代碼
ExecutorService exec= Executors
ArrayList
for(int i=0;i<10;i++)
results.add(exec.submit(new TaskT(i)));
for(Future
try{
bin = fuck.get() ;
str[coin] = bin;
coin++;
} catch(InterruptedException e){
System.exit(1);
} catch(ExecutionException e){
}
exec.shutdown();
return str;
}
public void setStr(String[] alph){
for(int i=0;i
ja.append(alph[i]+"\n");
}
public static void main(String args[]) {
Test sleep = new Test();
sleep.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
sleep.setStr(sleep.work());
}
}
class TaskT implements Callable
private int id=0;
public TaskT(int id){
this.id=id;
}
public String call(){
return "TaskT "+id;
}
}
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27534.html