[英]How do I create a window to run my letter grade program in?
I am a beginner in Java and I decided to write a letter grade checker program for people if they want to convert their grades in whole number form to a letter grade. 我是Java的初学者,所以我决定为需要编写整数形式的分数的人编写一个字母等级检查器程序。 I want to know how I can create a window for this to run in with a dialogue box and space for a photo/logo for the program.
我想知道如何为该窗口创建一个运行对话框的窗口,并为该程序的照片/徽标留出空间。
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);
}
}
}
There is a part of java called swing, which handles windows: Java中有一个称为swing的部分,它可以处理窗口:
https://docs.oracle.com/javase/tutorial/uiswing/ https://docs.oracle.com/javase/tutorial/uiswing/
If you dont like that you could try javafx which uses an xml for storing the UI: 如果您不喜欢它,可以尝试使用XML来存储UI的javafx:
https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm
You can use java swing to do this. 您可以使用java swing做到这一点。
It is a very basic example to create a window using 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);
}
});
}
}
You can follow this tutorial: 您可以按照以下教程进行操作:
http://zetcode.com/tutorials/javaswingtutorial/firstprograms/ http://zetcode.com/tutorials/javaswingtutorial/firstprograms/
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.