从命令行创建GUI程序

时间:2014-06-10 18:13:42

标签: java user-interface

import 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);
  }
}

0 个答案:

没有答案