Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Fubarable

Thread: JButton into an Array

  1. #1
    Ecksso is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default JButton into an Array

    So i'm hoping this isn't to aggravating of a question, i can honestly say i'm not great at Java but i'm trying to learn.

    Basically i need to make an Array of objects, and i need to enter objects into this array via a JButton.

    I have this as a Class

    class Application extends CardDeck {

    public Application (String Name, int average, String first, String second, String third){
    t1 = Name;
    t2 = Average;
    dataList.setSelectedIndex(0) = first;
    dataList.setSelectedIndex(1) = second;
    dataList.setSelectedIndex(2) = third;

    Which im not sure is correct and i have

    Application Apps[] = new Application[99];
    for (int i = 0; i < Apps.length; i++);
    if (event.getSource() == b1)
    Apps[i] = new Application();
    String[] data = {};

    to create the objects and put them into the array, im not sure what is missing or if everything is in the right order any help at all would be MASSIVELY appreciated.

    Every time i try to compile i get this error

    "Error: constructor Application in class Application cannot be applied to given types;
    required: java.lang.String,int,java.lang.String,java.lang.St ring,java.lang.String
    found: no arguments
    reason: actual and formal argument lists differ in length"

    I have tried everything i know and looked through about 6 Java website as well as 2 textbooks and i honestly cant figure out how to do this properly.

    I dont know it will help but here is a picture of the Applet

    imgur: the simple image sharer

    Each object needs to contain name, average and 3 universities that are chosen in the JList.

    Thank you for taking the time to read my post!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: JButton into an Array

    Java Code:
    constructor Application in class Application cannot be applied to given types;
     required: java.lang.String,int,java.lang.String,java.lang.St ring,java.lang.String
     found: no arguments
    I should think that's pretty self-explanatory. You're trying to use a constructor "new Application()" but the only constructor in the Application class requires 4 String parameters.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton into an Array

    Your error message is telling you what's wrong, and so in the future you'll want to try to understand it as best you can since it is often quite helpful. Your Application constructor is written to accept several parameters and you're trying to call it with none. So you'll need to figure out the best way to fix this.

    Edit: Hey Darryl! And goodnight!
    DarrylBurke likes this.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: JButton into an Array

    Ah, it's time for the day shift on the other side of the globe!

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Ecksso is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: JButton into an Array

    Quote Originally Posted by DarrylBurke View Post
    I should think that's pretty self-explanatory. You're trying to use a constructor "new Application()" but the only constructor in the Application class requires 4 String parameters.

    db
    Then how exactly do i set it up to have 4 string parameters i kidna got that much but i dont know what to change.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton into an Array

    Quote Originally Posted by Ecksso View Post
    Then how exactly do i set it up to have 4 string parameters i kidna got that much but i dont know what to change.
    I don't think we can help you with this as it will all depend on what you're class does, what the code is trying to do,... all things that you know but haven't told us.

  7. #7
    Ecksso is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: JButton into an Array

    Quote Originally Posted by Fubarable View Post
    I don't think we can help you with this as it will all depend on what you're class does, what the code is trying to do,... all things that you know but haven't told us.
    The class needs to take info from a GUI submit button, then create an object "Application" and store it in an array. Does that help?

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton into an Array

    Quote Originally Posted by Ecksso View Post
    The class needs to take info from a GUI submit button, then create an object "Application" and store it in an array. Does that help?
    So perhaps in the button's action listener, you will want to extract the information from the gui's fields and use them to make the parameters that will be used in your Application's constructor call.

  9. #9
    Ecksso is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: JButton into an Array

    Quote Originally Posted by Fubarable View Post
    So perhaps in the button's action listener, you will want to extract the information from the gui's fields and use them to make the parameters that will be used in your Application's constructor call.
    How do i do that?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton into an Array

    Again, we cannot help given the limited information that you've posted so far. Please when post your questions, assume that we don't have your requirement instructions nor your current code sitting in front of us, and assume that we don't have crystal balls and can't read minds.

Similar Threads

  1. ActionListener for JButton after changing Button to JButton
    By ravi.joshi53 in forum Java Applets
    Replies: 2
    Last Post: 10-07-2011, 07:35 AM
  2. Error in writing JButton Array of objects into File
    By justbeller in forum AWT / Swing
    Replies: 3
    Last Post: 06-08-2011, 11:06 PM
  3. jbutton
    By Patea2000 in forum NetBeans
    Replies: 1
    Last Post: 03-16-2011, 08:56 AM
  4. Replies: 2
    Last Post: 04-21-2010, 06:34 PM
  5. JButton help :)
    By yasmin k in forum AWT / Swing
    Replies: 7
    Last Post: 11-12-2009, 09:53 PM

Posting Permissions

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