Assignment: This lab is designed to help students with painting shapes and with
ID: 3819963 • Letter: A
Question
Assignment: This lab is designed to help students with painting shapes and with timer usage.
Write code that does the following:
• Make a simple GUI with a single panel in the center, a panel called DrawablePanel
o DrawablePanel must implement the paintComponent method
• Give the GUI a JMenuBar
• The first JMenu on the menu bar should be the File menu
o It has two options – a checkbox called “Rotate” and an item called “Exit”
• The second JMenu should be the Animal menu
o It should have three radio buttons, each of which is a different animal
• When the user selects a radio button, draw that simple animal on the DrawablePanel
• If the user selects Rotate from a file menu, start a timer that loops through each of the other three animals in a sequence, changing the animal every 3 seconds. Make sure to change the radio button selected in the animal menu as well, to change alongside the animal on the panel. If Rotate is deselected, the timer should stop
• Exit does what you think it should
• All menu items should have proper hotkeys established (make sure a letter is underlined in the name of the item!)
Notes
• You will not be graded on how well you can draw using paintComponent, but on how much heart your drawings have <3
o Your drawings should be mildly more complex than just two shapes, though
Example GUI
The default state of the GUI, showing off the Animal menu (you do not need to match the animals shown)
The File menu shown, with Dolphin selected from Animals (note – this Dolphin was drawn by a former student and was too nice for me not to use as the example)
File Animals O Dolphin Elephant O CatExplanation / Answer
import java.util.*;
import java.lang.*;
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class createPanel {
private JFrame jFrame = null;
//JMenuBar is a JComponent and can be added to a Container like any other JComponent.
private JPanel jContentPane = null;
private JButton butButton = null;
private JLabel labLabel = null;
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(400, 300);
jFrame.setContentPane(getJContentPane());
jFrame.setTitle("Paint Panel");
return jFrame;
}
private JPanel getJContentPane() {
if (jContentPane == null) {
labLabel = new JLabel();
labLabel.setBounds(new Rectangle(50, 35, 194, 58));
labLabel.setText("");
jContentPane = new JPanel();
jContentPane.setLayout(null);]l;./
ContentPane.add(labLabel, null);
}
return jContentPane;
}
public class DrawablePanel extends JPanel,MainMenu implements ActionListener{
}
public class MainMenu {
menu2.add(elephant);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.