4 Replies - 349 Views - Last Post: 29 August 2011 - 06:20 AM Rate Topic: -----

#1 LieannM  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 18-June 11

GUI's Concern

Posted 28 August 2011 - 07:28 AM

can somebody please help me how can I make this code into a GUI form :( .. and also i need to save it I/O even it is in GUI :) thanks in advance!

        
        Scanner scan = new Scanner(System.in);
        Scanner input = new Scanner(System.in);

        do{
        /*Student Student1= new Student();
        Student1.studinfo();
        Teacher Teach= new Teacher();
        Teach.teachinfo();
        System.out.println("");*/ 
        
         String a,c,G;
         int b = 0;
         char g;
         double grades;
         boolean S1age, S1g, S1gr, S2age, S2g, S2gr;
         S1age = false;
         S1g= false;
         S1gr= false;
         S2age = false;
         S2g= false;
         S2gr=false;
         
          Student STUD1 = new Student();
          Student STUD2 = new Student();
          Person getter = new Person();
          
        FileWriter fw = new FileWriter("Project document.doc");
        BufferedWriter bw = new BufferedWriter(fw);
         
       System.out.println("");
       System.out.print("\tEnter name for student #1: ");
       STUD1.setName(scan.nextLine());
       
       
        while(!S1age)
        {
            try
            {
            System.out.print("\tEnter age for student #1: ");   
            STUD1.setAge(scan.nextInt());
            S1age=true;
            }
            catch(MyException e)
            {
                System.out.println("\t\tInput Out of Range!\n\t\tPlease Enter value from 3 - 60, no NEGATIVE numbers!");
                System.out.println("");
                
            }
           catch (InputMismatchException j) {
             System.out.println("\t\tInputMismatchException Occured!");
             scan.nextLine();
             }
                    
            catch (RuntimeException i){
                System.out.println("\t\tRuntimeException Occured!");
            scan.nextLine();}
        }
        
        while(!S1g)
        {
            try
            {
                System.out.print("\tEnter gender [F/M] for student #1: ");   
                G = scan.next();
                g = G.charAt(0);
                STUD1.setGender(g);
                S1g = true;
            }
            catch(MyException  e)
            {
                System.out.println("\t\tPLEASE FOLLOW INSTRUCTION!");
                System.out.println("");
            }        
        }
        
        S1gr= false;
        while(!S1gr)
        {        
            try
            {
                System.out.print("\tEnter grade for student #1: ");
                STUD1.setGrade(scan.nextDouble());
                grades=STUD1.getGrade();
                S1gr = true;
            }
           catch(MyException  e)
            {
                System.out.println("\t\tInput Out Of Range\n\t\tPlease Enter 60-100, NEGATIVE numbers are not allowed!");
                System.out.println("");
            }
             
              catch (InputMismatchException j) {
              System.out.println("\t\tInputMismatchException Occured!");
              scan.nextLine();}
          
              catch (RuntimeException i){
              System.out.println("\t\tRuntimeException Occured!");
              scan.nextLine();}
        }
      
//----------------------------------- S2
       System.out.println("");
       System.out.print("\tEnter name for student #2: ");
       STUD2.setName(input.nextLine());
     
       while(!S2age)
        {
            try
            {
            System.out.print("\tEnter age for student #1: ");   
            STUD2.setAge(scan.nextInt());
            S2age=true;
            }
            catch(MyException e)
            {
                System.out.println("\t\tInput Out of Range!,\n\t\tPlease Enter valid value from 3 - 60, no NEGATIVE numbers!");
                System.out.println("");
                
            }
             catch (InputMismatchException j) {
             System.out.println("\t\tInputMismatchException Occured!");
             scan.nextLine();}
             
            catch (RuntimeException i){
             System.out.println("\t\tRuntimeException Occured!");
            scan.nextLine();}
        }
        
        while(!S2g)
        {
            try
            {
                System.out.print("\tEnter gender [F/M] for student #1: ");   
                G = scan.next();
                g = G.charAt(0);
                STUD2.setGender(g);
                S2g = true;
            }
            catch(MyException  e)
            {
                System.out.println("\t\tPLEASE FOLLOW INSTRUCTION!");
                System.out.println("");
            }        
        }
        
        S2gr= false;
        while(!S2gr)
        {        
            try
            {
                System.out.print("\tEnter grade for student #1: ");
                STUD2.setGrade(scan.nextDouble());
                grades=STUD2.getGrade();
                S2gr = true;
            }
           catch(MyException e)
            {
                System.out.println("\t\tInput Out Of Range \n\t\tPlease Enter 60-100, NEGATIVE numbers are not allowed!");
                System.out.println("");
            }
             
             catch (InputMismatchException j) {
             System.out.println("\t\tInputMismatchException Occured!");
             scan.nextLine();}
        
            catch (RuntimeException i){
            System.out.println("\t\tRuntimeException Occured!");
            scan.nextLine();}
        }
        Teacher TEACH = new Teacher();
      //  Person getter = new Person();
       
        
         //String a,G;
         double r;
         //char g;
         boolean tage, tgen,tsal;
         tage= false;
         tgen=false;
         tsal=false;
         
       System.out.println("");
       System.out.print("\tEnter name for teacher:  ");
       TEACH.setName(input.nextLine());
       
       
      while(!tage)
        {
            try
            {
            System.out.print("\tEnter age for student #1: ");   
            TEACH.setAge(scan.nextInt());
            tage=true;
            }
            catch(MyException e)
            {
                System.out.println("\t\tInput Out of Range!\n\t\tPlease Enter valid value from 3 - 60, no NEGATIVE numbers!");
                System.out.println("");
                
            }
             catch (InputMismatchException j) {
             System.out.println("\t\tInputMismatchException Occured!");
             }
           
            catch (RuntimeException i){
                System.out.println("\t\tRuntimeException Occured!");}
                    
            
            }
        
        
        while(!tgen)
        {
            try
            {
                System.out.print("\tEnter gender [F/M] for student #1: ");   
                G = scan.next();
                g = G.charAt(0);
                TEACH.setGender(g);
                tgen = true;
            }
            catch(MyException e)
            {
                System.out.println("\t\tPLEASE FOLLOW INSTRUCTION!");
                System.out.println("");
            }        
        }
        
        while(!tsal)
        {        
            try
            {
                System.out.print("\tEnter salary for teacher: ");
                TEACH.setSalary(scan.nextDouble());
                 r = TEACH.getSalary();
                tsal=true;
            }
           
            catch( MyException e)
            {
                System.out.println("\t\tInput Out Of Range, and No negative numbers.");
                System.out.print("\n");
            }
           
            
        
      
    System.out.println("");
    System.out.println("");
   /* System.out.println("\tTEACHER:");
    System.out.println("\tName:"+getter.getName());
    System.out.println("\tAge: "+TEACH.getAge());
    System.out.println("\tGender: "+TEACH.getGender());
    System.out.println("\tSalary: "+TEACH.getSalary());
    System.out.println("");
    System.out.println("\t\tTHANK YOU! ");}*/
    
       
       
         
        
           
       //---------------- output
  /*  System.out.println("");
    System.out.println("\tSTUDENT #1:");
    System.out.println("\tName: "+getter.getName());
    System.out.println("\tAge: "+STUD1.getAge());
    System.out.println("\tGender: "+STUD1.getGender());
    System.out.println("\tGrade: "+STUD1.getGrade());
    System.out.println("");
    System.out.println("\tSTUDENT #2:");
    System.out.println("\tName: "+name2);
    System.out.println("\tAge: "+STUD2.getAge());
    System.out.println("\tGender: "+STUD2.getGender());
    System.out.println("\tGrade: "+STUD2.getGrade());
    System.out.println("");*/
        
        bw.write("\t\t••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••");
        bw.write("\t\t••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••");
        bw.write("\t\t\t        WELCOME  ☻ \t\t\t             ");
        bw.write("\t\t••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••");
        bw.write("\t\t••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••");
       
         bw.write("\tSTUDENT 1");
         bw.write("\t\tStudent Name: "+STUD1.getName());
         bw.write("\t\tStudent Age: "+STUD1.getAge());
         bw.write("\t\tStudent Gender: "+STUD1.getGender());
         bw.write("\t\tStudent Grade: "+STUD1.getGrade());

         bw.write("\tSTUDENT 2");
         bw.write("\n\t\tStudent Name: "+STUD2.getName());
         bw.write("\n\t\tStudent Age: "+STUD2.getAge());
         bw.write("\n\t\tStudent Gender: "+STUD2.getGender());
         bw.write("\n\t\tStudent Grade: "+STUD2.getGrade());

         
         bw.write("\n\tTEACHER");
         bw.write("\n\t\tTeacher Name: "+TEACH.getName());
         bw.write("\n\t\tTeacher Age: "+TEACH.getAge());
         bw.write("\n\t\tTeacher Gender: "+TEACH.getGender());
         bw.write("\n\t\tTeacher Salary: "+TEACH.getSalary());
        
        
         bw.close();
         fw = null;
          
            
        System.out.print("Would you like to enter again?[Y/N]: ");
        answer=scan.next().charAt(0);
        }}while((answer!='N')&&(answer!='n'));
        
    System.out.println("");
    System.out.println("\t\t THANK YOU!");
    System.out.println("");
    System.out.println("");
        

}
}

