Trying Add Scroll Panel Output Program Current Output Would Like Window Scroll Panel Verti Q13225779

I am trying to add a scroll panel to the output of myprogram.

Mary, James Computer 7 3.48 Pass Smith John: Mathe

this is my current output

I would like for the window to have a scroll panelvertically.

This is my program

StudentA.java

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import java.util.ArrayList;
class StudentA implements Comparable {
static java.util.Random randomNum = new java.util.Random ();
static ArrayList firstNames = new ArrayList <>();
static ArrayList lastNames = new ArrayList <>();
static ArrayList Major= new ArrayList <>();
static SORTBY sortBy = SORTBY.LAST;
static int nextUID = 1;

String first, last,branch;
double gpa = 0,percentage=0;
boolean pass=false;
int credits = 0,semester=1;
int uid = 0;

public static void inputFile(String inputFile)
{
try {
Major.add(“Computer”);
Major.add(“Electrical”);
Major.add(“Electronics”);
Major.add(“Mathematics”);
Major.add(“Mechanical”);
Scanner input=new Scanner(new File(inputFile));

int n=input.nextInt();
for(int i=0;i {
firstNames.add (input.next());
lastNames.add ( input.next());
}
}
catch (java.io.FileNotFoundException e) {
System.out.println (e);
}
}
enum SORTBY {LAST,FIRST,CREDITS,GPA};

public StudentA (Scanner sc) {
uid = nextUID++;
first = sc.next();
last = sc.next();
branch=sc.next();
semester=sc.nextInt();
credits = sc.nextInt();
gpa = sc.nextDouble();

pass=true;
} // end Scanner constructor

public StudentA ()
{
   uid = nextUID++;
}

public int compareTo (StudentA x) {
switch (sortBy) {
case LAST : return last.compareTo (x.last);
case FIRST : return first.compareTo (x.first);
case CREDITS: return credits – x.credits;
case GPA : return (gpa > x.gpa)? 1 : -1;
} // end switch
return 0;
} // end compareTo for Comparable interface

@Override
public String toString () {
String passStatus=””;
if(pass==true)
passStatus=”Pass”;
else
passStatus=”Fail”;
return String.format (“%d %15s, %10s: %10s %10d %10d %10.2ft”+passStatus, uid, last, first,branch,semester,credits, gpa);

} // end method toString

public static StudentA [] makeRandom (int m) {
StudentA [] sa = new StudentA [m];
for (int i = 0; i < sa.length; i++) {
sa[i] = new StudentA ();
sa[i].first = firstNames.get (i); //no random number
sa[i].last = lastNames.get (i); // //no random number
sa[i].branch=Major.get(randomNum.nextInt(Major.size()));
sa[i].credits = randomNum.nextInt (120);
sa[i].gpa = randomNum.nextDouble () * 4.0;

sa[i].semester=randomNum.nextInt(8)+1;
if(sa[i].gpa>=1.5)
sa[i].pass=true;
} // end for each student to instantiate
return sa;
} // end method makeRanom
public static void writeOutput(StudentA [] s,String outFile)
{
try {
BufferedWriter output=new BufferedWriter(newFileWriter(outFile));
for(int i=0;i {
output.write(s[i]+”n”);
}
output.close();
} catch (Exception e) {
}
}

} // end class StudentAFG

Student.java

import java.awt.Dimension;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;

public class Student extends javax.swing.JFrame {

    BufferedWriter outWriter;
    StudentA s[];
    public Student() {
        StudentGUI();
      
    }

    private void StudentGUI() {

        inputFileChooser =new javax.swing.JButton();
        outputFileChooser = newjavax.swing.JButton();
        sortFirtsName = newjavax.swing.JButton();
        sortLastName = newjavax.swing.JButton();
        sortGPA = newjavax.swing.JButton();
      
        textArea = newjavax.swing.JTextArea();
        sortCredit = newjavax.swing.JButton();
      
       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(newjava.awt.event.WindowAdapter() {
           public void windowClosing(java.awt.event.WindowEvent close) {
               formWindowClosing(close);
           }
        });

       inputFileChooser.setText(“Input File”);
       inputFileChooser.addActionListener(newjava.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent input){
               inputFileChooserActionPerformed(input);
           }
        });

       outputFileChooser.setText(“Output File”);
       outputFileChooser.addActionListener(newjava.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent output){
               outputFileChooserActionPerformed(output);
           }
        });

       sortFirtsName.setText(“Sort by First Name”);
       sortFirtsName.addActionListener(new java.awt.event.ActionListener(){
           public void actionPerformed(java.awt.event.ActionEvent Fname){
               sortFirtsNameActionPerformed(Fname);
           }
        });

       sortLastName.setText(“Sort by last Name”);
       sortLastName.addActionListener(new java.awt.event.ActionListener(){
           public void actionPerformed(java.awt.event.ActionEvent Lname){
               sortLastNameActionPerformed(Lname);
           }
        });

        sortGPA.setText(“Sortby GPA”);
       sortGPA.addActionListener(new java.awt.event.ActionListener(){
           public void actionPerformed(java.awt.event.ActionEvent gpa) {
               sortGPAActionPerformed(gpa);
           }
        });

        sortCredit.setText(“SortBy Credit”);
       sortCredit.addActionListener(new java.awt.event.ActionListener(){
           public void actionPerformed(java.awt.event.ActionEvent credit){
               sortCreditActionPerformed(credit);
           }
        });
        setPreferredSize (newDimension (775, 400));
        setLayout (null);

        add (textArea);
        add(inputFileChooser);
        add(outputFileChooser);
        add(sortFirtsName);
        add(sortLastName);
        add (sortGPA);
        add (sortCredit);
      

      
        textArea.setBounds (20,20, 715, 220);
       inputFileChooser.setBounds (20, 270, 85, 25);
       outputFileChooser.setBounds (110, 270, 95, 25);
        sortFirtsName.setBounds(210, 270, 140, 25);
        sortLastName.setBounds(355, 270, 135, 25);
        sortGPA.setBounds (495,270, 105, 25);
        sortCredit.setBounds(605, 270, 115, 25);
        pack();
    }// //GEN-END:StudentGUI

    private voidinputFileChooserActionPerformed(java.awt.event.ActionEvent evt){//GEN-FIRST:event_inputFileChooserActionPerformed

          Filefile=null;
          JFileChooserchooser = new JFileChooser();
          chooser.setDialogTitle(“Load which file?”);
           intresult = chooser.showOpenDialog(null);
          if (result== JFileChooser.APPROVE_OPTION) {
           file =chooser.getSelectedFile();
      }
       String fileName=null;
     try{
         fileName =file.getCanonicalPath();
        StudentA.inputFile(fileName);
         s=StudentA.makeRandom(10);
         for (StudentA m:s)
         textArea.append(m+”n”);
     }catch(IOException e)
     {
        System.out.println(“Input ouput Exception “);
        System.exit(1);
     }
   }//GEN-LAST:event_inputFileChooserActionPerformed

    private voidsortFirtsNameActionPerformed(java.awt.event.ActionEvent evt){
       textArea.append(“————————– SORTED First————————-n”);
        StudentA.sortBy =StudentA.SORTBY.FIRST;
        java.util.Arrays.sort (s);
          for(StudentA m: s)
        textArea.append(m+”n”);
    }

    private voidsortLastNameActionPerformed(java.awt.event.ActionEvent evt){//GEN-FIRST:event_sortLastNameActionPerformed
      textArea.append(“———————— SORTED Last————————–n”);
        StudentA.sortBy =StudentA.SORTBY.LAST;
        java.util.Arrays.sort (s);
          for(StudentA m: s)
        textArea.append(m+”n”);
    }

    private voidsortGPAActionPerformed(java.awt.event.ActionEvent evt) {
       textArea.append(“———————— SORTED GPA————————–n”);
        StudentA.sortBy =StudentA.SORTBY.GPA;
        java.util.Arrays.sort(s);
        for (StudentA m:s)
       textArea.append(m+”n”);
    }

    private voidsortCreditActionPerformed(java.awt.event.ActionEvent evt) {
       textArea.append(“———————— SORTED CREDIT————————–n”);
        StudentA.sortBy =StudentA.SORTBY.CREDITS;
        java.util.Arrays.sort(s);
        for (StudentA m:s)
       textArea.append(m+”n”);
    }

    private voidoutputFileChooserActionPerformed(java.awt.event.ActionEvent evt){
         Filefile=null;
          JFileChooserchooser = new JFileChooser();
          chooser.setDialogTitle(“Load which file?”);
           intresult = chooser.showOpenDialog(null);
          if (result== JFileChooser.APPROVE_OPTION) {
           file =chooser.getSelectedFile();
      }
       String fileName=null;
     try{
         fileName =file.getCanonicalPath();
         outWriter=newBufferedWriter(new FileWriter(fileName));
     }catch(IOException e)
     {
        System.out.println(“Input ouput Exception “);
        System.exit(1);
     }
    }

    private voidformWindowClosing(java.awt.event.WindowEvent evt) {
         try {
                    outWriter.write(textArea.getText());
                   outWriter.close();
        } catch (Exception e){
        }
    }

    public static void main(String args[]){
        try {
           for (javax.swing.UIManager.LookAndFeelInfo info :javax.swing.UIManager.getInstalledLookAndFeels()) {
               if (“Nimbus”.equals(info.getName())) {
                   javax.swing.UIManager.setLookAndFeel(info.getClassName());
                   break;
               }
           }
        } catch(ClassNotFoundException ex) {

        } catch(InstantiationException ex) {

        } catch(IllegalAccessException ex) {

        } catch(javax.swing.UnsupportedLookAndFeelException ex) {

        }
        //

        /* Create and displaythe form */
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
               new Student().setVisible(true);
           }
        });
    }

    // Variables declaration – do notmodify//GEN-BEGIN:variables
    private javax.swing.JButtoninputFileChooser;
    private javax.swing.JButtonoutputFileChooser;
    private javax.swing.JButton sortCredit;
    private javax.swing.JButton sortFirtsName;
    private javax.swing.JButton sortGPA;
    private javax.swing.JButton sortLastName;
    private javax.swing.JTextArea textArea;
    // End of variablesdeclaration//GEN-END:variables
}

