Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

You will start with a working version from the previous lab. All requirements are still the same including You will create only one group

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."

There is one big exception:

**now the listener will have to be implemented in the TopPanel or in the CenterPanel.

**it cannot be implemented in the ControlPanel.

Current code is as follows:

Control Panel

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener; import javax.swing.*;

public class ControlPanel extends JPanel implements ActionListener{

CenterPanel cp; TopPanel tp; group g1; public ControlPanel() { super(); BorderLayout border = new BorderLayout(); setLayout(border); setBackground(Color.gray); student st1 = new student("Joshua", "James", 23); student st2 = new student("Victoria", "Snyder", 32); student st3 = new student("Conner", "Smith", 25); student st4 = new student("Skyler", "Reese", 28); student[] students = {st1, st2, st3, st4}; g1 = new group("Nittany Lions"); g1.addStudents(students); cp = new CenterPanel(g1);

cp.jb1.addActionListener(this); cp.jb2.addActionListener(this); cp.jb3.addActionListener(this); cp.jb4.addActionListener(this); tp = new TopPanel(g1); add(tp, "North"); add(cp, "Center"); } @Override public void actionPerformed(ActionEvent e) { Object obj = e.getSource();

if (obj == cp.jb1) { cp.jb1.setText("Student gpa: " + g1.getStudentGPA(0)); tp.jb3.setText("" + g1.getAverageGPA()); } if (obj == cp.jb2) { cp.jb2.setText("Student gpa: " + g1.getStudentGPA(0)); tp.jb3.setText("" + g1.getAverageGPA()); } if (obj == cp.jb3) { cp.jb3.setText("Student gpa: " + g1.getStudentGPA(0)); tp.jb3.setText("" + g1.getAverageGPA()); } if (obj == cp.jb4) { cp.jb4.setText("Student gpa: " + g1.getStudentGPA(0)); tp.jb3.setText("" + g1.getAverageGPA()); } } }

import java.awt.*; import javax.swing.*;

public class CenterPanel extends JPanel { JButton jb1, jb2, jb3, jb4; public CenterPanel(group g1) { super(); GridLayout grid = new GridLayout(4, 1); setLayout(grid); setBackground(Color.pink); jb1 = new JButton("Name = " + g1.students[0].getName() + " " + g1.students[0].myGPA); add(jb1); jb2 = new JButton("Name = " + g1.students[1].getName() + " " + g1.students[1].myGPA); add(jb2); jb3 = new JButton("Name = " + g1.students[2].getName() + " " + g1.students[2].myGPA); add(jb3); jb4 = new JButton("Name = " + g1.students[3].getName() + " " + g1.students[3].myGPA); add(jb4); } }

import java.awt.*; import javax.swing.*;

public class TopPanel extends JPanel { JButton jb1, jb2, jb3;

public TopPanel(group g1) { super(); setBackground(Color.blue); jb1 = new JButton(g1.groupName); jb2 = new JButton("Group Average: "); jb2.setBackground(Color.white); jb3 = new JButton("" + g1.getAverageGPA()); add(jb1); add(jb2); add(jb3); } }

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