This post has been edited by macosxnerd101: 28 August 2011 - 08:20 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: GUI's Concern

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: GUI's Concern

Posted 28 August 2011 - 07:39 AM

The easiest way to properly apply code tags is to completely select the text (highlight it) and then select the [CODE] button in the editor pane above the text entry area.

The task you've asked help with is non-trivial. If you've no experience with GUIs in Java, I suggest you consult the Swing tutorials here on DIC. There's one that has ~5 parts that provides an excellent overview of how to code a Java GUI using Swing.
Was This Post Helpful? 2
  • +
  • -

#3 LieannM  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 18-June 11

Re: GUI's Concern

Posted 28 August 2011 - 07:45 AM

THANK YOU :)
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: GUI's Concern

Posted 28 August 2011 - 10:54 AM

I apologize that my first answer wasn't better. I didn't give your untagged code a thorough look.

It's common for some to get a taste of GUI programming early in their studies by having simple exchanges with the user using Java's simplest dialog construct, JOptionPane, in its various forms. Looking at your code, I think that's where you are.

You can learn more about how to use simple graphical dialogs on this page. On that page, pay particular attention to "Creating and Showing Simple Dialogs," and "Getting the User's Input from a Dialog." I don't think you'll need to go past the last subject to complete this assignment.

The approach you should use is to replace your existing program's interaction with the user using simple dialogs. Instead of telling the user something with a System.out.println() statement, say it in a dialog, and instead of prompting for and getting the user's input the same way, use a dialog.