Mary, James Computer 7 3.48 Pass Smith John: Mathematics 5 52 3.89 Pass 3 Johnson Robert Mathematics 5 107 3.44 Pass 4 Elizabeth Michael: Electrical 8 74 0.58 Fai 5 Linda Miller Mathematics 72 1.41 Fai Brown David Mathematics 8 78 0.07 Fai 7 Jones Richard Electrical 5 88 3.36 Pass 8 Margaret, Joseph: Electronics 6 38 0.30 Fai 9 Jessica, Charles: Mathematics 5 59 1.40 Fai 10 Jackson Terry Electrical 7 29 1.11 Fai SORTED GPA Brown David Mathematics 8 78 0.07 Fai 8 Margaret, Joseph: Electronics 6 38 0.30 Fai Input File Output File Sort by First Name Sort by last Name Sort by GPA Sort By Credit Show transcribed image text Mary, James Computer 7 3.48 Pass Smith John: Mathematics 5 52 3.89 Pass 3 Johnson Robert Mathematics 5 107 3.44 Pass 4 Elizabeth Michael: Electrical 8 74 0.58 Fai 5 Linda Miller Mathematics 72 1.41 Fai Brown David Mathematics 8 78 0.07 Fai 7 Jones Richard Electrical 5 88 3.36 Pass 8 Margaret, Joseph: Electronics 6 38 0.30 Fai 9 Jessica, Charles: Mathematics 5 59 1.40 Fai 10 Jackson Terry Electrical 7 29 1.11 Fai SORTED GPA Brown David Mathematics 8 78 0.07 Fai 8 Margaret, Joseph: Electronics 6 38 0.30 Fai Input File Output File Sort by First Name Sort by last Name Sort by GPA Sort By Credit

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.