This exercise is based off of the ComboBoxes Video listed in the Week 11 Assignm
ID: 3701477 • Letter: T
Question
This exercise is based off of the ComboBoxes Video listed in the Week 11 Assignment instructions in Canvas. This Exercise will be graded Manually.
Follow along with the video and create an extended JFrame class that has a ComboBox, object with an included "main" method. The JFrame must use the "Flow" layout, have a JComboBox, and JLabel. Instead of using Animal names for the values in the JComboBox, include the last 7 courses you have taken in this program like: "ICT362","ICT377".
REQUIRED FOR A GRADE
The ComboBoxes class must extend JFrame with the title as the
student's name. The value of the JLabel should be the students
first name initially and then change to the selected combobox value
as the ComboBox is changed.
The ComboBox must list at least 7 courses
The code I have:
import javax.swing.*;
import java.awt.*;
/**
* Enter JavaDoc Class information here
* Include a description of what this class does!!!
* Make sure you include your full name
* Filename: ComboBoxes.java
*/
public class ComboBoxes {
// ******* Create code here ************
} // end ComboBoxes class
Explanation / Answer
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; /** * Enter JavaDoc Class information here * Include a description of what this class does!!! * Make sure you include your full name * Filename: ComboBoxes.java */ public class ComboBoxes extends JFrame { public ComboBoxes(String name) { JFrame frame = new JFrame(name); String[] str = name.split(" "); JLabel lbl1 = new JLabel(str[0]); lbl1.setBounds(50,50, 100,30); String names[] = {"Java", "C", "C++", "Python", "Php", "Perl"}; JComboBox combo = new JComboBox(names); combo.setBounds(200, 50,100,30); frame.add(lbl1); frame.add(combo); frame.setLayout(null); frame.setSize(350,200); frame.setVisible(true); combo.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e) { lbl1.setText(combo.getSelectedItem().toString()); } }); } // ******* Create code here ************ public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter student name : "); String name = scan.nextLine(); new ComboBoxes(name); } } // end ComboBoxes class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.