Try replacing your first print statement with a simple dialog and come back if you need more help. (Remember to post your updated code in code tags, any error messages you're having trouble with (cut and paste), and as much info as possible about any questions you have.)

Good luck!
Was This Post Helpful? 2
  • +
  • -

#5 LieannM  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 18-June 11

Re: GUI's Concern

Posted 29 August 2011 - 06:20 AM

View PostGregBrannon, on 28 August 2011 - 10:54 AM, said:

I apologize that my first answer wasn't better. I didn't give your untagged code a thorough look.

It's common for some to get a taste of GUI programming early in their studies by having simple exchanges with the user using Java's simplest dialog construct, JOptionPane, in its various forms. Looking at your code, I think that's where you are.

You can learn more about how to use simple graphical dialogs on this page. On that page, pay particular attention to "Creating and Showing Simple Dialogs," and "Getting the User's Input from a Dialog." I don't think you'll need to go past the last subject to complete this assignment.

The approach you should use is to replace your existing program's interaction with the user using simple dialogs. Instead of telling the user something with a System.out.println() statement, say it in a dialog, and instead of prompting for and getting the user's input the same way, use a dialog.

Try replacing your first print statement with a simple dialog and come back if you need more help. (Remember to post your updated code in code tags, any error messages you're having trouble with (cut and paste), and as much info as possible about any questions you have.)

Good luck!


thankyou so much :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1