Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从命令行生成GUI程序_Java_User Interface - Fatal编程技术网

Java 从命令行生成GUI程序

Java 从命令行生成GUI程序,java,user-interface,Java,User Interface,导入java.util.Scanner 我正试图把它变成一个GUI程序,我的想法给了我很多错误,所以如果有人能帮我弄清楚,那就太好了 public class Problemtwo { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the side: "); double side = input.nex

导入java.util.Scanner

我正试图把它变成一个GUI程序,我的想法给了我很多错误,所以如果有人能帮我弄清楚,那就太好了

public class Problemtwo {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.print("Enter the side: ");
    double side = input.nextDouble();

    double area = 3 * 1.73205 * side * side / 2;

    System.out.println("The area " + area);
  }
}
这就是我试图创建的GUI

import java.swing.JOptionPane;
import java.lang.Math;

public class GUI_Problemtwo {
  public static void main(String[] args) {

    double side;
    double area;

    StringsideString = JOptionPane.showInputDialog("Enter the side: ");

    return;
  }

    // Convert string to double
    double side = Double.parseDouble(sideString);

    double side = input.nextDouble();

    // Compute the area
    double area = 3 * 1.73205 * side * side / 2;

    // Display results
    String output = "The area is " + area;
}
我只知道我真的做错了什么。另外,我还有另外一个GUI,我可以将它输入到对话框中,但我无法让它在对话框中调出任何输出,它看起来甚至没有停止运行

import javax.swing.JOptionPane;
import java.io.*;
public class GUI_Account {

  public static void main(String[] args)throws IOException {
    BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));
    double bal=0;
    int month,i;

    // Prompts user to enter a number of months
    String MString = JOptionPane.showInputDialog("Enter number of months: ");

    if (MString == null) {System.out.println("User prompt cancelled");
      return;
  }

  month=Integer.parseInt(kb.readLine());
  for(i=0;i<month;i++) {
    bal=(bal+100)*1.00417;
  }

  // Convert string to double
  double M =Double.parseDouble(MString);      

  // Display results in dialog box
  String output = "The amount is " + bal; JOptionPane.showMessageDialog(null, output);
  }
}
import javax.swing.JOptionPane;
导入java.io.*;
公共类GUI_帐户{
公共静态void main(字符串[]args)引发IOException{
BufferedReader kb=新的BufferedReader(新的InputStreamReader(System.in));
双平衡=0;
int月,i;
//提示用户输入月份数
字符串MString=JOptionPane.showInputDialog(“输入月数:”);
如果(MString==null){System.out.println(“用户提示已取消”);
返回;
}
month=Integer.parseInt(kb.readLine());

对于(i=0;iIn GUI_问题2,您尚未声明一个变量以接受对话结果。请尝试修复该问题并查看发生了什么情况。此外,尝试使用最后一部分的扫描仪获取系统。在您的代码中缺少大括号,很可能还有一些额外的方法。请在有时间时更新您的问题。学习Oracle教程。