Question
Write a java program so the user can choose the dimensions of the flag and which country's flag to be displayed. Also, create a class
Write a java program so the user can choose the dimensions of the flag and which country's flag to be displayed.
Also, create a class country, which has the following properties: name, color1, color2, color3, and if the stripes are horizontal or vertical.You will need to create 6 instances of the country class.
The user should be able to select between 3 flags with vertical stripes (Italy, France, Romania) and 3 flags with horizontal stripes (Germany, Holland, Hungary), using the menubar.
The following is the code i currently have:
FlagComponent Class
import java.awt.Color; import java.awt.Graphics;
import javax.swing.JComponent;
@SuppressWarnings("serial") public class FlagComponent extends JComponent { private int xLeft, yTop, width; private Color c1; private Color c2; private Color c3; public FlagComponent(int width, Color c1, Color c2, Color c3){ xLeft = 100; yTop = 100; this.width = width; this.c1 = c1; this.c2 = c2; this.c3 = c3; } public void paintComponent(Graphics g) { xLeft = 100; yTop = 100; width = 90; g.setColor(c1); g.fillRect(xLeft, yTop, width / 3, width * 2 / 3); g.setColor(c2); g.fillRect(xLeft + 2 * width / 3, yTop, width / 3, width * 2 / 3); //g.setColor(Color.WHITE); //g.fillRect(xLeft + width/3, yTop, width /3, width * 2 / 3); g.setColor(c3); g.fillRect(xLeft + width / 3, yTop, xLeft + width / 3, width * 2 / 3); //g.fillRect(xLeft + width / 3, yTop + width * 2 / 3, xLeft + width * 2 / 3); //g.drawLine(130, 100, 160, 100); //g.drawLine(130, 160, 160, 160); }
}
FlagProgram Class
import java.awt.Color; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem;
@SuppressWarnings("serial") public class FlagProgram extends JFrame { private JMenu dimensionMenu = new JMenu("Dimenions"); private JMenu countryMenu = new JMenu("Country"); private JMenuItem width100Item = new JMenuItem("100"); private JMenuItem width200Item = new JMenuItem("200"); private JMenuItem width500Item = new JMenuItem("500");
private JMenuItem italyItem = new JMenuItem("Italy"); private JMenuItem franceItem = new JMenuItem("France"); private JMenuItem romaniaItem = new JMenuItem("Romania"); @SuppressWarnings("unused") public static void main(String[] args) { FlagProgram flagProgram= new FlagProgram(); }
public FlagProgram() { this.setSize(600, 800); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(dimensionMenu); menuBar.add(countryMenu); dimensionMenu.add(width100Item); dimensionMenu.add(width200Item); dimensionMenu.add(width500Item); countryMenu.add(italyItem); countryMenu.add(franceItem); countryMenu.add(romaniaItem); ActionListener listener = new FlagListener(); this.setVisible(true); this.add(new FlagComponent(100, Color.BLUE, Color.WHITE, Color.RED)); } public class FlagListener implements ActionListener() { public void actionPerformed(ActionEvent Event){ } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started