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

Hey, mostly done with my project, but I\'m having a hard time trying to get my w

ID: 3863378 • Letter: H

Question

Hey, mostly done with my project, but I'm having a hard time trying to get my window to look like what it is above. Below is my Java program. Can you help? Thanks.

import javax.swing.*; //for swing classes

import java.awt.BorderLayout;
import java.awt.event.*; //for event handling

public class LeavinesPropertyTax extends JFrame
{
   private JPanel panel; // to hold components
   private JLabel actualValueLabel;
   private JLabel assessmentValueLabel;
   private JLabel propertyTaxLabel;
   private JTextField actualValueTF; // text field
   private JButton calcButton1;
   private JButton calcButton2;
   private final int WINDOW_WIDTH = 700;
   private final int WINDOW_HEIGHT = 200;
  
  
  
   // start of constructor
   public LeavinesPropertyTax()
   {
       // set the title bar text
       setTitle("Property Tax");
      
       // set the size of the window
       setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
      
       // specifying what happens when the close button is clicked
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
       // build the panel and adding it the the frame
       buildPanel();
      
       // add the panel to the frame's content pane
       add(panel);
      
       // display the window
       setVisible(true);
      
   } // end of constructor
  
  
   // start of buildPanel method
   private void buildPanel ()
   {
       // actual value label to display instructions.
       actualValueLabel = new JLabel("Enter the property value $");
      
       // assessment value label
       assessmentValueLabel = new JLabel();
      
       // property tax label
       propertyTaxLabel = new JLabel();
      
       // actual vale text field
       actualValueTF = new JTextField(8);
      
       // calculation buttons
       calcButton1 = new JButton("Calculate Assessment Value");
       calcButton2 = new JButton("Calculate the Property Tax");
      
      
      
       // the action listers to the button
       calcButton1.addActionListener(new CalcButtonListener());
       calcButton2.addActionListener(new CalcButtonListener());
      
       // JPanel object
       panel = new JPanel();
      
       // add the components to the panel
       panel.add(actualValueLabel);
       panel.add(actualValueTF);
       panel.add(calcButton1);
       panel.add(calcButton2);
       panel.add(assessmentValueLabel);
       panel.add(propertyTaxLabel);
      
       // Adds the panel to the content pane
       add(panel);
      
       // calculation buttons added to the content pane
       JPanel subPanel = new JPanel();
       subPanel.add( calcButton1);
       subPanel.add( calcButton2);
       panel.add(subPanel, BorderLayout.SOUTH);
       //add(calcButton1, BorderLayout.EAST);
       //add(calcButton2, BorderLayout.WEST);
      
       // Displays the window
       setVisible(true);
      
   } // end of buildPanel method
  
   // The class CalcButtonListener is an action listener class for the calculate button.
   private class CalcButtonListener implements ActionListener
   {
       // This method is executed when the user clicks on the button that says "calculate."
       public void actionPerformed(ActionEvent e)
       {
           String input;
           String actionCommand = e.getActionCommand();
           double amount;
           double assessmentValue;
           double propertyTax;
          
          
          
          
          
          
          
           // get the text entered by the user into the actual value text field.
           input = actualValueTF.getText();
          
           // convert the input into double
           amount = Double.parseDouble(input);
          
           // calculate the property tax
           assessmentValue = amount * 0.4;
          
           // calculate the property tax
           propertyTax = assessmentValue * 0.64 / 100;
          
           // Determine which button was clicked and display the output.
                       if (actionCommand.equals("Calculate Assessment Value"))
                       {
                           JOptionPane.showMessageDialog(null,"Assessment value: $" + assessmentValue );
                       }
                      
                       else if (actionCommand.equals("Calculate the Property Tax"))
                       {
                           JOptionPane.showMessageDialog(null,"Property tax: $" + propertyTax );
                       }
          
          
       } // end of actionPerformed method
   } // end of calcButtonListener class
  
   // the object to the LeavinesPropertyTex class
   public static void main(String args[])
   {
       new LeavinesPropertyTax();
   } // end of main method
} // end of LeavinesPropertyTax class

Property Tax Enter the property value Calculate Assessment Value Calculate Property Tax

Explanation / Answer

Steps to get the desired screen:
1. Create a label, name it as "Property Tax" and select Properties-> border->choose Line border
2. Create a label and name it as "Enter the property value"
3. Create a text field, select Properties-> border->choose Line border. Choose edit text and clear the textfield content
4. Create two buttons, name them as "Calculate Assessmet value" and "Calculate
property tax". Then select Properties -> border->choose Line border. Then deselect the contentAreaFilled checkbox.
5. To set boreder for the jframe use coding part. Include
import javax.swing.BorderFactory;
import java.awt.Color;

Then in the frame constructor, include the following line of code:

getRootPane().setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK));