java在文本框显示代码不成功,就是设置一个按钮点击一下得到第一个文本框内的数值在第二个文本框显示
第二个文本框显示银行大写。。。。。importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener...
第二个文本框显示银行大写。。。。。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
public class ListenChange implements ActionListener {
JTextField inputField;
JTextField showField;
JButton changeButton;
public void four(int s) {
//showField=new JTextField();
switch (s) {
case 0:
showField.setText("零");
break;
case 1:
showField.setText("壹");
break;
case 2:
showField.setText("贰");
break;
case 3:
showField.setText("叁");
break;
case 4:
showField.setText("肆");
break;
case 5:
showField.setText("伍");
break;
case 6:
showField.setText("陆");
break;
case 7:
showField.setText("柒");
break;
case 8:
showField.setText("扒");
break;
case 9:
showField.setText("玖");
break;
default:
break;
}
}
public void wei(int j) {
//showField=new JTextField();
switch (j) {
case 0:
showField.setText("仟");
break;
case 1:
showField.setText("百");
break;
case 2:
showField.setText("拾");
break;
default:
break;
}
}
public void hou(int i) {
//showField=new JTextField();
switch (i) {
case 0:
showField.setText("兆");
break;
case 1:
showField.setText("亿");
break;
case 2:
showField.setText("万");
break;
default:
break;
}
}
public void setInput(JTextField inputField) {
this.inputField=inputField;
}
public void setShow(JTextField showField) {
this.showField=showField;
}
public void actionPerformed(ActionEvent e) {
//showField=new JTextField();
String s=inputField.getText();
char[] c=s.toCharArray();
int[] money=new int[c.length];
for (int i = 0; i < c.length; i++) {
money[i]=c[i]-'0';
}
int[][] str=new int[4][4];
int i=money.length-1;
for (int h = 4; h>0; h--) {
for (int z = 4; z>0; z--) {
if(i==-1) break;
str[h-1][z-1]=money[i];
i--;
}
}
boolean flag=false;
for (int j = 0; flag==false&&j<4; j++) {
for (int j2 = 0;flag==false&&j2<4; j2++) {
if(str[j][j2]<1) str[j][j2]=20;
else flag=true;
}
}
for (int j = 0; j < str.length; j++) {
for (int j2 = 0; j2 < str.length; j2++) {
if(str[j][j2]!=0) continue;
if(j2!=3&&str[j][j2]+str[j][j2+1]==0) str[j][j2]=10;
if(j2==3&&str[j][j2]==0) str[j][3]=10;
}
}
ListenChange t=new ListenChange();
for (int j = 0; j < str.length; j++) {
for (int j2 = 0; j2 < str.length; j2++) {
int n=str[j][j2];
t.four(n);
if(str[j][j2]==10||str[j][j2]==20||str[j][j2]==0) showField.setText("");
else t.wei(j2);
}
if(str[j][3]==20) showField.setText("");
else t.hou(j);
}
}
} 展开
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
public class ListenChange implements ActionListener {
JTextField inputField;
JTextField showField;
JButton changeButton;
public void four(int s) {
//showField=new JTextField();
switch (s) {
case 0:
showField.setText("零");
break;
case 1:
showField.setText("壹");
break;
case 2:
showField.setText("贰");
break;
case 3:
showField.setText("叁");
break;
case 4:
showField.setText("肆");
break;
case 5:
showField.setText("伍");
break;
case 6:
showField.setText("陆");
break;
case 7:
showField.setText("柒");
break;
case 8:
showField.setText("扒");
break;
case 9:
showField.setText("玖");
break;
default:
break;
}
}
public void wei(int j) {
//showField=new JTextField();
switch (j) {
case 0:
showField.setText("仟");
break;
case 1:
showField.setText("百");
break;
case 2:
showField.setText("拾");
break;
default:
break;
}
}
public void hou(int i) {
//showField=new JTextField();
switch (i) {
case 0:
showField.setText("兆");
break;
case 1:
showField.setText("亿");
break;
case 2:
showField.setText("万");
break;
default:
break;
}
}
public void setInput(JTextField inputField) {
this.inputField=inputField;
}
public void setShow(JTextField showField) {
this.showField=showField;
}
public void actionPerformed(ActionEvent e) {
//showField=new JTextField();
String s=inputField.getText();
char[] c=s.toCharArray();
int[] money=new int[c.length];
for (int i = 0; i < c.length; i++) {
money[i]=c[i]-'0';
}
int[][] str=new int[4][4];
int i=money.length-1;
for (int h = 4; h>0; h--) {
for (int z = 4; z>0; z--) {
if(i==-1) break;
str[h-1][z-1]=money[i];
i--;
}
}
boolean flag=false;
for (int j = 0; flag==false&&j<4; j++) {
for (int j2 = 0;flag==false&&j2<4; j2++) {
if(str[j][j2]<1) str[j][j2]=20;
else flag=true;
}
}
for (int j = 0; j < str.length; j++) {
for (int j2 = 0; j2 < str.length; j2++) {
if(str[j][j2]!=0) continue;
if(j2!=3&&str[j][j2]+str[j][j2+1]==0) str[j][j2]=10;
if(j2==3&&str[j][j2]==0) str[j][3]=10;
}
}
ListenChange t=new ListenChange();
for (int j = 0; j < str.length; j++) {
for (int j2 = 0; j2 < str.length; j2++) {
int n=str[j][j2];
t.four(n);
if(str[j][j2]==10||str[j][j2]==20||str[j][j2]==0) showField.setText("");
else t.wei(j2);
}
if(str[j][3]==20) showField.setText("");
else t.hou(j);
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |