📄 example9_3.java
字号:
/*
* Example9_3.java
*
* Created on 2006年10月19日, 上午11:31
*/
package example9_3;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Administrator
*/
public class Example9_3 extends Applet implements Runnable{
/** Initializes the applet Example9_3 */
/* public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}*/
int money=1000;TextArea text1,text2;
Thread 会计,出纳;
public void init(){
会计=new Thread(this); 出纳=new Thread(this);
text1=new TextArea(16,10);text2=new TextArea(16,10);
add(text1);add(text2);
}
public void start(){出纳.start();会计.start();}
public synchronized void withdraw(int number){
if(Thread.currentThread()==会计) {
for(int i=1;i<=3;i++) {
money=money+number;
try{Thread.sleep(1000);}
catch(InterruptedException e){}
text1.append("\n"+money);
}
}
else if(Thread.currentThread()==出纳) {
for(int i=1;i<=2;i++) {
money=money-number/2;
try{Thread.sleep(1000);}
catch(InterruptedException e){}
text2.append("\n"+money);
}
}
}
public void run(){
if(Thread.currentThread()==会计||Thread.currentThread()==出纳)
{for(int i=1;i<=3;i++) withdraw(100); }
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(new java.awt.BorderLayout());
}
// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -