📄 dtmf.java
字号:
package DTMF;
/*
* @(#)DTMF.java 1.0 06/04/17
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_2\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/
import java.awt.*;
import java.applet.*;
public class DTMF extends Applet implements Runnable {
Thread runner;//????????????????
boolean isTextFieldEntry = false;//判断文本框里面是否有数字???
Panel pnlKeyPad = new Panel();
// String toText;
BorderLayout borderLayout1 = new BorderLayout(0, 20);
GridLayout gridLayout1= new GridLayout(4, 4, 5, 5);
Button btnZero = new Button("0");
Button btnOne = new Button("1");
Button btnTwo = new Button("2");
Button btnThree = new Button("3");
Button btnFour = new Button("4");
Button btnFive = new Button("5");
Button btnSix = new Button("6");
Button btnSeven = new Button("7");
Button btnEight = new Button("8");
Button btnNine = new Button("9");
Button btnStar = new Button("*");
Button btnHash = new Button("#");
//Button btnA = new Button("A");
//Button btnB = new Button("B");
//Button btnC = new Button("C");
//Button btnD = new Button("D");
// Button btnDial = new Button("拨号");
AudioClip toneZero, toneOne, toneTwo, toneThree, toneFour,
toneFive, toneSix, toneSeven, toneEight,
toneNine, toneStar, toneHash, toneA, toneB, toneC, toneD;
// TextField tfNumber = new TextField(12);
Panel pnlNumberEntry = new Panel();
FlowLayout flowLayout1 = new FlowLayout();
Label lbcopy=new Label("(c)华南理工大学电子信息学院",Label.CENTER);
//Construct the applet
public DTMF() {
}
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
if (runner != null) {
runner.stop();
runner = null;
}
}
public void run() {
}
//Initialize the applet
public void init() {
try { jbInit(); } catch (Exception e) { e.printStackTrace(); }
}
//Component initialization
public void jbInit() throws Exception{
this.setLayout(borderLayout1);
pnlNumberEntry.setLayout(flowLayout1);
pnlKeyPad.setLayout(gridLayout1);
//this.add("North", pnlNumberEntry);
//pnlNumberEntry.add(tfNumber);
//pnlNumberEntry.add(btnDial);
this.add("Center", pnlKeyPad);
pnlKeyPad.add(btnOne);
pnlKeyPad.add(btnTwo);
pnlKeyPad.add(btnThree);
// pnlKeyPad.add(btnA);
pnlKeyPad.add(btnFour);
pnlKeyPad.add(btnFive);
pnlKeyPad.add(btnSix);
// pnlKeyPad.add(btnB);
pnlKeyPad.add(btnSeven);
pnlKeyPad.add(btnEight);
pnlKeyPad.add(btnNine);
// pnlKeyPad.add(btnC);
pnlKeyPad.add(btnStar);
pnlKeyPad.add(btnZero);
pnlKeyPad.add(btnHash);
// pnlKeyPad.add(btnD);
this.add("South",lbcopy);
toneZero = getAudioClip(getDocumentBase(), "zero.au");
toneOne = getAudioClip(getDocumentBase(), "one.au");
toneTwo = getAudioClip(getDocumentBase(), "two.au");
toneThree = getAudioClip(getDocumentBase(), "three.au");
toneFour = getAudioClip(getDocumentBase(), "four.au");
toneFive = getAudioClip(getDocumentBase(), "five.au");
toneSix = getAudioClip(getDocumentBase(), "six.au");
toneSeven = getAudioClip(getDocumentBase(), "seven.au");
toneEight = getAudioClip(getDocumentBase(), "eight.au");
toneNine = getAudioClip(getDocumentBase(), "nine.au");
toneStar = getAudioClip(getDocumentBase(), "star.au");
toneHash = getAudioClip(getDocumentBase(), "hash.au");
toneA = getAudioClip(getDocumentBase(), "A.au");
toneB = getAudioClip(getDocumentBase(), "B.au");
toneC = getAudioClip(getDocumentBase(), "C.au");
toneD = getAudioClip(getDocumentBase(), "D.au");
this.requestFocus();
}
void pause() {
try { Thread.sleep(200); }
catch (InterruptedException e) { return; }
}
/*
public void dialDigitString() {
String s = tfNumber.getText();
int l = s.length();
for (int i = 0; i<l; i++) {
char c = s.charAt(i);
switch (c) {
case '0': toneZero.play(); pause(); break;
case '1': toneOne.play(); pause(); break;
case '2': toneTwo.play(); pause(); break;
case '3': toneThree.play(); pause(); break;
case '4': toneFour.play(); pause(); break;
case '5': toneFive.play(); pause(); break;
case '6': toneSix.play(); pause(); break;
case '7': toneSeven.play(); pause(); break;
case '8': toneEight.play(); pause(); break;
case '9': toneNine.play(); pause(); break;
case '*': toneStar.play(); pause(); break;
case '#': toneHash.play(); pause(); break;
// case 'A': toneA.play(); pause(); break;
// case 'B': toneB.play(); pause(); break;
// case 'C': toneC.play(); pause(); break;
// case 'D': toneD.play(); pause(); break;
}
}
tfNumber.setText("");
}
*/
//Get Applet information
public String getAppletInfo() {
return "(c)华南理工大学电子信息学院";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
public boolean action(Event evt, Object obj) {
if (evt.target == btnZero) {
toneZero.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnOne) {
toneOne.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnTwo) {
toneTwo.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnThree) {
toneThree.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnFour) {
toneFour.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnFive) {
toneFive.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnSix) {
toneSix.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnSeven) {
toneSeven.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnEight) {
toneEight.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnNine) {
toneNine.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnStar) {
toneStar.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnHash) {
toneHash.play();
this.requestFocus();
return true;
}
/* else
if (evt.target == btnA) {
//toneA.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnB) {
toneB.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnC) {
toneC.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnD) {
toneD.play();
this.requestFocus();
return true;
}
else
if (evt.target == btnDial) {
dialDigitString();
this.requestFocus();
return true;
}
*/ else
return false;
}
public boolean gotFocus(Event evt, Object obj) {
//if (evt.target == tfNumber) {
// isTextFieldEntry = true;
// return true;
//}
//else
return false;
}
public boolean lostFocus(Event evt, Object obj) {
//if (evt.target == tfNumber) {
// isTextFieldEntry = false;
// return true;
//}
//else
return false;
}
public boolean keyDown(Event evt, int key) {
if (!isTextFieldEntry) {
switch ((char)key) {
case '0': toneZero.play(); break;
case '1': toneOne.play(); break;
case '2': toneTwo.play(); break;
case '3': toneThree.play(); break;
case '4': toneFour.play(); break;
case '5': toneFive.play(); break;
case '6': toneSix.play(); break;
case '7': toneSeven.play(); break;
case '8': toneEight.play(); break;
case '9': toneNine.play(); break;
case '#': toneHash.play(); break;
case '*': toneStar.play(); break;
/* case 'a':
case 'A': toneA.play(); break;
case 'b':
case 'B': toneB.play(); break;
case 'c':
case 'C': toneC.play(); break;
case 'd':
case 'D': toneD.play(); break;
*/ default:
}
}
return !isTextFieldEntry;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -