91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 50KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-18
  • 語言: 其他
  • 標簽: thread??java??

資源簡介

創(chuàng)建3個線程,每個線程的工作是在自己的界面隨機的顯示26個字母中的一個;可通過界面按鈕,臨時掛起或回復各線程的運行。

資源截圖

代碼片段和文件信息

package?randomcharacter;
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?RandomCharacter?extends?Japplet?implements?ActionListener{
????private?String?allchars?=?“ABCDEFGHIJKLMNOPQRSTUVWXYZ“;
????private?final?static?int?SIZE?=?3;
????private?JLabel?[]outputs;
????private?JCheckBox?[]checkBoxes;
????private?Thread?[]threads;
????private?boolean?[]suspended;
????static?int?count?=?0;

????public?void?init(){
????????outputs?=?new?JLabel[SIZE];
????????checkBoxes?=?new?JCheckBox[SIZE];
????????threads?=?new?Thread[SIZE];
????????suspended?=?new?boolean[SIZE];
????????Container?container?=?getContentPane();
????????container.setLayout(new?GridLayout(SIZE255));

????????for(int?count?=?0;count????????????outputs[count]?=?new?JLabel();
????????????outputs[count].setBackground(Color.GREEN);
????????????outputs[count].setOpaque(true);
????????????container.add(outputs[count]);
????????????checkBoxes[count]?=?new?JCheckBox(“線程掛起“);
????????????checkBoxes[count].addActionListener(this);
????????????container.add(checkBoxes[count]);
????????}
????}

????public?void?start(){
????????for(int?count?=?0;count????????????threads[count]?=?new?Thread(new?Runnableobject()“線程“+(count+1));
????????????threads[count].start();
????????}
????}

????private?int?getIndex(Thread?current){
????????for(int?count?=?0;count????????????if(current?==?threads[count]){
????????????????return?count;
????????????}
????????}
????????return?-1;
????}

????public?synchronized?void?stop(){
????????for(int?count?=?0;count????????????threads[count]?=?null;
????????}
????????notifyAll();
????}

????public?synchronized?void?actionPerformed(ActionEvent?event){
????????for(int?count?=?0;count????????????if(event.getSource()==checkBoxes[count]){
????????????????suspended[count]?=!suspended[count];
????????????????outputs[count].setBackground(suspended[count]?Color.MAGENTA:Color.GREEN);
????????????????if(!suspended[count]){
????????????????????notifyAll();
????????????????}
????????????????return;
????????????}
????????}
????}

????private?class?Runnableobject?implements?Runnable{
????????public?void?run(){
????????????final?Thread?currentThread?=?Thread.currentThread();
????????????final?int?index?=?getIndex(currentThread);
????????????System.err.println(“index=“+index+“thread=“+currentThread.getName());
????????????while?(threads[index]?==?currentThread){
????????????????try{
????????????????????Thread.sleep((int)(Math.random()*1000));
????????????????????synchronized?(RandomCharacter.this){
????????????????????????while(suspended[index]&&threads[index]==currentThread){
????????????????????????????RandomCharacter.this.wait();
????????????????????????}
????????????????????}
????????????????}
????????????????catch?(InterruptedException?e){
????????????????????e.printStackTrace();
????????????????}

????????????????SwingUtilities.invokeL

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????16763??2018-06-22?17:00??11.8(2)\20180622170012.png
?????文件????????1546??2018-06-22?16:41??11.8(2)\RandomCharacter$Runnableobject$1.class
?????文件????????2262??2018-06-22?16:41??11.8(2)\RandomCharacter$Runnableobject.class
?????文件????????3543??2018-06-22?16:41??11.8(2)\RandomCharacter.class
?????文件????????3430??2018-05-28?21:14??11.8(2)\RandomCharacter.java
?????文件???????32768??2018-06-22?17:01??11.8(2)\Thumbs.db
?????文件?????????141??2018-06-22?16:41??11.8(2)\java.policy.applet
?????目錄???????????0??2018-09-28?14:30??11.8(2)\

評論

共有 條評論