ios不越狱修改手机型号:JAVA 小问题

来源:百度文库 编辑:高校问答 时间:2024/05/08 01:30:33
怎样把一行字符串 输入到 光标闪烁的地方,然后执行 回车 功能。

1.控制台:使用System类变量in,这是一个InputStream对象。
public static String readLine(){
StringBuffer response = new StringBuffer();
try{
BufferedInputStream buff = new BufferedInputStream(System.in);
int in = 0;
char inChar;
do{
in = buff.read();
inChar = (char)in;
if(in!=-1){response.append(inChar);}
}while((in!=-1)&(inChar!='\n'));
buff.close;
return response.toString();
}catch(IOExeption e){
System.out.println("异常:"+e.getMessage());
return null;
}
}
2.对话框:只要加入以下一句即可
String response = JOptionPane.showInputDialog(null,"请输入:","输入对话框",0);
3.另外补充一点: 没有与System.out.print();相对应的标准输入方法。

JTextArea jtext=new JTextArea();

jtext.insert("<String>",
jtext.getCaretPosition());

public int read(char[]b,int off,int len)
应该可以吧