mercredi 14 décembre 2016

using an if statement inside button

I am currently stuck on a bit of program, I'm sure there is a way to do it but just can't think of it, so here it goes. so I am using eclipse window viewer and I made a GUI to how I want and I got a Ccombo with a few options to select from, and what I want to do is when a button is clicked I want the program to be able to see what they selected and then depending on what they selected have a different outcome put into another text field

OptionsOptimizer = new Shell();
    OptionsOptimizer.setSize(450, 340);
    OptionsOptimizer.setText("Options Optimizer");

    Label lblSpread = new Label(OptionsOptimizer, SWT.NONE);
    lblSpread.setAlignment(SWT.CENTER);
    lblSpread.setBounds(10, 10, 213, 15);
    lblSpread.setText("Type Of Spread");

    CCombo combo = new CCombo(OptionsOptimizer, SWT.BORDER);
    combo.setItems(new String[] {"Put Credit Spread", "Short Naked Put", "Put Broken Wing Butterfly", "Custom Naked Put", "Call Debit Spread", "Call Calander", "Call Ratio Backspread", "Put Diagonal", "Short Straddle", "Short Strangle", "Short Iron Condor", "Short Iron Butterfle"});
    combo.setBounds(10, 31, 213, 21);

    Label lblDaysUntilExperation = new Label(OptionsOptimizer, SWT.NONE);
    lblDaysUntilExperation.setAlignment(SWT.CENTER);
    lblDaysUntilExperation.setBounds(229, 10, 158, 15);
    lblDaysUntilExperation.setText("Days Until Experation");

    Days = new Text(OptionsOptimizer, SWT.BORDER);
    Days.setBounds(229, 31, 158, 21);

     Label lblPrice = new Label(OptionsOptimizer, SWT.NONE);
     lblPrice.setAlignment(SWT.CENTER);
     lblPrice.setBounds(10, 58, 76, 15);
     lblPrice.setText("Price");

     Price = new Text(OptionsOptimizer, SWT.BORDER);
     Price.setBounds(10, 79, 76, 21);

     Label lblProfit = new Label(OptionsOptimizer, SWT.NONE);
     lblProfit.setAlignment(SWT.CENTER);
     lblProfit.setBounds(229, 58, 76, 15);
     lblProfit.setText("Profit");

     Profit = new Text(OptionsOptimizer, SWT.BORDER);
     Profit.setBounds(229, 79, 76, 21);

     Label lblMargin = new Label(OptionsOptimizer, SWT.NONE);
     lblMargin.setAlignment(SWT.CENTER);
     lblMargin.setBounds(311, 58, 76, 15);
     lblMargin.setText("Margin");

     Margin = new Text(OptionsOptimizer, SWT.BORDER);
     Margin.setBounds(311, 79, 76, 21);

     Label lblPercentInThe = new Label(OptionsOptimizer, SWT.NONE);
     lblPercentInThe.setAlignment(SWT.CENTER);
     lblPercentInThe.setBounds(92, 58, 131, 15);
     lblPercentInThe.setText("Percent In The Money");

     ITM = new Text(OptionsOptimizer, SWT.BORDER);
     ITM.setBounds(92, 79, 131, 21);


     Label Volitility = new Label(OptionsOptimizer, SWT.NONE);
     Volitility.setBounds(10, 145, 377, 15);
     Volitility.setText("You want to volitility");

     Label lblOverTime = new Label(OptionsOptimizer, SWT.NONE);
     lblOverTime.setBounds(10, 166, 377, 15);
     lblOverTime.setText("Over time ");

     Label lblPriceYouShould = new Label(OptionsOptimizer, SWT.NONE);
     lblPriceYouShould.setBounds(10, 187, 377, 15);
     lblPriceYouShould.setText("Price you should leave");

     Label ROI = new Label(OptionsOptimizer, SWT.NONE);
     ROI.setBounds(10, 208, 377, 15);
     ROI.setText("Rate Of Interest");

     Label ROC = new Label(OptionsOptimizer, SWT.NONE);
     ROC.setBounds(10, 229, 377, 15);
     ROC.setText("Rate On Capital");

     Label Annual = new Label(OptionsOptimizer, SWT.NONE);
     Annual.setBounds(10, 250, 377, 15);
     Annual.setText("Annual impact");

     Label Equity = new Label(OptionsOptimizer, SWT.NONE);
     Equity.setBounds(10, 271, 377, 15);
     Equity.setText("% of equity");


     Button Enter = new Button(OptionsOptimizer, SWT.NONE);
     Enter.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent e) {
            double profit = Double.parseDouble(Profit.getText());
            double margin = Double.parseDouble(Margin.getText());
            double roi = profit/margin;
            double roundroi = Math.round(roi*10000)/100.0;
            ROI.setText("Your return on investment is " + roundroi + "%");
            double percent = Double.parseDouble(ITM.getText());
            double OTM = ((100 - percent)/100);
            int day = Integer.parseInt(Days.getText());
            double roc = (roi/day)*OTM;
            double roundroc = Math.round(roc*10000)/100.0;
            ROC.setText("Your return on capital per day is " + roundroc + "%");
            double annual = roc*365*.4;
            double roundannual = Math.round(annual*10000)/100.0;
            Annual.setText("Your annual return is " + roundannual + "% if you invested 40% of your total equity");

            Volitility.setText(combo.getText());
            }

    });

    Enter.setBounds(159, 108, 75, 25);
    Enter.setText("Evaluate");

}

Aucun commentaire:

Enregistrer un commentaire