Tag: 输入

如何在EditText提示后设置焦点到文本?

我感兴趣的是你可以在提示EditText之后将焦点设置为文本? 如果xml布局没有这样的属性? 在那时我仍然看起来像这样。 需要 编辑: Asok给出了最快和最有效的答案 我也发现了类似的方式: EditText.append( “60”); // 60或EditText中的文本

如何在不输入字符的情况下让Java的hasNextInt()停止等待整数?

我得到了以下代码,并要求编写从TestList扩展的Solution类。 我为它编写了一个构造函数(刚刚调用了super),并在下面代码的最后一行调用了printSecond2()方法。 所有其他方法都是inheritance的。 这是代码: public class Test3A { public static void main(String[] args) { TestList tl = new Solution(); tl.loadList(); ((Solution) (tl)).printSecond2();//prints every second element } } 但是,该死的东西从来没有打印过任何东西,所以我进入了TestList类(提供了它)并在loadList()方法的每一行之后放置了println语句: public void loadList () { if (input.hasNextInt ())//input is a Scanner object { int number = input.nextInt (); loadList (); add (number); } } 我发现我可以继续无限地添加空格,换行符和整数,并且只有在输入字符时才会最终调用add(number)方法。 因此,如果我不这样做,它只是等待更多输入而不是继续前进。 由于提供的示例输入/输出是:我对此感到困惑: […]

Java – exception处理 – 如何重新输入无效输入

exception处理仅接受双输入。 因此,当用户输入“k”时,它会显示“错误!请输入一个数字!”。 但是,它不是允许用户重新输入输入,而是跳转到下一个输入“平均脉冲”。如何使其工作以使其保持在同一条线上并允许重新输入值? //主要课程 public class Main { //Master class public static void main( String args[] ) //Standard header for main method { kbentry input = new kbentry(); //Creates object of kbentry class System.out.print(“\nPlease enter a number for Total Impulse: ” ); //Print message to enter 1. input double totalImpulse = input.totalImpulse1(); //Holds the variable […]

从用户输入中读取数学表达式

我需要能够读入用户输入并将其拆分以供以后使用。 用户可以输入整数或分数和一个操作,我不知道如何阅读。 用户输入的示例是4/8 – 3/12或3 + 2/3或12/16 * 4或-2/3 / 64/96 。 现在我正在使用这样的东西: public class FractionApp { public static void main(String[] args){ Scanner s = new Scanner(System.in); int[] fraction = new int[5]; String input; String operation; System.out.println(“Enter the expression: “); input = s.next(); StringTokenizer st = new StringTokenizer (input, “/” + ” “); fraction[0] = […]

java.io.IOException:不支持mark / reset

此代码不起作用。 我准备好上课,因为它可以在这里找到,但音乐不起作用。 我怎样才能解决这个问题? private void lblCliqueMouseClicked(java.awt.event.MouseEvent evt){ lblClique.setText(“achou”); musica = new Som(); boolean repetir = false; FileInputStream arquivo = null; try { arquivo = new FileInputStream(“musica.mp3”); } catch (FileNotFoundException ex) { Logger.getLogger(TelaProjeto.class.getName()).log(Level.SEVERE, null, ex); } musica.tocar(arquivo, repetir); }

如何在Java中读取格式化输入?

假设我的输入文件包含: 3 4 5 6 7 8 9 10 我想运行一个while循环并读取整数,这样我将在循环的每次迭代后分别获得3,4,5,6,7,8和10。 这在C / C ++中很简单,但在Java中却不行…… 我试过这段代码: try { DataInputStream out2 = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); int i=out2.read(); while(i!=-1){ System.out.println(i); i=out2.readInt(); } } catch (IOException ex) { } 而我得到的是: 51 540287029 540418080 538982176 151599117 171511050 218762506 825232650 如何在Java中读取此文件中的整数?

BUTTON1_MASK和BUTTON1_DOWN_MASK之间的区别是什么?

来自java网站: BUTTON1_DOWN_MASK = The Mouse Button1 extended modifier constant. BUTTON1_MASK = The Mouse Button1 modifier constant. 我甚至不确定“修饰常数”是什么。 更不用说扩展了一个。 但我确实理解BUTTON1_MASK只是单击鼠标左键时的整数表示。

使用while循环和扫描仪validation输入

从指定范围(0,20)的用户获取有效整数并且为int的最佳方法是什么。 如果输入无效的整数打印输出错误。 我想的是: int choice = -1; while(!scanner.hasNextInt() || choice 20) { System.out.println(“Error”); scanner.next(); //clear the buffer } choice = scanner.nextInt(); 这是正确的还是有更好的方法?

Java:从互联网上的目录中读取文本文件

有人知道如何递归地从互联网上的特定目录中读取文件,用Java吗? 我想阅读这个网站目录中的所有文本文件: http : //www.cs.ucdavis.edu/~davidson/courses/170-S11/Female/ 我知道如何读取计算机上文件夹中的多个文件,以及如何从互联网上读取单个文件。 但是如何在互联网上读取多个文件,而无需对url进行硬编码? 我试过的东西: // List the files on my Desktop final File folder = new File(“/Users/crystal/Desktop”); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { File fileEntry = listOfFiles[i]; if (!fileEntry.isDirectory()) { System.out.println(fileEntry.getName()); } } 我试过的另一件事: // Reading data from the web try { // […]

中断线程等待用户输入然后退出应用程序

我有两个线程在运行, userInputThread等待来自命令行的用户输入,而interrupterThread在启动后1秒尝试中断userInputThread 。 显然,您无法中断被System.in阻止的线程。 另一个答案建议在中断线程之前使用System.in.close()关闭System.in 。 但是,当我运行以下代码时, userInputThread永远不会被中断,应用程序只是挂起而不关闭。 class InputInterruptionExample { private Thread userInputThread; private Thread interrupterThread; InputInterruptionExample() { this.userInputThread = new Thread(new UserInputThread()); this.interrupterThread = new Thread(new InterrupterThread()); } void startThreads() { this.userInputThread.start(); this.interrupterThread.start(); } private class UserInputThread implements Runnable { public void run() { try { System.out.println(“enter your name: “); String userInput = […]