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 11 of 11

Thread: I am not getting the result I need

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I am not getting the result I need

    I am trying to create a frame by creating a class called CustApp. In the main method, I am trying to write code in the main method that will create a Customer object, assign to variable c. I am then to use setters to assign the following values in the Customer object ajectssociated with variable c:
    Kindness Foods, 1 Milkof St., Human, ME 03234, Joe Samaritan, 555-3333
    Finally, I am to create a CustFrame object and pass c, assign to cf.

    This is what I have:
    public class CustApp {
     
    	public CustApp(Customer c) {
    		// TODO Auto-generated constructor stub
    	}
     
    	public static void main(String[] args) {
    		Customer c = new Customer();
    		c.setCustName("Kindness Foods");
    		c.setShipToStreet("1 Miko St");
    		c.setShipToCity("Human");
    		c.setShipToState("ME");
    		c.setShipToZip("03234");
    		c.setContactPerson("Joe Samaritan");
    		c.setContactPhone("555-3333");
     
    		CustFrame cf = new CustFrame(c);
    }
    }

    I keep getting the same frame I got before with different labels saying something else from an earlier class. Can anyone see anything obvious, because I have fiddled with this forever....

    --- Update ---

    Oh, here is CustFrame by the way:

    import java.awt.Frame;
    import java.awt.Label;
     
    public class CustFrame extends Frame {
     
    	public CustFrame(Customer cust) {
     
    	//	this.setSize(300, 282);
    	//	this.setLayout(null);
    	//	this.setVisible(true);
     
    		Label custNameLbl = new Label();
    		this.setSize(300, 282);
    		this.setLayout(null);
    		custNameLbl.setBounds(62, 65, 176, 23);
    		custNameLbl.setText("test text");
    		this.add(custNameLbl);
    		this.setVisible(true);
     
    		Label shipToLbl1 = new Label();
    		this.setSize(300, 282);
    		this.setLayout(null);
    		shipToLbl1.setBounds(62, 120, 176, 23);
    		shipToLbl1.setText("test text");
    		this.add(shipToLbl1);
    		this.setVisible(true);
     
    		Label shipToLbl2 = new Label();
    		this.setSize(300, 282);
    		this.setLayout(null);
    		shipToLbl2.setBounds(62, 175, 176, 23);
    		shipToLbl2.setText("test text");
    		this.add(shipToLbl2);
    		this.setVisible(true);
     
    		Label contactInfo = new Label();
    		this.setSize(300, 282);
    		this.setLayout(null);
    		contactInfo.setBounds(62, 230, 176, 23);
    		contactInfo.setText("test text");
    		this.add(contactInfo);
    		this.setVisible(true);
     
    	//	custNameLbl.setText(cust.getCustName());
    	//	shipToLbl1.setText(cust.getShipToStreet());
    	//	shipToLbl2.setText(cust.getShipToCity());
    	//	contactInfo.setText(cust.getContactPerson());
    	}
     
    	public static void main(String[] args) {
    		Customer cust = new Customer();
    		CustFrame Customer = new CustFrame(cust);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: I am not getting the result I need

    labels saying something else from an earlier class.
    Sounds like a dirty work environment. Find the old versions of the class (both .java and .class files) and delete them.
    How are you managing the source code for the program?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    I guess I am confused as to why the setters in the recent class have no effect and are not returned? I continue to get the same results that I get from the CustFrame class. To me, it seems like the Kindness Foods, 1 Milkof, etc. should display, not "test text." But that is what I get, "test text." All of the code in the CustApp class does nothing apparently...

    Oh, and thanks for the tip Norm on the Java tags.

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    Why would this class "CustApp' be displaying the results of the earlier class, 'CustFrame' when I am creating a new instance of the CustFrame class? Shouldn't a new class be starting from a clean slate? The new instance is still inheriting the same text from the earlier version and i can't figure out why. I do not get the impression from the professor that I am supposed to delete the earlier class, because I have to turn them all in.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: I am not getting the result I need

    text from the earlier version
    Make sure you have deleted all copies of the old version
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    Nevermind guys...I think I stumbled upon the answer...thanks in advance for any future help, because I'll be back!

    --- Update ---

    Thanks Norm. I think I figured it out - and you are absolutely right.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    Quote Originally Posted by Norm View Post
    Make sure you have deleted all copies of the old version
    Okay, I have another one - but it is related. My problem starts with two existing classes: Item and ItemApp.

    Here is Item

    package c2;
     
    public class Item {
     
    	String itemNum, itemName, itemUPC, itemQty, itemUM;
     
     
    	public Item(String iNum, String iName, String iUPC, String iQty, String iUM) {
    		this.itemNum = iNum;
    		this.itemName = iName;
    		this.itemUPC = iUPC;
    		this.itemQty = iQty;
    		this.itemUM = iUM;
    	}
     
    	public void show() {
    		System.out.println(itemNum);
    		System.out.println(itemName);
    		System.out.println(itemUPC);
    		System.out.println(itemQty);
    		System.out.println(itemUM);
    	}
     
    public static void main(String []args)	{
     
    }
     
    }

    Here is ItemApp...

    package c2;
     
    public class ItemApp {
     
    	public static void main(String[] args) {
    		Item itemObj = new Item("44", "Crest Tartar Ctrl 17 oz", "5432", "1",
    				"Dozen");
    		itemObj.show();
     
    		/*
    		 * String itemNum = new String("99"); String itemName = new
    		 * String("Cheerios 32oz"); String itemUPC = new String("4321"); String
    		 * itemQty = new String("1"); String itemUM = new String("Gross");
    		 * System.out.println(itemNum); System.out.println(itemName);
    		 * System.out.println(itemUPC); System.out.println(itemQty);
    		 * System.out.println(itemUM);
    		 */
     
    	}
    }

    Here are my instructions:

    In this exercise, you will modify the Item application to display the Item information in a frame.
    Like the Employee application, you will create a new frame and have ItemApp pass an Item object with all the pertinent information.
    1. In the ECEx/src, create a new package called c3.
    2. Select the ItemApp and Item classes in ECEx.c2, then copy and paste them into c3. In c3/Item:
    3. Change the five String variables to private.
    4. Comment out the show method.
    5. Save the code and verify that there are no errors in Item.
    6. Using RAD, generate setters and getters for the five private variables.
    7. Change the Item constructor so that the five setters are used to set the values of the five private variables to the parameter values.
    8. Save the Item source and verify that there are no errors in the Item class.
    9. Create a new class in c3 called ItemFrame, identify its superclass java.awt.Frame, and do not have RAD generate any stubs.
    The executable code should consist of a package statement, and import statement, the class header and opening and closing class body braces.
    10. Define the ItemFrame constructor such that an Item object must be passed and assigned to a
    variable called item.
    11. Define the ItemFrame title as, the size as 400 by 400, and position the frame 100 pixels from the left and top of the screen.
    12. Define two labels and assign them to class variables called amountLbl and iDLbl.
    13. Define the two labels' sizes and locations such that they will look like figure 3.1 when displayed.
    14. Change the ItemFrame constructor such that the data is retrieved from the Item object and formatted to appear as in figure 3.1.
    15. Change ItemApp so it does not invoke the show method but instead creates an instance of ItemFrame and passes the Item variable itemObj to ItemFrame's constructor.
    Results of the Exercise
    1. One new package called c3 in ECEx project.
    Introduction to Java Using WebSphere - Challenge Exercises 7
    Chapter 3 - GUI
    2. One new class file called ItemFrame in c3 created as outlined above.
    3. Item and ItemApp modified as outlined above.

    Check that the Exercise Was Done Correctly
    1. Using RAD, verify that the new project c3 and class ItemFrame were created in the ECEx
    project.
    2. Run ItemApp.
    3. The frame should be positioned and the contents displayed as in figure 3.1.

    Untitled-1.jpg
    Figure 3.1


    This is the code I have so far in ItemFrame:

    package c3;
     
    import java.awt.Frame;
    import java.awt.Label;
     
    public class ItemFrame extends Frame {
     
    public ItemFrame(ItemApp itemObj){
    //	ItemFrame object = new ItemFrame(item);
     
    	this.setSize(400,400);
    	this.setLayout(null);
    	this.setVisible(true);
     
     
    	Label amountLbl = new Label();
    	this.setSize(400,400);
    	this.setLayout(null);
    	amountLbl.setBounds(100,100,100,100);
    	amountLbl.setText(Item.getItem());
    	this.add(amountLbl);
    	this.setVisible(true);
     
    	Label iDLbl = new Label();
    	this.setSize(400,400);
    	this.setLayout(null);
    	iDLbl.setBounds(100,100,100,100);
    	iDLbl.setText("were received with a UPC of 5432");
    	this.add(iDLbl);
    	this.setVisible(true);
     
    }
     
    public static void main(String[] args) {
     
    	ItemApp item = new ItemApp();
    	ItemFrame Item = new ItemFrame(item);
    }
    }

    I am doing something wrong with the call function, as I try to call Item. Any clues?
    Attached Images Attached Images

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: I am not getting the result I need

    I am doing something wrong with the call function,
    Please explain why you think there is something wrong? Copy the full text of any error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    amountLbl.setText(Item.getItemName());

    With this line of code, I receive an error message that says: Cannot make a static reference to the non-static method getItemName() from the type Item. It wants me to change the modifier of getItemName() to static in the Item class. I am pretty sure this can't be right.

    Note: In the code that I pasted for ItemFrame, I used getItem(), which is undefined. It should likely be getItemName() instead.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: I am not getting the result I need

    If the getItemName() method is not static, you need reference to an instance of the class to call the method.

    I don't see where that method is defined in any of the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am not getting the result I need

    Ok, I'll take a look at that. Thanks!

Similar Threads

  1. Isn't the result supposed to be 6?
    By obel1x in forum Java Theory & Questions
    Replies: 3
    Last Post: April 12th, 2014, 03:43 AM
  2. hi if u can help me please to figure this how D become result of 1
    By ohad in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2013, 07:35 AM
  3. [SOLVED] Got different result from (Eclipse VS NetBean)
    By SmokyBrain in forum Java IDEs
    Replies: 4
    Last Post: May 4th, 2012, 07:08 AM
  4. Implementing Sha256 and not getting the result I should get
    By ydan87 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 26th, 2011, 03:30 PM