Question: Create an application that displays some flags for different countries. Each flag will be matched with a button. When a button is pressed the country

Create an application that displays some flags for different countries. Each flag will be matched with a button. When a button is pressed the country name will be displayed (or some other interesting information).

  1. Create a new project.
    1. Create a folder in the root of the project called images.
    2. Save the attached flags icons in the images folder.
  2. Create a new Flags class
    1. The class must extend JFrame and implement ActionListener.
    2. In the Flags constructor, set up a GridLayout that is three rows tall and three columns wide. I set up gaps of five horizontal and vertical.
    3. Set the layout for the Flags class to the GridLayout in step 2a.
  3. Create the images and buttons for each flag
    1. Create a Panel for each flag and button combination.
    2. Set up a new GridLayout for each button / image combination that is two rows tall and one column wide. I set up gaps of three horizontal and vertical.
    3. Set the Layout of the flag and button panel.
    4. JLabels allow text labels or icon labels. Put a flag icon in a JLabel by creating a new ImageIcon with one of the GIF files attached. The name will be the icon name prefixed with the images directory name. For example: JLabel flag = new JLabel(new ImageIcon("images/China.gif")).
    5. Create a button with the country name for the button.
    6. Add an actionListener on the button that is the Flags object.
    7. Add the flag icon JLabel and the button to the Flag layout.
    8. Set a tooltip on the flag and button panel that says "Flag of " and the country name.
    9. Add the panel to the Flag class.
    10. Repeat for each country. This is a good opportunity for a method to remove duplication.
  4. Create the actionPerformed() method to implement the ActionListener.
    1. Get the source of the action, which will be a JButton. It will be necessary to cast the Object to a JButton.
    2. Create a JOptionPane to display "Button pressed " and the country name by displaying the button text.
  5. In the main method, instantiate the Flag class.
    1. Set the title.
    2. Set the windows size. 700 by 700 worked fine.
    3. Set the default close operation to EXIT_ON_CLOSE, so the application will end cleanly.
    4. Finally, set visible to true.
  6. Run the application and test the presentation and functionality.
  7. As required for all assignments from now on
    1. validate the proper functionality using the example answers below and review the Concepts and Ideas checklist format the code
    2. add a comment at the top of the file that reads @ author and your name
    3. build the javadocs
    4. Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.
    5. Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.
    6. submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Example:

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!