我是Java的初学者,如果他们想要将整数形式的成绩转换为字母等级,我决定为人们写一个字母成绩检查程序。我想知道如何创建一个窗口,以便在程序的照片/徽标的对话框和空间中运行。
import java.util.Scanner;
public class noname {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
int gradescore;
System.out.println("Please enter your score and round the decimals");
gradescore = user_input.nextInt();
if((gradescore >= 94) && (gradescore <= 100)) {
char grade = 'A';
System.out.println("Your grade is an "+grade);
gradescore = user_input.nextInt();
} else if ((gradescore >=90) && (gradescore <= 93)) {
char grade = 'A';
System.out.println("Your grade is an " +grade +"-");
gradescore = user_input.nextInt();
} else if ((gradescore >= 87) && (gradescore <=89)) {
char grade = 'B';
System.out.println("Your grade is a "+grade +"+");
gradescore = user_input.nextInt();
} else if ((gradescore >= 83) && (gradescore <= 86)) {
char grade = 'B';
System.out.println("Your grade is a "+grade);
gradescore = user_input.nextInt();
} else if ((gradescore >= 80) && (gradescore <= 82)) {
char grade = 'B';
System.out.println("Your grade is a "+grade +"-");
gradescore = user_input.nextInt();
} else if ((gradescore >= 77) && (gradescore <= 79)) {
char grade = 'C';
System.out.println("Your grade is a " +grade +"-");
gradescore = user_input.nextInt();
} else if ((gradescore >= 73) && (gradescore <= 76)) {
char grade = 'C';
System.out.println("Your grade is a " +grade);
gradescore = user_input.nextInt();
} else if ((gradescore >= 70) && (gradescore <= 72)) {
char grade = 'C';
System.out.println("Your grade is a " +grade +"-");
gradescore = user_input.nextInt();
} else if ((gradescore >= 67) && (gradescore <= 69)) {
char grade = 'D';
System.out.println("Your grade is a " +grade +"+");
gradescore = user_input.nextInt();
} else if ((gradescore >= 63) && (gradescore <=66)) {
char grade = 'D';
System.out.println("Your grade is a " +grade);
gradescore = user_input.nextInt();
} else if ((gradescore >= 60) && (gradescore <= 62)) {
char grade = 'D';
System.out.println("Your grade is a " +grade +"-");
gradescore = user_input.nextInt();
} else if (gradescore < 60) {
char grade = 'F';
System.out.println("Your grade is an " +grade);
}
}
}
答案 0 :(得分:0)
有一部分叫做swing的java,它处理windows:
https://docs.oracle.com/javase/tutorial/uiswing/
如果您不喜欢,可以尝试使用xml存储UI的javafx:
https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm
答案 1 :(得分:0)
您可以使用java swing来执行此操作。
这是使用swing创建窗口的一个非常基本的示例:
import java.awt.EventQueue;
import javax.swing.JFrame;
public class SimpleExample extends JFrame {
public SimpleExample() {
setTitle("Simple example");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SimpleExample ex = new SimpleExample();
ex.setVisible(true);
}
});
}
}
您可以按照本教程进行操作:
http://zetcode.com/tutorials/javaswingtutorial/firstprograms/
希望它有所帮助。