📄 gee1001.java
字号:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GEE1001 implements ActionListener{
private workFrame myFrame;
public GEE1001(){
myFrame = new workFrame();
myFrame.getInButton().addActionListener(this);
myFrame.getClearButton().addActionListener(this);
}
public static void main(String[] argv){
GEE1001 ge = new GEE1001();
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource() == myFrame.getInButton()){
String str = myFrame.getInTextArea().getText();
int rows = myFrame.getInTextArea().getLineCount();
for(int i=0;i<rows;i++){
int index = 0,subindex = 0,firstvalue = 0,secondvalue = 0;
String sub = "",firstsub = "", secondsub = "";
while(str.charAt(index)!= '='){
sub = sub + str.charAt(index);
index ++;
}
str = ""+str.substring(index+1).trim();
str = ""+str.substring(0);
while(sub.charAt(subindex)!='+'){
firstsub = firstsub + sub.charAt(subindex);
subindex++;
}
firstsub = "" +firstsub.trim();
secondsub = sub.substring(subindex+2,sub.length()-1);
if(firstsub.indexOf(' ') == -1 && firstsub.equalsIgnoreCase("zero")&&
secondsub.indexOf(' ') == -1 && secondsub.equalsIgnoreCase("zero")){
break;
}
if(firstsub.indexOf(' ') == -1)
firstvalue = getValue(firstsub);
else
firstvalue = getValue(getSub(firstsub,1))+10*getValue(getSub(firstsub,0));
if(secondsub.indexOf(' ') == -1)
secondvalue = getValue(secondsub);
else
secondvalue = getValue(getSub(secondsub,1))+10*getValue(getSub(secondsub,0));
myFrame.getOutTextArea().append(firstvalue+secondvalue+""+"\n");
}
}
else if(arg0.getSource() == myFrame.getClearButton()){
myFrame.getInTextArea().setText("");
myFrame.getOutTextArea().setText("");
}
}
public int getValue(String str){
if(str.equalsIgnoreCase("one")) return 1;
else if(str.equalsIgnoreCase("two")) return 2;
else if(str.equalsIgnoreCase("three")) return 3;
else if(str.equalsIgnoreCase("four")) return 4;
else if(str.equalsIgnoreCase("five")) return 5;
else if(str.equalsIgnoreCase("six")) return 6;
else if(str.equalsIgnoreCase("seven")) return 7;
else if(str.equalsIgnoreCase("eight")) return 8;
else if(str.equalsIgnoreCase("nine")) return 9;
else if(str.equalsIgnoreCase("zero")) return 0;
return 0;
}
public String getSub(String s,int index){
String[] array = new String[3];
String sub = new String();
int arrayindex = 0;
s = s+' ';
for(int m=0;m<s.length();m++){
if(s.charAt(m)!=' ')
sub = sub+s.charAt(m);
else{
array[arrayindex] = sub;
sub = "";
arrayindex++;
}
}
if(index <arrayindex)
return array[index];
else return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -