Question: The program needs the following: Scenarios Some information is missing 1. the user does not type the first name or the last name 2. the

The program needs the following:

Scenarios

Some information is missing

1. the user does not type the first name or the last name

2. the OK button is pressed

3. a message saying "Student name cannot be blank" is displayed on the message button

- "Error" is displayed on both buttons in the right panel

Some information is missing

1. the user does not ask the GPA to be calculated (GPA value is still zero)

2. the OK button is pressed

3. a message saying "Calculate the GPA before submitting" is displayed on the message button

- "Error" is displayed on both buttons in the right panel

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

public class LeftPanel extends JPanel implements ChangeListener, ActionListener { student s; JTextField fNameText; JLabel fNameLabel; JLabel lNameLabel; JTextField lNameText; JLabel ageLabel; JSlider ageSlider; JButton studentGPA; JButton newStudentGPA; JButton message; JButton okButton; RightPanel rp;

public LeftPanel(RightPanel rp) { super(); this.rp = rp; setSize(600, 600); GridLayout gr = new GridLayout (5,2); gr.setHgap(10); gr.setVgap(10); setLayout(gr); fNameLabel = new JLabel("First Name:"); fNameText = new JTextField(""); lNameLabel = new JLabel("Last Name:"); lNameText = new JTextField(""); ageLabel = new JLabel("Age:"); ageSlider = new JSlider(JSlider.HORIZONTAL,0,40,5); studentGPA = new JButton("0.0"); newStudentGPA = new JButton("GPA Calculator"); message = new JButton("Message goes here"); okButton = new JButton("OK"); add(fNameLabel); add(fNameText); add(lNameLabel); add(lNameText); add(ageLabel); add(ageSlider); add(studentGPA); add(newStudentGPA); add(message); add(okButton); ageSlider.setMajorTickSpacing(10); ageSlider.setMinorTickSpacing(5); ageSlider.setPaintTicks(true); ageSlider.setPaintLabels(true); ageSlider.addChangeListener(this); newStudentGPA.addActionListener(this); okButton.addActionListener(this); } @Override public void stateChanged(ChangeEvent e){ Object obj = e.getSource(); if(obj == ageSlider){ int age = ageSlider.getValue(); message.setText("Age is: " + age); } }

@Override public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (obj == newStudentGPA) { getStudent(); studentGPA.setText("" + s.semesterGPA()); } if (obj == okButton) { message.setText("Ok button was pressed"); getStudent(); rp.b1.setText(s.firstName + " " + s.lastName + " " + s.age); } } public void getStudent() { String fname = fNameText.getText(); String lname = lNameText.getText(); int age = ageSlider.getValue(); s = new student(fname, lname, age); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!