Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WHAT TO DO IS GIVEN CLEARLY IN THE IMAGES ATTACHED BELOW :- App.java :- package L05; /** * * @author user */ public class App

WHAT TO DO IS GIVEN CLEARLY IN THE IMAGES ATTACHED BELOW :-

App.java :-

package L05;

/**

*

* @author user

*/

public class App

{

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

double avgGPA = 0.0;

double semGPA = 0.0;

Student s1 = new Student("Iron", "Man", 12);

Student s2 = new Student("Black", "Widow", 12);

Student s3 = new Student("Captain", "America", 12);

Student s4 = new Student("Spider", "Man", 12);

Group g1 = new Group("Avengers", s1, s2, s3, s4);

new MainFrame(g1).setVisible(true);

}

}

MainFrame.java :-

package L05;

/**

*

* @author user

*/

public class MainFrame extends javax.swing.JFrame

{

public MainFrame(Group grp)

{

super ("Assignment 05");

controlPanel = new ControlPanel(grp);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(controlPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)

);

pack();

}

/**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

//

private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 642, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 366, Short.MAX_VALUE)

);

pack();

}//

// Variables declaration - do not modify

// End of variables declaration

private ControlPanel controlPanel;

}

ControlPanel.java :-

package L05;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JPanel;

/**

*

* @author user

*/

public class ControlPanel extends JPanel

{

private TopPanel topPanel;

private CenterPanel centerPanel;

ControlPanel(Group grp)

{

setLayout(new java.awt.BorderLayout(1, 1));

topPanel = new TopPanel(grp);

topPanel.setBackground(new java.awt.Color(0, 0, 204));

topPanel.setPreferredSize(new java.awt.Dimension(590, 45));

centerPanel = new CenterPanel(grp);

centerPanel.setLayout(new java.awt.GridLayout(4, 0));

add(topPanel, java.awt.BorderLayout.PAGE_START);

add(centerPanel, java.awt.BorderLayout.CENTER);

}

}

TopPanel.java :-

package L05;

import javax.swing.JPanel;

/**

*

* @author user

*/

public class TopPanel extends JPanel

{

// Variables declaration - do not modify

public javax.swing.JButton jButton1;

public javax.swing.JButton jButton2;

public javax.swing.JButton jButton3;

TopPanel(Group grp)

{

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton3 = new javax.swing.JButton();

jButton1.setText(grp.name);

jButton2.setText("Group Average GPA is ");

jButton3.setText(grp.averageGPA().toString());

javax.swing.GroupLayout TopPanelLayout = new javax.swing.GroupLayout(this);

setLayout(TopPanelLayout);

TopPanelLayout.setHorizontalGroup(

TopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(TopPanelLayout.createSequentialGroup()

.addGap(114, 114, 114)

.addComponent(jButton1)

.addGap(113, 113, 113)

.addComponent(jButton2)

.addGap(72, 72, 72)

.addComponent(jButton3)

.addContainerGap(124, Short.MAX_VALUE))

);

TopPanelLayout.setVerticalGroup(

TopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TopPanelLayout.createSequentialGroup()

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(TopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jButton1)

.addComponent(jButton2)

.addComponent(jButton3))

.addContainerGap())

);

}

}

CenterPanel.java :-

package L05;

import javax.swing.JPanel;

/**

*

* @author user

*/

public class CenterPanel extends JPanel

{

public javax.swing.JButton jButton4;

public javax.swing.JButton jButton5;

public javax.swing.JButton jButton6;

public javax.swing.JButton jButton7;

CenterPanel(Group grp)

{

jButton4 = new javax.swing.JButton();

jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jButton7 = new javax.swing.JButton();

setLayout(new java.awt.GridLayout(4, 0));

jButton4.setText(grp.member1.getInfo());

add(jButton4);

jButton5.setText(grp.member2.getInfo());

add(jButton5);

jButton6.setText(grp.member3.getInfo());

add(jButton6);

jButton7.setText(grp.member4.getInfo());

add(jButton7);

}

}

Group.java :-

package L05;

/**

*

* @author user

*/

public class Group

{

public String name;

public Student member1;

public Student member2;

public Student member3;

public Student member4;

public double g1=this.member1.getGPA();

public double g2=this.member2.getGPA();

public double g3=this.member3.getGPA();

public double g4=this.member4.getGPA();

public double g=g1+g2+g3+g4;

public Group(String name, Student s1, Student s2, Student s3, Student s4)

{

this.name=name;

this.member1=s1;

this.member2=s2;

this.member3=s3;

this.member4=s4;

}

public void getInfo()

{

System.out.printf("Group Name: %s ",this.name);

this.member1.getInfo();

this.member2.getInfo();

this.member3.getInfo();

this.member4.getInfo();

System.out.printf("Group GPA: %.2f ",this.averageGPA());

}

public Double averageGPA()

{

double avgGPA=0.0;

avgGPA=g;

avgGPA/=4;

long factor = (long) Math.pow(10, 2);

avgGPA = avgGPA * factor;

long tmp = Math.round(avgGPA);

return (double) tmp / factor;

// return avgGPA;

}

public double getSemesterGPA(Student s)

{

return s.getGPA();

}

}

