How do i call a variable from one method/ or create a field variable from it












-2















I need to use the args[2] instead of the 1.12 in balloon 2 same for args[0] and args[1] but that's for later in the program. There is a frame and everything I removed them, thought the site was asking me to do so.



import javax.swing.*;
import java.awt.*;

public class ProportionalBalons extends JPanel {

public void runArguments(String args) {
String currencyCostumerHas = args[0];
String currencyCostumerWants = args[1];
String USDollarToEUEuroexchangeValueS = args[2];
int exchangeValue = new Integer(USDollarToEUEuroexchangeValueS).intValue();
}


public void paintComponent(Graphics g) {
double balon1Diameter = costumerDeposit;
double balon2Diameter = costumerDeposit * 1.12;
//ballon 1
g.drawOval(10, 10, balon1Diameter, balon1Diameter);
//ballon 2
g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);

}
}









share|improve this question




















  • 2





    Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

    – Timothy Truckle
    Dec 28 '18 at 18:13













  • Is passing it in as an argument to paintComponent not an option?

    – Stalemate Of Tuning
    Dec 28 '18 at 18:14






  • 1





    @StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

    – Christopher Schultz
    Dec 28 '18 at 18:16











  • @ChristopherSchultz Ah, makes sense then.

    – Stalemate Of Tuning
    Dec 28 '18 at 18:17
















-2















I need to use the args[2] instead of the 1.12 in balloon 2 same for args[0] and args[1] but that's for later in the program. There is a frame and everything I removed them, thought the site was asking me to do so.



import javax.swing.*;
import java.awt.*;

public class ProportionalBalons extends JPanel {

public void runArguments(String args) {
String currencyCostumerHas = args[0];
String currencyCostumerWants = args[1];
String USDollarToEUEuroexchangeValueS = args[2];
int exchangeValue = new Integer(USDollarToEUEuroexchangeValueS).intValue();
}


public void paintComponent(Graphics g) {
double balon1Diameter = costumerDeposit;
double balon2Diameter = costumerDeposit * 1.12;
//ballon 1
g.drawOval(10, 10, balon1Diameter, balon1Diameter);
//ballon 2
g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);

}
}









share|improve this question




















  • 2





    Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

    – Timothy Truckle
    Dec 28 '18 at 18:13













  • Is passing it in as an argument to paintComponent not an option?

    – Stalemate Of Tuning
    Dec 28 '18 at 18:14






  • 1





    @StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

    – Christopher Schultz
    Dec 28 '18 at 18:16











  • @ChristopherSchultz Ah, makes sense then.

    – Stalemate Of Tuning
    Dec 28 '18 at 18:17














-2












-2








-2








I need to use the args[2] instead of the 1.12 in balloon 2 same for args[0] and args[1] but that's for later in the program. There is a frame and everything I removed them, thought the site was asking me to do so.



import javax.swing.*;
import java.awt.*;

public class ProportionalBalons extends JPanel {

public void runArguments(String args) {
String currencyCostumerHas = args[0];
String currencyCostumerWants = args[1];
String USDollarToEUEuroexchangeValueS = args[2];
int exchangeValue = new Integer(USDollarToEUEuroexchangeValueS).intValue();
}


public void paintComponent(Graphics g) {
double balon1Diameter = costumerDeposit;
double balon2Diameter = costumerDeposit * 1.12;
//ballon 1
g.drawOval(10, 10, balon1Diameter, balon1Diameter);
//ballon 2
g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);

}
}









share|improve this question
















I need to use the args[2] instead of the 1.12 in balloon 2 same for args[0] and args[1] but that's for later in the program. There is a frame and everything I removed them, thought the site was asking me to do so.



import javax.swing.*;
import java.awt.*;

