Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java create a Gui that uses a combo box to select an orange, cheesecake, and

ID: 3803469 • Letter: I

Question

In Java create a Gui that uses a combo box to select an orange, cheesecake, and a full sandwhich. Use JLabels and JTextField objects to ask them for measurements so a radius for an orange, a base and height for a cheesecake a side length for a squre. Using the paint Component, add a JButton to draw each shape when the user clicks "Draw an Orange", "Draw a full sandwhich", "Draw a cheesecake". The orange should be orange, the cheesecake should be green, the full sandwhich should be blue. Label above the orange what the user inputted as the radius, Label the calculated area of the circle below. Label on the sides of the sandwhich what the user put as the side length, calculate the area of the sandwhich above. Label on the sides of the cheesecake what the user put as the base and height, calculate the area of the sandwhich below. Only the questions relevant to the selection should be displayed. For example, when you click orange, the user is prompted only for the radius and given the JButton "Draw an Orange".

Explanation / Answer

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Test extends JPanel {
private static JComboBox comboBox;
private static JTextField textField;
public Test() {
super(new BorderLayout());
JPanel labelPanel = new JPanel(new GridLayout(2, 1)); // 2 rows 1 column
add(labelPanel, BorderLayout.WEST);
JPanel fieldPanel = new JPanel(new GridLayout(2, 1)); // 2 rows 1 column
add(fieldPanel, BorderLayout.CENTER);
JLabel labelCombo = new JLabel("Bank Code");

String[] options = { "Option1", "Option2", "Option3", "Option4", "Option15" };
comboBox = new JComboBox(options);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
JLabel labelTextField = new JLabel("Bank account number");
textField = new JTextField();
fieldPanel.add(comboBox);
fieldPanel.add(textField);
}

public static void main(String[] args) {
final Test form = new Test();
JButton submit = new JButton("Submit Form");
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createIban((String) comboBox.getSelectedItem(), textField.getText());
}
});
JFrame f = new JFrame("Text Form Example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(form, BorderLayout.NORTH);
JPanel p = new JPanel();
p.add(submit);
f.getContentPane().add(p, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}

private static void createIban(String selectedItem, String text) {
System.out.println("Im in createIban with the values: " + selectedItem + " and " + text);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote