Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Cannot Convert from Void to JTextField

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Location
    Norfolk, England
    Posts
    7
    My Mood
    Cheerful
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Cannot Convert from Void to JTextField

    Hey everyone, this is my first post to ask a question that I hope won't be too difficult to solve.

    I am trying to make a small app that keeps score in a darts game including games, sets, current score etc...

    I want to display the score after each player has thrown their three darts, however, after entering in three scores and clicking the button to take the total of these scores away from the initial 501, the score which I had displayed in a JLabel did not update.

    I have tried to change it to a JTExtField in the hope that outputting it this way will allow the value to change.

    I wanted to make sure that the value of each players score could not be edited and came across the method "setEditable()" and I tried to implement it, however, when adding this line in including the false for the boolean, I get the following error message: "Type Mismatch; Cannot convert from Void to JTextField".

    This is what the section of my code looks like:

    scoreBox1 = new JTextField(3).setEditable(false);
    panel1.add(scoreBox1);
    scoreBox1.setText(Player1Score);

    I would be very grateful for some help, many thanks in advance, Rob.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Cannot Convert from Void to JTextField

    setEditable() method is void, you're trying to assign your JTextField to a method which returns nothing.
    Change: scoreBox1 = new JTextField(3).setEditable(false);
    To: scoreBox1 = new JTextField(3);
    scoreBox1.setEditable(false);
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    StandbyExplosion (August 24th, 2011)

  4. #3
    Junior Member
    Join Date
    Aug 2011
    Location
    Norfolk, England
    Posts
    7
    My Mood
    Cheerful
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Cannot Convert from Void to JTextField

    Thank you very much!

Similar Threads

  1. Void Class in Java
    By srinu.gandikota in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 2nd, 2011, 04:22 AM
  2. +calculateCharge():Void
    By theoneyouenvy in forum Object Oriented Programming
    Replies: 7
    Last Post: April 20th, 2011, 09:56 PM
  3. javascript:void(0
    By serenafare1 in forum Member Introductions
    Replies: 1
    Last Post: April 12th, 2011, 09:44 PM
  4. How to combine these 3 void methods?..
    By TimoElPrimo in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 8th, 2011, 02:25 PM
  5. Calling a void method into a static void main within same class
    By sketch_flygirl in forum Object Oriented Programming
    Replies: 3
    Last Post: November 15th, 2009, 05:24 PM

Tags for this Thread