Hi, I need help with this problem. Here is my program = import javax.swing.*; im
ID: 3625501 • Letter: H
Question
Hi, I need help with this problem. Here is my program =import javax.swing.*;
import java.awt.event.*;
class MonthlySalesTax extends JFrame implements ActionListener
{
private JPanel panel;
private JLabel messageLabel_monthlysales;
private JTextField monthlysalesTextField;
private JButton saletaxButton;
private final int WINDOW_WIDTH = 250;
private final int WINDOW_HEIGHT = 250;
public MonthlySalesTax()
{
setTitle("Monthly Sales Tax");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
private void buildPanel()
{
messageLabel_monthlysales = new JLabel("Enter Total sales for the month ");
monthlysalesTextField = new JTextField(10);
saletaxButton = new JButton("Calculate Monthly Sales Tax");
saletaxButton.addActionListener(new CalculateMST());
panel = new JPanel();
panel.add(messageLabel_monthlysales);
panel.add(monthlysalesTextField);
panel.add(saletaxButton);
}
public void actionPerformed(ActionEvent e)
{
String input;
double CountyTax;
double StateTax;
double TotalsalesTax;
input = monthlysalesTextField.getText();
CountyTax = (Double.parseDouble(input)* 0.02);
StateTax = (Double.parseDouble(input)* 0.04);
TotalsalesTax = (CountyTax + StateTax);
JOptionPane.showMessageDialog(null, " The Amount Of County Sales Tax : " + CountyTax + " The Amount Of State Sales Tax : " + StateTax + " The Total Sales Tax : " + TotalsalesTax );
}
public static void main(String[] args)
{
MonthlySalesTax ST = new MonthlySalesTax();
}
}
The problem is I want all of the GUI to be on one thing, I would like the message to be taken out that gives you the information after calculated and that info to be on the same page as where the original GUI is. Please be able to compile and have the entire GUI on the same page. Will rate high!
Explanation / Answer
Dear,
Modified the code
import javax.swing.*; //Needed for swing classes
import java.awt.event.*; //Needed for ActionListener Interface
class MonthlySalesTaxDemo extends JFrame
{
private JPanel panel; // To reference a panel
private JLabel messageLabel_monthlysales;
// To reference a label
private JTextField monthlysalesTextField;
// To reference a text field
private JButton saletaxButton;
// To reference a button
private final int WINDOW_WIDTH = 250; // Window width
private final int WINDOW_HEIGHT = 250;// Window height
// Constructor
public MonthlySalesTaxDemo()
{
// Set the window title.
setTitle("Monthly Sales Tax");
// Set the size of the window.
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
// Specify what happens when the close button
// is clicked.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Build the panel and add it to the frame.
buildPanel();
// Add the panel to the frame's content pane.
add(panel);
// Display the window.
setVisible(true);
}
//The buildPanel method adds a label, text field,
and a //button to a panel.
private void buildPanel()
{
// Create a label to display instructions.
messageLabel_monthlysales =
new JLabel("Enter Total sales for the month ");
monthlysalesTextField = new JTextField(10);
// Create a button with the caption "Calculate".
saletaxButton = new
JButton("Calculate Monthly Sales Tax");
saletaxButton.addActionListener
(new CalculateMST());
panel = new JPanel();
panel.add(messageLabel_monthlysales);
panel.add(monthlysalesTextField);
panel.add(saletaxButton);
}
public class CalculateMST implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String input; // To hold the user's input
double CountyTax;
double StateTax;
double TotalsalesTax;
input = monthlysalesTextField.getText();
CountyTax = (Double.parseDouble(input)* 0.02);
StateTax = (Double.parseDouble(input)* 0.04);
TotalsalesTax = (CountyTax + StateTax);
JOptionPane.showMessageDialog(null, " The Amount Of County Sales Tax : " + CountyTax + " The Amount Of State Sales Tax : " + StateTax + " The Total Sales Tax : " + TotalsalesTax );
}
}
}
public class MonthlySalesTax
{
public static void main(String[] args)
{
MonthlySalesTaxDemo ST = new MonthlySalesTaxDemo();
}
}
Hope this will help you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.