Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: HELPPPPPP Java Program With JButtons and JFrames

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELPPPPPP Java Program With JButtons and JFrames

    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);
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELPPPPPP Java Program With JButtons and JFrames

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Do you have any questions?

    I keep getting errors
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Connect to MySQL using jTextfield, jbuttons in NetBeans
    By Light Mike in forum JDBC & Databases
    Replies: 2
    Last Post: August 11th, 2012, 10:41 PM
  2. 2 JFrames In One Applaction.
    By Java Programmer in forum Java Theory & Questions
    Replies: 5
    Last Post: January 9th, 2012, 11:47 PM
  3. JFrames and JMenuBars
    By rushhour in forum AWT / Java Swing
    Replies: 3
    Last Post: November 4th, 2010, 05:14 PM
  4. JFrames not coming up?
    By scooty199 in forum AWT / Java Swing
    Replies: 13
    Last Post: October 30th, 2010, 02:54 AM
  5. Multiple JFrames
    By Scottj996 in forum AWT / Java Swing
    Replies: 1
    Last Post: April 15th, 2010, 05:24 AM

Tags for this Thread