Results 1 to 2 of 2

Thread: GUI problem

  1. #1
    nanna is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Unhappy GUI problem

    Hi,
    I need your help in checking what is the error in this program?? When I try to run it error messages appear ??

    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    /**
      The RetailPriceWindow class displays a JFrame that lets a user enter
      a wholecost of an item and markup percentage of the item.When the calculate button is clicked, a dialog box is displayed with the item`s retail price.
    
      
    */
    
    public class RetailPriceWindow extends JFrame {
        private JPanel panel;
        private JLabel costLabel;
        private JLabel markupLabel;
        private JTextField costeTextField;
        private JTextField markuptextField;
        private JButton calcButton;
        private final int WINDOW_WIDTH = 350;
        private final int WINDOW_HEIGHT = 200;
    
    /**
    constructor
    */
    
      public RetailPriceWindow() {
        setTitle("Item Retail Price");
        setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        buildPanel();
        add(panel);
        setVisible(true); }
      public static void main (String[] args) {
          new RetailPriceWindow();
      private void buildPanel() {
        panel = new JPanel();
        panel.add(costLabel);
        panel.add(markupLabel);
        panel.add(costTextField);
        panel.add(markupTextField);
        
        costLabel = new JLabel("Enter the item wholecost");
        markupLabel = new JLabel("Enter the item markup percentage");
        costTextField = new JTextField(10);
        markupTextField = new JTextField(10);
        calcButton = new JButton("Calculate");
        calcButton.addActionListener(new ButtonListener());
        panel.add(calcButton);
        
      private class ButtonListener implements ActionListener {
    /**
      The actionperformed methods executes when the user clicks on the Calculate button.
      @param e The event object.
    */
       public void actionPerformed(ActionEvent e) {
          String input1;
          String input2;
          double retailprice;
          input = costTextField.getText();
          input = markupTextField.getText();
          retailprice = Double.parseDouble(input1)*(input2)/50;
       JOptionPane.showMessageDialog(null, "The retail price for" + "the item`s wholecost" +
                   input1 + " and the item`s markup percentage" + input2 + " is" + retailprice);
         
        }      
       }
      }
     }
    }
    Run Test:
    RetailPriceWindow.java:34: illegal start of expression
    private void buildPanel() {
    ^
    RetailPriceWindow.java:34: illegal start of expression
    private void buildPanel() {
    ^
    RetailPriceWindow.java:34: ';' expected
    private void buildPanel() {
    ^
    RetailPriceWindow.java:49: illegal start of expression
    private class ButtonListener implements ActionListener
    ^
    4 errors

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    you cannot declare method in the method.Look you declared the method in the main method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •