菜鸟请教高手指点
想做一题连接字符串或者数字的,也就是AA+BB=AABB或1+2=12的,自己做了一个,感觉很麻烦,太复杂了,所以想请教一下高手有没有什么简单的写法,在此附上我的代码,希望高手能帮我写一个简单的程序,让我学习学习:
package ks;
import java.awt.*;
import java.awt.event.*;
public class Text implements ActionListener {
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
Button b1 = new Button("连接字符串");
public Text() {
}
public static void main(String args[])
{
Text t1 = new Text();
t1.init();
}
/**
* actionPerformed
*
* @param e ActionEvent
*/
public void init(){
Frame f1 = new Frame();
f1.setLayout(new BorderLayout(10,20));
f1.add("North",t1);
f1.add("Center",t2);
f1.add("South",b1);
f1.add("East",t3);
b1.addActionListener(this);
f1.show();
}
public void actionPerformed(ActionEvent e) {
String t4 = "";
t4 = t1.getText().concat(t2.getText());
t3.setText(t4);
StringBuffer ss = new StringBuffer();
ss.append(11);
System.out.println(ss);
}
}
class GetInt
{
public int getInt(String str)
{
try
{
if(str.length()==0)
return -1;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)<'0'||str.charAt(i)>'9')
return -1;
}
return 1;
}
catch(Exception e)
{
return -1;
}
}
}
class Input
{
public static void main(String[] args)
{
GetInt get=new GetInt();
int num=get.getInt(args[0]);
if(num==1)
{
System.out.println(Integer.parseInt(args[0]) + Integer.parseInt(args[1]));
}
else{
System.out.println(args[0].concat(args[1]));
}
}
}