6 Replies - 1473 Views - Last Post: 04 December 2012 - 12:30 PM Rate Topic: -----

#1 PatriotPrice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-December 12

Converting program into GUI?

Posted 04 December 2012 - 01:42 AM

Okay so im not completely done with this program, but i want to get it working in GUI and then applet before i move on in it, its a grading program that then spits out grades needed for an A for now, whats the easiest way to convert this into GUI, ive really only used joptionpane and not really all that much looking for any and all help maybe if someone could convert one section of it for me would be amazing as well where i could look at it for how to do the rest!
And for example the last part from "For an A in this class you will need the following grades: through all of the assignments id like all of that on one panel! Ive got this program to work but gah am i horrible at GUI

Thanks!

import java.util.Scanner;


public class Prog5 {

	public static void main(String args[])
	{
		int numberOfGrades;
		int grade = 0; 
		int gradesDone = 0;
		int completed;
		float totalPoints = 0;
		int points;
		float pointsEarned = 0;
		float remainingPoints;
		int aLeft;
		float assignment = 0;
		int aCounter = 0;
		
		
		
		Scanner input = new Scanner( System.in );
		
		System.out.println("How many total grades will there be? ");
		numberOfGrades = input.nextInt();
		
		int [] grades = new int [numberOfGrades+1];
		
		do            
		{
			
		grade++;
		System.out.println("Points possible for assignment " + grade + ":");
		grades[grade] = input.nextInt();
		
		
		 
		}while (grade < numberOfGrades);
		
		
		for ( int counter=1; counter < grades.length; counter++ )
			totalPoints += grades[counter]; 
		
		
		
		System.out.println("an ID "+ java.util.Arrays.toString(grades));
		System.out.println(totalPoints);
		
		System.out.println("How many assignments completed?");
		completed = input.nextInt();
		
		
		int [] completedArray = new int [completed+1];
		
		
		
		do            
		{
		 gradesDone++;
		
		System.out.println("Points recieved on assignment " + gradesDone + ":");
		completedArray[gradesDone] = input.nextInt();
		
		
		 
		}while (gradesDone < completed);
		
		for ( int counter=1; counter < completedArray.length; counter++ )
			pointsEarned += completedArray[counter]; 
		
		remainingPoints =  (totalPoints - pointsEarned);
		aLeft = numberOfGrades - completed;
		
		
		
		do            
		{
		 assignment++;
		 
		 		
		 
		}while (((pointsEarned+assignment)/(totalPoints)) <= .895);
		
		
		System.out.println("For an A in this class you will need the following grades:");
		
		do
		{
			 
			aCounter++;
			
			if ((assignment-grades[gradesDone+aCounter])>0)
			{
			System.out.println("Assignment " + (gradesDone+aCounter) + ": " + 
			(int) (grades[gradesDone+aCounter]));
			
			assignment = assignment-grades[gradesDone+aCounter];
			
						}
			
			else
			{
				System.out.println("Assignment " + (gradesDone+aCounter) + ": " + (int) assignment);
				
				assignment = assignment-grades[gradesDone+aCounter];
			}
			
		}while (assignment > 0);
		
		
		
		
		
		
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Converting program into GUI?

#2 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Converting program into GUI?

Posted 04 December 2012 - 01:52 AM

GUI programming is not an easy process and it is extremely object oriented. The program you have written is all within the main method. This is not an object oriented approach, so reusing the code you wrote will not be easy when switching over to a GUI.

You could check out macosxnerd101's tutorial: How To Approach Swing For Beginners

I would, however, suggest that you first make sure you have a firm grasp on Object Oriented programming before you try to tackle making a GUI. You can check out Getting Better at Java Programming for lots of good resources and a sort of timeline for learning things.
Was This Post Helpful? 1
  • +
  • -

#3 PatriotPrice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-December 12

Re: Converting program into GUI?

Posted 04 December 2012 - 02:01 AM

View PostSheph, on 04 December 2012 - 01:52 AM, said:

GUI programming is not an easy process and it is extremely object oriented. The program you have written is all within the main method. This is not an object oriented approach, so reusing the code you wrote will not be easy when switching over to a GUI.

You could check out macosxnerd101's tutorial: How To Approach Swing For Beginners

I would, however, suggest that you first make sure you have a firm grasp on Object Oriented programming before you try to tackle making a GUI. You can check out Getting Better at Java Programming for lots of good resources and a sort of timeline for learning things.


oh my that doesnt sound good haha gotta turn this in tomorrow, wonderful finals week, ill look over those things, thanks hopefully it wont end up to complicated lol

View PostSheph, on 04 December 2012 - 01:52 AM, said:

GUI programming is not an easy process and it is extremely object oriented. The program you have written is all within the main method. This is not an object oriented approach, so reusing the code you wrote will not be easy when switching over to a GUI.

You could check out macosxnerd101's tutorial: How To Approach Swing For Beginners

I would, however, suggest that you first make sure you have a firm grasp on Object Oriented programming before you try to tackle making a GUI. You can check out Getting Better at Java Programming for lots of good resources and a sort of timeline for learning things.





This may be a completely dumb question, is it possible to turn the program i have into an applet? like will those kinds of commands work in an applet? or do i have to use gui for that
Was This Post Helpful? 0
  • +
  • -

#4 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Converting program into GUI?

Posted 04 December 2012 - 02:05 AM

If this is for a class and you haven't covered OOP yet, you cannot be expected to produce a GUI program. Focus on the actual requirements for the assignment. You will learn the rest in time. Meanwhile, between classes, you can take the initiative and look into those links I posted. That is how you are going to learn the most. :)
Was This Post Helpful? 0
  • +
  • -

#5 PatriotPrice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-December 12

Re: Converting program into GUI?

Posted 04 December 2012 - 02:21 AM

View PostSheph, on 04 December 2012 - 02:05 AM, said:

If this is for a class and you haven't covered OOP yet, you cannot be expected to produce a GUI program. Focus on the actual requirements for the assignment. You will learn the rest in time. Meanwhile, between classes, you can take the initiative and look into those links I posted. That is how you are going to learn the most. :)/>



Well weve covered object oriented programming, but not very well, we dont have the best teacher at all on the last exam we had i think the class average was failing. Its actually caused one of my friends to change majors because of how much he hates programming and i think its really because of the teacher, i find the subject interesting as can be and i dont mind sitting down figuring out all the logic, we just never stay on things very long and he doesnt cover in depth lol the requirements for this assignment are to create a program that we could use personally, have it run in Japplet, and to use comments and white space effectively (doing that stuff last)
Its unfortunate, and at this point wish i just learned it all on my own and didnt rely on his reviews and such up to this point. Cuz now its got me in a bind for example on this program!
Was This Post Helpful? 0
  • +
  • -

#6 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Converting program into GUI?

Posted 04 December 2012 - 02:52 AM

Quote

This may be a completely dumb question, is it possible to turn the program i have into an applet? like will those kinds of commands work in an applet? or do i have to use gui for that


The basic concepts of programming remain the same. The difference is that the user is interacting with the applet (which is a gui) instead of the console. The console specific commands, such as System.out.println and System.in wrapped by a Scanner, won't work.

Instead of the user typing input into the console, they have to type it into a text area, or they have to click a button or move their mouse or type a keystroke. If you designed your program in such a way that you can switch between the type of input/output, then it would not be as much of a problem. Your program relies too heavily on the console commands, and so you wouldn't be able to turn it into an applet without a very big rewrite.

This is where OOP comes in. If you had your program separated into multiple classes, you would be able to reuse some of them and only chuck the ones that specifically dealt with the console. So, while it's possible... it's not practical in your situation.
Was This Post Helpful? 1
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: Converting program into GUI?

Posted 04 December 2012 - 12:30 PM

Your program is not very nice because in a nice program you should always separate the following elemnts:
- the data (who it is store: file, data base, in memory)
- the user interface (console, Application, Applet)
- the business rules (the actual program logic)

When these elemnts are clearly separated than you can replace one of them by another. So if your program use flat files and you want to convert them to a database, you should have to change the user interface part neither the business rules part.

If you pass, as you wish, from a console application to a GUI interface, you shouldn't have to change neither the way your data is stored or the business rules.

In your case, you have a big, single main() method where everything is packed together not easy to change :)
If instead of reading your grades using a Scanner in the middle of everyting you had a method

int[] getGrades()   {
    get number of grade
    create array int[]
    prompt user for each of them
    return the array
}


then switching to GUI is a piece of cake. You just modify that method and the logic that further down manipulate the grade array is not changed

Now you will have to redo everything because you just can't insert the GUI elements where actually is your grade array creation and filling with a Scanner. In a GUI it is a completly different element.

Have fun anyhow and happy coding

that returned the array of grades
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1