This example is like this. But we have to include boxes for 2 bedrooms, 3 bedroo
ID: 3661346 • Letter: T
Question
This example is like this. But we have to include boxes for 2 bedrooms, 3 bedrooms, 4 bedrooms , no garage, 1 car, 2 car, 3 car. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class NewHome extends JFrame implements ItemListener { int newHome1 = 100000; int newHome2 = 120000; int newHome3 = 180000; int newHome4 = 250000; JCheckBox homeBox1 = new JCheckBox("Aspen $" + newHome1,true); JCheckBox homeBox2 = new JCheckBox("Brittany $" + newHome2,false); JCheckBox homeBox3 = new JCheckBox("Colonial $" + newHome3,false); JCheckBox homeBox4 = new JCheckBox("Dartmoor $" + newHome4,false); JLabel homeBuildersLabel = new JLabel("Home Builders Inc."); JLabel homeOptionLabel = new JLabel("Select the desired model"); JLabel homeOptionLabel0 = new JLabel(""); JLabel ePrice = new JLabel("The price of your home is:"); JTextField totPrice = new JTextField(10); public NewHome() { super("Home Price Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel(); pane.add(homeBuildersLabel); pane.add(homeOptionLabel); pane.add(homeOptionLabel0); pane.add(homeBox1); pane.add(homeBox2); pane.add(homeBox3); pane.add(homeBox4); ButtonGroup homeGroup = new ButtonGroup(); homeGroup.add(homeBox1); homeGroup.add(homeBox2); homeGroup.add(homeBox3); homeGroup.add(homeBox4); pane.add(ePrice); pane.add(totPrice); totPrice.setText("$" + newHome1); homeBox1.addItemListener(this); homeBox2.addItemListener(this); homeBox3.addItemListener(this); homeBox4.addItemListener(this); setContentPane(pane); } public static void main(String[] arguments) { JFrame aFrame = new NewHome(); aFrame.setSize(250,500); aFrame.setVisible(true); } public void itemStateChanged(ItemEvent event) { if(homeBox1.isSelected()) totPrice.setText("$" + newHome1); else if(homeBox2.isSelected()) totPrice.setText("$" + newHome2); else if(homeBox3.isSelected()) totPrice.setText("$" + newHome3); else // if(homeBox4.isSelected()) totPrice.setText("$" + newHome4); } }Explanation / Answer
About Design Pattern What is the design pattern? If a problem occurs over and over again, a solution to that problem has been used effectively. That solutionis described as a pattern. The design patterns are language-independent strategies for solving commonobject-oriented design problems. When you make a design, you should know the names of some commonsolutions. Learning design patterns is good for people to communicate each other effectively. In fact, youmay have been familiar with some design patterns, you may not use well-known names to describe them.SUN suggests GOF (Gang Of Four--four pioneer guys who wrote a book named "Design Patterns"-Elements of Reusable Object-Oriented Software), so we use that book as our guide to describe solutions.Please make you be familiar with these terms and learn how other people solve the code problems. Do I have to use the design pattern? If you want to be a professional Java developer, you should know at least some popular solutions to codingproblems. Such solutions have been proved efficient and effective by the experienced developers. Thesesolutions are described as so-called design patterns. Learning design patterns speeds up your experienceaccumulation in OOA/OOD. Once you grasped them, you would be benefit from them for all your life andjump up yourselves to be a master of designing and developing. Furthermore, you will be able to use theseterms to communicate with your fellows or assessors more effectively.Many programmers with many years experience don't know design patterns, but as an Object-Orientedprogrammer, you have to know them well, especially for new Java programmers. Actually, when yousolved a coding problem, you have used a design pattern. You may not use a popular name to describe it or may not choose an effective way to better intellectually control over what you built. Learning how theexperienced developers to solve the coding problems and trying to use them in your project are a best wayto earn your experience and certification.Remember that learning the design patterns will really change how you design your code; not only will yoube smarter but will you sound a lot smarter, too. How many design patterns? Many. A site says at least 250 existing patterns are used in OO world, including Spaghetti which refers topoor coding habits. The 23 design patterns by GOF are well known, and more are to be discovered on theway.Note that the design patterns are not idioms or algorithms or components. What is the relationship among these patterns? Generally, to build a system, you may need many patterns to fit together. Different designer may usedifferent patterns to solve the same problem. Usually: import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.InputEvent; import java.util.Random; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JToggleButton; import javax.swing.JToolBar; public class Minesweeper extends JFrame { private int columns = 10; private int rows = 10; private static final long serialVersionUID = 1L; // Stores which cells are bombs and which are not boolean jBombs[][] = new boolean[rows][columns]; // Stores information on which cell has been displayed boolean jShown[][] = new boolean[rows][columns]; // Stores information on surrounding cells int jCells[][] = new int[rows][columns]; private int currX, currY = 0; JToggleButton jButtons[] = new JToggleButton[columns*rows]; private JPanel jPanel = null; private JToolBar jToolBar = null; private JPanel jContentPane = null; private JButton jBtnNewGame = null; private JProgressBar jProgressBar = null; /** * This is the default constructor */ public Minesweeper() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(436, 315); this.setContentPane(getJPanel()); this.setTitle("Minesweeper"); } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(getJToolBar(), BorderLayout.NORTH); jPanel.add(getJContentPane(), BorderLayout.CENTER); jPanel.add(getJProgressBar(), BorderLayout.SOUTH); } return jPanel; } /** * This method initializes jToolBar * * @return javax.swing.JToolBar */ private JToolBar getJToolBar() { if (jToolBar == null) { jToolBar = new JToolBar(); jToolBar.setFloatable(false); jToolBar.add(getJBtnNewGame()); } return jToolBar; } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { GridLayout gridLayout = new GridLayout(); gridLayout.setRows(rows); gridLayout.setColumns(columns); jContentPane = new JPanel(); jContentPane.setLayout(gridLayout); BuildBoard(); } return jContentPane; } private void BuildBoard() { // JContentPane will call this function before jProgressBar was built when first started if(jProgressBar != null) // So we check to see if the progress bar has been initialized { jProgressBar.setValue(0); } jContentPane.removeAll(); int i = 0; for(int x = 0; xRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.