2015-02-05 16 views
0

내 컴퓨터 과학 수업을 위해서 우리는 GPA 계산기를 만들고 학생과 GPA의 전체 이름을 표시하기 위해 동일한 프로그램에 애플릿을 포함시켜야합니다. 나는 프로그램을 작동 시켰습니다.Java 응용 프로그램에 애플릿을 어떻게 포함합니까?

import java.util.*; 
import java.text.DecimalFormat; 
import javax.swing.JApplet; 
import java.awt.*; 


public class Project1_Michael_Micool extends JApplet 
{ 
public static void main(String[]args) 
{ 
String first_name, last_name, course1, course2, course3, course4; 
    //Sets all the needed variables to string values for first, last and course names 
int cred_course1, cred_course2, cred_course3, cred_course4, total_credits; 
    //Sets all the course credits as int values 
float grade_course1, grade_course2, grade_course3, grade_course4, grade_point1, grade_point2, grade_point3, grade_point4, total_grades_added, gpa; 


Scanner scan = new Scanner(System.in); 
DecimalFormat fmt = new DecimalFormat("0.##"); 


System.out.println("Welcome to the UNG GPA calculator."); 

System.out.println(); 
System.out.println("Please enter your first name"); 
first_name = scan.next(); //Assigns the entered name as first_name 
System.out.println("Please enter your last name"); 
last_name = scan.next(); //Assigns the entered name as last_name 


System.out.println(); 
System.out.println("A: 4.0  A-:3.67 "); 
System.out.println("B+:3.33  B:3.00 B-:2.67"); 
System.out.println("C+: 2.33 C:2.00 C-:1.67"); 
System.out.println("D+: 1.33 D:1.00 F:0.00"); 


System.out.println(); 
System.out.println("Please enter your first course name and number. EX: PSYC1101"); 
course1 = scan.next(); 
System.out.println("Please enter the number of credits for course 1."); 
cred_course1 = scan.nextInt(); 
System.out.println("Please enter your grade for course 1 using the chart. EX: B+= 3.33"); 
grade_course1 = scan.nextFloat();  


System.out.println(); 
System.out.println(); 
System.out.println("Please enter your second course name and number. EX: PSYC1101"); 
course2 = scan.next(); 
System.out.println("Please enter the number of credits for course 2."); 
cred_course2 = scan.nextInt(); 
System.out.println("Please enter your grade for course 2 using the chart. EX: B+= 3.33"); 
grade_course2 = scan.nextFloat(); 


System.out.println(); 
System.out.println(); 
System.out.println("Please enter your third course name and number. EX: PSYC1101"); 
course3 = scan.next(); 
System.out.println("Please enter the number of credits for course 3."); 
cred_course3 = scan.nextInt(); 
System.out.println("Please enter your grade for course 3 using the chart. EX: B+= 3.33"); 
grade_course3 = scan.nextFloat(); 


System.out.println(); 
System.out.println(); 
System.out.println("Please enter your fourth course name and number. EX: PSYC1101"); 
course4 = scan.next(); 
System.out.println("Please enter the number of credits for course 4."); 
cred_course4 = scan.nextInt(); 
System.out.println("Please enter your grade for course 4 using the chart. EX: B+= 3.33"); 
grade_course4 = scan.nextFloat(); 


total_credits = cred_course1 + cred_course2 + cred_course3 + cred_course4; 
grade_point1 = grade_course1 * cred_course1; 
grade_point2 = grade_course2 * cred_course2; 
grade_point3 = grade_course3 * cred_course3; 
grade_point4 = grade_course4 * cred_course4; 
total_grades_added = grade_point1 + grade_point2 + grade_point3 + grade_point4; 
gpa = total_grades_added/total_credits; 
gpa = Math.abs(gpa); 


course1 = course1.toUpperCase(); 
course2 = course2.toUpperCase(); 
course3 = course3.toUpperCase(); 
course4 = course4.toUpperCase(); 


System.out.println("Your name is " + first_name + " " + last_name); 
System.out.println("You are taking " + course1 + " which is worth " + cred_course1 + " credit hours"); 
System.out.println("You are taking " + course2 + " which is worth " + cred_course2 + " credit hours"); 
System.out.println("You are taking " + course3 + " which is worth " + cred_course3 + " credit hours"); 
System.out.println("You are taking " + course4 + " which is worth " + cred_course4 + " credit hours"); 
System.out.println("Your total credit hours is " + total_credits); 
System.out.println("Your GPA is " + fmt.format(gpa)); 
} 
} 

다음은 작동해야하는 애플릿입니다.

public void paint(Graphics page) 
{ 
page.drawString(first_name + " " + last_name, 110, 70); 
page.drawString(gmt.format(gpa), 130, 100); 
} 

내 질문은 프로그램에 애플릿을 통합하는 방법입니다.

답변

1

게시 한 내용은 "애플릿"이 아닙니다. paint AWT 위젯 (예 : 애플릿) 일 수있는 메소드 일뿐입니다. UI에 통합하는 위젯에서 해당 메소드를 사용하기 만하면됩니다. 이 (애플리케이션이 Frame 또는 JFrame 전세계 거의 기초)는 하이브리드 애플리케이션/애플릿이지만, 그 주된 방법은 커맨드 라인에 집중되지 않는

1

Applet (또는 JApplet) 일반적 main(String[])가 없다.

애플릿 또는 응용 프로그램에서 명령 줄 코드를 사용하는 실용적인 방법은 없습니다. GUI를 사용하려면 다시 작성해야합니다. 내 컴퓨터 과학 수업 ..for


..

Why CS teachers should stop teaching Java applets에 강사를 참조하십시오.