Student.java :-

package L05;

/**

*

* @author user

*/

public class Student

{

private String firstName;

private String lastName;

private int age;

private double gpa;

public Student(String fName, String lName, int age)

{

this.firstName = fName;

this.lastName = lName;

this.age = age;

//init gpa

semesterGPA();

}

public String getInfo()

{

return "Name = " +this.firstName+" "+this.lastName+" "+this.gpa;

}

public void semesterGPA()

{

double semgpa = Math.random() * 4.0;

long factor = (long) Math.pow(10, 2);

semgpa = semgpa * factor;

long tmp = Math.round(semgpa);

gpa=(double) tmp / factor;

}

public String getFirstName()

{

return firstName;

}

public double getGPA()

{

return gpa;

}

}

-

Question Description :

image text in transcribed

image text in transcribed

What You Will Learn Basic button tracking Implementing Action Listeners Deliverables app-Java (initial application) MainFrame.java (external JFrame) A Java class for the control panel, that will contain the 2 new panels, using a layout. . A Java class for the Panel that will display the group's name and group's average GPA . A Java class for the Panel that will display names and semester GPAs of the 4 students in a group. . group java and student,java (a working version from previous labs, no changes needed). Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents You will start with a working version from the previous lab. All requirements are still the same including "You will create only one group object g1 in this assignment. There will be only one statement group g1 new group!..);, in the whole application." Additional requirements are below. The ActionListener will be implemented in the ControlPanel, the external panel that contains the other two panels. A ceetainer panel with a border layout It has two panels. The ActionListener will be implemented here A panel with 3 buttons displaying estracted from a group object A container panel with a border layout. It has two panels. The ActionListener will be implemented here You will listen to this button and when it is clicked it will recalculate A panel with 3 buttons displaying information extracted from a group object Uses the default layout. NAME Zack Smith 2.65 and display the GPA again. You will listen to this button and NAME- tobert Jones 344 when it is clicked it will recalculate A panel with 4 buttons with group student's names and with student's semester GPAs extracted from a group object Uses a grid layout. The 4 buttons will be listened to and they will display the recalculated GPA when they are clicked and display the GPA again. You will listen to this button and NAME Jeanifer Merris 2.0 when it is clicked it will recalculate and display the GPA again. You will listen to this button and NAME Megan Hilton 2.0s when it is clicked it will recalculate and display the GPA again. You will be listening to the 4 buttons with student information. Every time a user click on one of the buttons, the GPA will be recalculated using semesterGPA and displayed again When a student GPA is recalculated, the group average GPA has to be updated too and displayed again. Important-#1-Where to implement the ActionListener? It is a requirement that you implement the ActionListener in ControlPanel, which is the panel that contains the other two panels You have to use the traditional model for listening that you have been using so far public class ControlPanel extends JPanel implements ActionListener . Lab 06 Listening: Video (no audio/transcript)(0:20) e Activate o to Sett What You Will Learn Basic button tracking Implementing Action Listeners Deliverables app-Java (initial application) MainFrame.java (external JFrame) A Java class for the control panel, that will contain the 2 new panels, using a layout. . A Java class for the Panel that will display the group's name and group's average GPA . A Java class for the Panel that will display names and semester GPAs of the 4 students in a group. . group java and student,java (a working version from previous labs, no changes needed). Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents You will start with a working version from the previous lab. All requirements are still the same including "You will create only one group object g1 in this assignment. There will be only one statement group g1 new group!..);, in the whole application." Additional requirements are below. The ActionListener will be implemented in the ControlPanel, the external panel that contains the other two panels. A ceetainer panel with a border layout It has two panels. The ActionListener will be implemented here A panel with 3 buttons displaying estracted from a group object A container panel with a border layout. It has two panels. The ActionListener will be implemented here You will listen to this button and when it is clicked it will recalculate A panel with 3 buttons displaying information extracted from a group object Uses the default layout. NAME Zack Smith 2.65 and display the GPA again. You will listen to this button and NAME- tobert Jones 344 when it is clicked it will recalculate A panel with 4 buttons with group student's names and with student's semester GPAs extracted from a group object Uses a grid layout. The 4 buttons will be listened to and they will display the recalculated GPA when they are clicked and display the GPA again. You will listen to this button and NAME Jeanifer Merris 2.0 when it is clicked it will recalculate and display the GPA again. You will listen to this button and NAME Megan Hilton 2.0s when it is clicked it will recalculate and display the GPA again. You will be listening to the 4 buttons with student information. Every time a user click on one of the buttons, the GPA will be recalculated using semesterGPA and displayed again When a student GPA is recalculated, the group average GPA has to be updated too and displayed again. Important-#1-Where to implement the ActionListener? It is a requirement that you implement the ActionListener in ControlPanel, which is the panel that contains the other two panels You have to use the traditional model for listening that you have been using so far public class ControlPanel extends JPanel implements ActionListener . Lab 06 Listening: Video (no audio/transcript)(0:20) e Activate o to Sett

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions