Okay so I need to build a program that has 3 panels and a group object, one of the panels will contain two other panels, a top panel that display's the group's name and average gpa, and a center panel that contains 4 buttons which display each of the 4 students of the group including their name and individual GPA.
I have a feeling I'm going wrong somewhere with the supers and that's why I keep getting errors when I try to pass over st1.getInfo() to the CenterPanel class.
I need a total of 7 classes:
app
mainframe
controlpanel
toppanel
centerpanel
group
student
Here's what I have for each class:
app.java:
public class app
{
public static void main(String args[])
{
MainFrame mjf = new MainFrame();
}
}
CenterPanel.java:
import java.awt.*;
import javax.swing.*;
public class CenterPanel extends JPanel {
static JButton jb1, jb2, jb3, jb4;
public CenterPanel() {
super();
GridLayout grid = new GridLayout(4, 1);
setLayout(grid);
setBackground(Color.pink);
student st1 = new student("Mike","Myers");
jb1 = new JButton(st1.getInfo());
add(jb1);
jb2 = new JButton();
add(jb2);
jb3 = new JButton();
add(jb3);
jb4 = new JButton();
add(jb4);
}
public JButton getJb1() {
return jb1;
}
public void setJb1(JButton jb1) {
this.jb1 = jb1;
}
public JButton getJb2() {
return jb2;
}
public void setJb2(JButton jb2) {
this.jb2 = jb2;
}
public JButton getJb3() {
return jb3;
}
public void setJb3(JButton jb3) {
this.jb3 = jb3;
}
public JButton getJb4() {
return jb4;
}
public void setJb4(JButton jb4) {
this.jb4 = jb4;
}
}
ControlPanel.java
import java.awt.*;
import javax.swing.*;
public class ControlPanel extends JPanel
{
CenterPanel cp;
TopPanel tp1;
public ControlPanel()
{
super();
BorderLayout border = new BorderLayout();
setLayout(border);
setBackground(Color.gray);
cp = new CenterPanel();
tp1 = new TopPanel();
add(tp1, "North");
add(cp, "Center");
}
}
group.java:
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class group extends TopPanel {
String groupName;
ArrayList<student> studentgrouplist;
public group(String groupName1) {
groupName = groupName1;
studentgrouplist = new ArrayList<>();
}
public String groupList() {
String info = "";
for (int i = 0; i < studentgrouplist.size(); i++) {
this.getStudentgrouplist().get(i);
student temp = this.getStudentgrouplist().get(i);
info = info + "\n" + temp.getFirstName() + " " + temp.getLastName() + ": " + temp.getRandomGPA();
}
return getGroupName() + info;
}
public double groupAvg() {
double total = 0;
for (int i = 0; i < studentgrouplist.size(); i++) {
total = total + this.getStudentgrouplist().get(i).getRandomGPA();
}
return total / studentgrouplist.size();
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public ArrayList<student> getStudentgrouplist() {
return studentgrouplist;
}
public void setStudentgroup(ArrayList<student> studentgrouplist) {
this.studentgrouplist = studentgrouplist;
}
}
mainframe.java:
import java.awt.*;
import javax.swing.*;
public class MainFrame extends JFrame
{
ControlPanel mjp;
public MainFrame()
{
super("Assignment 05 Starter");
mjp = new ControlPanel();
getContentPane().add(mjp, "Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1200, 500);
setVisible(true);
}
}
student.java:
import java.awt.*;
import javax.swing.*;
public class student extends CenterPanel {
private static student st1;
private static student st4;
private static student st3;
private static student st2;
String firstName;
String lastName;
double randomGPA;
public student(String pFirstName, String pLastName){
super();
firstName = pFirstName;
lastName = pLastName;
double gpa = Math.random();
randomGPA = gpa * 5.0;
student st1 = new student("Mike","Myers");
student st2 = new student("Test","Blah");
student st3 = new student("Brad","Long");
student st4 = new student("Mitch","Best");
}
public void setGetInfo(String firstName, String lastName) {
this.getJb1();
}
public String getInfo() {
return this.getInfo();
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public double getRandomGPA() {
return randomGPA;
}
public void setRandomGPA(double randomGPA) {
this.randomGPA = randomGPA;
}
}
TopPanel.java:
import java.awt.*;
import javax.swing.*;
public class TopPanel extends JPanel
{
JButton jb1, jb2, jb3, jb4;
public TopPanel(){
super();
setBackground(Color.gray);
jb1 = new JButton();
ImageIcon psu = new ImageIcon("images/psu.jpg");
jb1.setIcon(psu);
jb1.setBackground(Color.white);
add(jb1);
jb2 = new JButton("Group Name Goes Here");
jb2.setBackground(Color.white);
add(jb2);
jb3 = new JButton("Group Average GPA is");
jb3.setBackground(Color.white);
add(jb3);
jb4 = new JButton("The Groups Avg. GPA Goes Here (Extracted from the GROUP Object)");
jb4.setBackground(Color.white);
add(jb4);
}
}