7 Replies - 1330 Views - Last Post: 18 January 2011 - 08:52 PM Rate Topic: -----

#1 ReePa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 11

Newbie java swing app

Posted 17 January 2011 - 02:31 AM

Hi I have created a java swing app for an estate agents to calulate commision based on the amount of sales a specific sale's person has made, but I want to add a new variable in but dont know how as netbeans keeps shouting at me :)

At the moment my code looks like this

public class BackForm extends javax.swing.JFrame {
private String name;
private String sales;
    /** Creates new form BackForm */
    public BackForm(String inName, String inSales) {
        initComponents();
        name = inName;
        sales = inSales;

       
        double amtsales = 0, commission = 0;
        try{
            amtsales = Double.parseDouble(sales);
        }catch(Exception e){
            System.out.println("Need a numeric value for sales.");
        }
        if (amtsales > 249999) commission = amtsales *0.001;        
        else if (amtsales > 199999) commission = amtsales *0.0005;
        else if (amtsales > 149999) commission = amtsales *0.0003;       
        else if (amtsales > 99999) commission = amtsales *0.0001;
        else if (amtsales < 99999) commission = amtsales *0;
        


        

        lblname.setText ("Staff name       "+ name);
        lblsales.setText("Total sales     "+ amtsales);
        lblcomm.setText("Commission due      "+ commission);
        
        
        







    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        lblname = new javax.swing.JLabel();
        lblsales = new javax.swing.JLabel();
        lblcomm = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        lblname.setFont(new java.awt.Font("Century Gothic", 1, 11));

        lblsales.setFont(new java.awt.Font("Century Gothic", 1, 11));

        lblcomm.setFont(new java.awt.Font("Century Gothic", 1, 11));

        jButton1.setText("Quit");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(151, 151, 151)
                .addComponent(jButton1)
                .addContainerGap(163, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(84, 84, 84)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblsales, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                    .addComponent(lblcomm, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                    .addComponent(lblname, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(106, 106, 106))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(lblname, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblsales, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(lblcomm, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(30, 30, 30))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
this.dispose();        // TODO add your handling code here:
    }                                        

    

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblcomm;
    private javax.swing.JLabel lblname;
    private javax.swing.JLabel lblsales;
    // End of variables declaration  


The variable i want to add is that the commision is calculated along with a specific area ( different area's around town are easier to sell house's than others)
eg Area A gets X amount of commision
Area B gets X amount of commision

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Newbie java swing app

#2 ReePa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 11

Re: Newbie java swing app

Posted 17 January 2011 - 02:51 AM

Oh balls , please ignore the generated code for my gui in the middle , i cant edit my post sorry
Was This Post Helpful? 0
  • +
  • -

#3 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Newbie java swing app

Posted 17 January 2011 - 03:05 AM

It's good to avoid using GUI builders as they produce unmaintainable code. If you were to have hand written this code, you would be adding a variable as you would any other variable, declare and initialize.
Was This Post Helpful? 0
  • +
  • -

#4 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: Newbie java swing app

Posted 17 January 2011 - 03:13 AM

Completely separate your "business logic" code from your GUI code and you'll find making these types of changes to be much easier. Do not mix your GUI and your logic code, it leads to nothing but maintenance nightmares and fragile code.
Was This Post Helpful? 1
  • +
  • -

#5 ReePa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 11

Re: Newbie java swing app

Posted 17 January 2011 - 03:56 AM

Thanks for your wise words , im being taught atm using netbeans own ui code so its all I know, this is only the second swing app ive created lol . I will take what you guys have said on board though seeing as your the guru's lol
Was This Post Helpful? 0
  • +
  • -

#6 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Newbie java swing app

Posted 17 January 2011 - 03:25 PM

You can always start with sun's tutorial (I started with it myself). :)
Here is the swing's section:
http://download.orac...torial/uiswing/
Was This Post Helpful? 0
  • +
  • -

#7 midhir  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 27-October 10

Re: Newbie java swing app

Posted 18 January 2011 - 02:30 PM

There is also 5 great Swing tutitorials located on this site as well. They helped me out tons in my Java programming class I just finished.

Mike
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Newbie java swing app

Posted 18 January 2011 - 08:52 PM

View PostReePa, on 17 January 2011 - 05:56 AM, said:

Thanks for your wise words , im being taught atm using netbeans own ui code so its all I know, this is only the second swing app ive created lol .

You created ? :) You mean NetBeans created.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1