import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BoxLayout;
// Graphical-User-Interface for Desktop in Java using Java Swing.
public class FRQMenu extends JFrame implements ActionListener {
private JFrame frame;
private JMenuBar menubar;
private JMenu menu;
private JPanel panel;
private JLabel message = new JLabel("Click on Menu to select an FRQ.");
private JLabel n_msg = new JLabel("We are the CODE MONKEYS \n");
private JLabel fillable = new JLabel("");
public final String[] MENUS = { // 1D Array of Menu Choices
"FRQ No. 1: Methods and Control Structures", "FRQ No. 2: Classes", "FRQ No. 3: Array/ArrayList", "FRQ No. 4: 2D Array"
};
// Statics to assist with timer and messaging, single copy (no instance)
private static int delay = 20;
private static int step = 1;
private static String hashes = "";
// Constructor enables the Frame instance, the object "this.frame"
public FRQMenu(String title) {
// Initializing Key Objects
frame = new JFrame(title);
menubar = new JMenuBar();
menu = new JMenu("Menu");
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
// Initializing Menu objects and adding actions
for (String mx : MENUS) {
JMenuItem m = new JMenuItem(mx);
m.addActionListener(this);
menu.add(m);
}
// Adding / Connecting Objects
menubar.add(menu);
frame.setJMenuBar(menubar);
frame.add(message);
frame.add(panel);
panel.add(n_msg);
panel.add(message);
panel.add(fillable);
// Sets JFrame close operation to Class variable JFrame.EXIT_ON_CLOSE
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set the size of window based on objects
frame.setSize(500,500);
// makes the frame object visible according to properties previously set
frame.setVisible(true); // flow of control shifts to frame object
}
// event from user selecting a menu option
public void actionPerformed(ActionEvent e) {
// local variable to ActinEvent
String selection = e.getActionCommand(); // menu selection
String msg; // local variable to create response from action
final String[] COLORS = {"Red", "Green", "Blue", "Purple"}; // add more colors here
final String start_msg = "<html>"; // html building
final String end_msg = "</html>";
final String hash = "#";
// run code based on the menuItem that was selected
if ( selection.equals(MENUS[0]) ) { // Hello Action
msg = start_msg + "<p> Explaining: " + selection + "</p>";
message.setText(msg);
fillable.setText("<html><body>Generally speaking, the Methods and Control Structures FRQ involve having to write the code for a certain method that College Board provides you with for a specified purpose. For example, with the FRQ I just did, in part a, I had to create a method for getScore, which returned the score of the user. If the game that the user played was a bonus round, their total score would be multiplied by 3. For part b, I had to write the code for the playManyTimes method, which returned the highest score of the games played if the play() method was called more than once.</body></html>");
} else if ( selection.equals(MENUS[1]) ) { // Color Action
msg = start_msg + "<p> Explaining: " + selection + "</p>";
message.setText(msg);
fillable.setText("<html><body>Classes FRQs can be one of, if not the easiest FRQ in the entire exam. This is primarily because of its brevity and simplicity of knowledge. When you approach this specific problem, you primarily have to write a large amount of code by yourself, and know some of the intricacies of writing classes. Unlike most of the FRQs, this is not very fill-in-the-blank. Thus, when approaching this frq, it is necessary for students to be aware of how methods work, and how to approach certain ideas of classes.</body></html>");
} else if ( selection.equals(MENUS[2])){ // Loading Bar Action
msg = start_msg + "<p> Explaining: " + selection + "</p>";
message.setText(msg);
fillable.setText("<html><body>In the ArrayList FRQ, you'll be presented with a set of coding challenges involving ArrayLists in Java. Just like the example you mentioned, part (a) might require you to create a method, such as getScore, with a specific purpose. For instance, it could involve calculating and returning a user's score, taking into account bonus rounds that might triple their total score. In part (b) of the question, you could be asked to implement a method like playManyTimes. This method might be designed to analyze multiple game rounds, and your task would be to return the highest score achieved among these rounds if the play() method is called more than once. Overall, the ArrayList FRQ evaluates your ability to work with dynamic data structures, such as ArrayLists, in Java. Your goal is to write code that accomplishes well-defined objectives, including handling potential complexities and variations in the problem.</body></html>");
}
else {
msg = start_msg + "<p> Explaining: " + selection + "</p>";
message.setText(msg);
fillable.setText("<html><body>The Array/Array Lists FRQ asks the student to write program code to create objects of a class and call methods. It also asks the students to write program code to satisfy method specifications using expressions, conditional statements, and iterative statements. CollegeBoard provides the student with a ReviewAnalysis class, and I had to write code for two methods inside said class. In part A, I had to write code for a loop that accessed each element of the array instance variable allReviews and returned the calculated average of all the return values of the method getRating. I had to declare and initialize a variable to hold the sum of all ratings. Inside the loop, I had to call the method getRating on all Review elements in allReviews, accumulating a total of the ratings. In part B, I had to write an array list to hold string values.</body></html>");
}
}
// Driver turn over control the GUI
public static void main(String[] args) {
// Activates an instance of FRQMenu class, which makes a JFrame object
new FRQMenu("Menu");
}
}
FRQMenu.main(null);
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.