public class ProportionalBalons extends JPanel {

public void runArguments(String args) {
String currencyCostumerHas = args[0];
String currencyCostumerWants = args[1];
String USDollarToEUEuroexchangeValueS = args[2];
int exchangeValue = new Integer(USDollarToEUEuroexchangeValueS).intValue();
}


public void paintComponent(Graphics g) {
double balon1Diameter = costumerDeposit;
double balon2Diameter = costumerDeposit * 1.12;
//ballon 1
g.drawOval(10, 10, balon1Diameter, balon1Diameter);
//ballon 2
g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);

}
}






java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 18:14









Lavish Kothari

828514




828514










asked Dec 28 '18 at 18:06









Lirim KusariLirim Kusari

32




32








  • 2





    Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

    – Timothy Truckle
    Dec 28 '18 at 18:13













  • Is passing it in as an argument to paintComponent not an option?

    – Stalemate Of Tuning
    Dec 28 '18 at 18:14






  • 1





    @StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

    – Christopher Schultz
    Dec 28 '18 at 18:16











  • @ChristopherSchultz Ah, makes sense then.

    – Stalemate Of Tuning
    Dec 28 '18 at 18:17














  • 2





    Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

    – Timothy Truckle
    Dec 28 '18 at 18:13













  • Is passing it in as an argument to paintComponent not an option?

    – Stalemate Of Tuning
    Dec 28 '18 at 18:14






  • 1





    @StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

    – Christopher Schultz
    Dec 28 '18 at 18:16











  • @ChristopherSchultz Ah, makes sense then.

    – Stalemate Of Tuning
    Dec 28 '18 at 18:17








2




2





Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

– Timothy Truckle
Dec 28 '18 at 18:13







Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. idownvotedbecau.se/noresearch

– Timothy Truckle
Dec 28 '18 at 18:13















Is passing it in as an argument to paintComponent not an option?

– Stalemate Of Tuning
Dec 28 '18 at 18:14





Is passing it in as an argument to paintComponent not an option?

– Stalemate Of Tuning
Dec 28 '18 at 18:14




1




1





@StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

– Christopher Schultz
Dec 28 '18 at 18:16





@StalemateOfTuning That's a JPanel, so paintComponent is an overridden method of a superclass. So no, it can't be changed.

– Christopher Schultz
Dec 28 '18 at 18:16













@ChristopherSchultz Ah, makes sense then.

– Stalemate Of Tuning
Dec 28 '18 at 18:17





@ChristopherSchultz Ah, makes sense then.

– Stalemate Of Tuning
Dec 28 '18 at 18:17












2 Answers
2






active

oldest

votes


















1














You need to capture the information you get from runArguments. I think actually what you want is a constructor:



public class ProportionalBalons extends JPanel {
private String currencyCostumerHas;
private String currencyCostumerWants;
private double exchangeRate = args[2];

public ProportionalBalons(int currencyCustumerHas, String currencyCustumerWants, exchangeRate) {
this.currencyCostumerHas = currencyCostumerHas;
this.currencyCostumerWants = currencyCostumerWants;
this.exchangeRate = exchangeRate;
}

public void paintComponent(Graphics g) {
double balon1Diameter = costumerDeposit;
double balon2Diameter = costumerDeposit * exchangeRate;
//ballon 1
g.drawOval(10, 10, balon1Diameter, balon1Diameter);
//ballon 2
g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);
}
}


Here, when you create a new ProportionalBalons object, you will capture the values of your arguments and they will be available to all the methods defined in ProportionalBalons.



A few notes:




  1. I didn't see any use of the "currency" variables, but I put them in there because it looks like you probably do actually need them.

  2. There is no definition of the customerDeposit in your existing code; I assume it's somewhere. If you must, you can capture it in the constructor as well.

  3. The exchange rate certainly shouldn't be an int. If the USD is either 1x or 2x EUR, then I'll pick 1x, please (I get paid in USD). I've made this a double.






share|improve this answer
























  • Yeah that makes way more sense than my suggestion. Deleting my answer

    – Stalemate Of Tuning
    Dec 28 '18 at 18:27



















0














If your args variable is declared and initialized outside of your paintComponent() and runArguments() methods then you should be able to call it from within paintComponent.



double balon2Diameter=costumerDeposit*args[2];


If the variable is only local then it won't work.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962596%2fhow-do-i-call-a-variable-from-one-method-or-create-a-field-variable-from-it%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You need to capture the information you get from runArguments. I think actually what you want is a constructor:



    public class ProportionalBalons extends JPanel {
    private String currencyCostumerHas;
    private String currencyCostumerWants;
    private double exchangeRate = args[2];

    public ProportionalBalons(int currencyCustumerHas, String currencyCustumerWants, exchangeRate) {
    this.currencyCostumerHas = currencyCostumerHas;
    this.currencyCostumerWants = currencyCostumerWants;
    this.exchangeRate = exchangeRate;
    }

    public void paintComponent(Graphics g) {
    double balon1Diameter = costumerDeposit;
    double balon2Diameter = costumerDeposit * exchangeRate;
    //ballon 1
    g.drawOval(10, 10, balon1Diameter, balon1Diameter);
    //ballon 2
    g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);
    }
    }


    Here, when you create a new ProportionalBalons object, you will capture the values of your arguments and they will be available to all the methods defined in ProportionalBalons.



    A few notes:




    1. I didn't see any use of the "currency" variables, but I put them in there because it looks like you probably do actually need them.

    2. There is no definition of the customerDeposit in your existing code; I assume it's somewhere. If you must, you can capture it in the constructor as well.

    3. The exchange rate certainly shouldn't be an int. If the USD is either 1x or 2x EUR, then I'll pick 1x, please (I get paid in USD). I've made this a double.






    share|improve this answer
























    • Yeah that makes way more sense than my suggestion. Deleting my answer

      – Stalemate Of Tuning
      Dec 28 '18 at 18:27
















    1














    You need to capture the information you get from runArguments. I think actually what you want is a constructor:



    public class ProportionalBalons extends JPanel {
    private String currencyCostumerHas;
    private String currencyCostumerWants;
    private double exchangeRate = args[2];

    public ProportionalBalons(int currencyCustumerHas, String currencyCustumerWants, exchangeRate) {
    this.currencyCostumerHas = currencyCostumerHas;
    this.currencyCostumerWants = currencyCostumerWants;
    this.exchangeRate = exchangeRate;
    }

    public void paintComponent(Graphics g) {
    double balon1Diameter = costumerDeposit;
    double balon2Diameter = costumerDeposit * exchangeRate;
    //ballon 1
    g.drawOval(10, 10, balon1Diameter, balon1Diameter);
    //ballon 2
    g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);
    }
    }


    Here, when you create a new ProportionalBalons object, you will capture the values of your arguments and they will be available to all the methods defined in ProportionalBalons.



    A few notes:




    1. I didn't see any use of the "currency" variables, but I put them in there because it looks like you probably do actually need them.

    2. There is no definition of the customerDeposit in your existing code; I assume it's somewhere. If you must, you can capture it in the constructor as well.

    3. The exchange rate certainly shouldn't be an int. If the USD is either 1x or 2x EUR, then I'll pick 1x, please (I get paid in USD). I've made this a double.






    share|improve this answer
























    • Yeah that makes way more sense than my suggestion. Deleting my answer

      – Stalemate Of Tuning
      Dec 28 '18 at 18:27














    1












    1








    1







    You need to capture the information you get from runArguments. I think actually what you want is a constructor:



    public class ProportionalBalons extends JPanel {
    private String currencyCostumerHas;
    private String currencyCostumerWants;
    private double exchangeRate = args[2];

    public ProportionalBalons(int currencyCustumerHas, String currencyCustumerWants, exchangeRate) {
    this.currencyCostumerHas = currencyCostumerHas;
    this.currencyCostumerWants = currencyCostumerWants;
    this.exchangeRate = exchangeRate;
    }

    public void paintComponent(Graphics g) {
    double balon1Diameter = costumerDeposit;
    double balon2Diameter = costumerDeposit * exchangeRate;
    //ballon 1
    g.drawOval(10, 10, balon1Diameter, balon1Diameter);
    //ballon 2
    g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);
    }
    }


    Here, when you create a new ProportionalBalons object, you will capture the values of your arguments and they will be available to all the methods defined in ProportionalBalons.



    A few notes:




    1. I didn't see any use of the "currency" variables, but I put them in there because it looks like you probably do actually need them.

    2. There is no definition of the customerDeposit in your existing code; I assume it's somewhere. If you must, you can capture it in the constructor as well.

    3. The exchange rate certainly shouldn't be an int. If the USD is either 1x or 2x EUR, then I'll pick 1x, please (I get paid in USD). I've made this a double.






    share|improve this answer













    You need to capture the information you get from runArguments. I think actually what you want is a constructor:



    public class ProportionalBalons extends JPanel {
    private String currencyCostumerHas;
    private String currencyCostumerWants;
    private double exchangeRate = args[2];

    public ProportionalBalons(int currencyCustumerHas, String currencyCustumerWants, exchangeRate) {
    this.currencyCostumerHas = currencyCostumerHas;
    this.currencyCostumerWants = currencyCostumerWants;
    this.exchangeRate = exchangeRate;
    }

    public void paintComponent(Graphics g) {
    double balon1Diameter = costumerDeposit;
    double balon2Diameter = costumerDeposit * exchangeRate;
    //ballon 1
    g.drawOval(10, 10, balon1Diameter, balon1Diameter);
    //ballon 2
    g.drawOval(60 * 8, 10, balon2Diameter, balon2Diameter);
    }
    }


    Here, when you create a new ProportionalBalons object, you will capture the values of your arguments and they will be available to all the methods defined in ProportionalBalons.



    A few notes:




    1. I didn't see any use of the "currency" variables, but I put them in there because it looks like you probably do actually need them.

    2. There is no definition of the customerDeposit in your existing code; I assume it's somewhere. If you must, you can capture it in the constructor as well.

    3. The exchange rate certainly shouldn't be an int. If the USD is either 1x or 2x EUR, then I'll pick 1x, please (I get paid in USD). I've made this a double.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 28 '18 at 18:25









    Christopher SchultzChristopher Schultz

    14.2k23956




    14.2k23956













    • Yeah that makes way more sense than my suggestion. Deleting my answer

      – Stalemate Of Tuning
      Dec 28 '18 at 18:27



















    • Yeah that makes way more sense than my suggestion. Deleting my answer

      – Stalemate Of Tuning
      Dec 28 '18 at 18:27

















    Yeah that makes way more sense than my suggestion. Deleting my answer

    – Stalemate Of Tuning
    Dec 28 '18 at 18:27





    Yeah that makes way more sense than my suggestion. Deleting my answer

    – Stalemate Of Tuning
    Dec 28 '18 at 18:27













    0














    If your args variable is declared and initialized outside of your paintComponent() and runArguments() methods then you should be able to call it from within paintComponent.



    double balon2Diameter=costumerDeposit*args[2];


    If the variable is only local then it won't work.






    share|improve this answer




























      0














      If your args variable is declared and initialized outside of your paintComponent() and runArguments() methods then you should be able to call it from within paintComponent.



      double balon2Diameter=costumerDeposit*args[2];


      If the variable is only local then it won't work.






      share|improve this answer


























        0












        0








        0







        If your args variable is declared and initialized outside of your paintComponent() and runArguments() methods then you should be able to call it from within paintComponent.



        double balon2Diameter=costumerDeposit*args[2];


        If the variable is only local then it won't work.






        share|improve this answer













        If your args variable is declared and initialized outside of your paintComponent() and runArguments() methods then you should be able to call it from within paintComponent.



        double balon2Diameter=costumerDeposit*args[2];


        If the variable is only local then it won't work.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 28 '18 at 18:10









        Zach PedigoZach Pedigo

        695




        695






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962596%2fhow-do-i-call-a-variable-from-one-method-or-create-a-field-variable-from-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas