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

Thread: MyLogoLab

  1. #1
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default MyLogoLab

    I have to create my own logo, but I'll show you the rubric first.

    50 Points


    The logo will be created in a separate class file called MyLogo. The first step is to create a file with the class definition, class variables, and default constructor.

    Define three variables, two of type integer to hold the x and y positions for the logo and a Graphics variable that holds where the logo will be drawn on.

    Required Constructors:

    Default constructor will initialize the Graphics variable to null and it will set the x and y values to 0.

    Secondary constructor that will take three inputs for the three class variables.

    Another secondary constructor that only takes as input a Graphics variable. The x and y variables should be set to 0.


    60 Points


    Create a method named toString(). This should take no inputs and should return a String that describes the logo including the x and y coordinates. Format and label it so it the output is understandable.


    70 Points


    Create a drawMyLogo() method that will take no inputs. This method will draw your logo using the Graphics variable defined for the class. You can draw any kind of logo you want but maximum size is 100 x 100 pixels and MUST use the x and y position variables defined for the class.


    80 Points

    Now create a static method that does not return anything. A static method does not use any class variables!

    Name the method drawFriscoCorpLogo and have it draw a smiley face (or other simple picture of your choice) in the top left corner of the window. The method will take input in the form of a Graphics variable.


    90 Points

    Write a setXY mutator method that takes two integer inputs and modifies the x and y coordinates for the class.


    100 Points

    Up to you, some ideas:
    Use the setXY method and a loop to draw multiple logos spaced at regular intervals across the window – make sure not to draw beyond the window edge
    Implement a loop that redraws the screen with a logo in a different place so that it moves across the screen (ie animate the logo so it moves)






    Here's my code with errors, I just need help fixing it.

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.awt.Color.*;
    
    public class MyLogoLab extends JPanel {
       private int xLogo;
       private int yLogo;
       private String g;
    
    }
      public class MyLogoOne(String input) {
      	 String g = null;
      	 int xLogo = 0;
      	 int yLogo = 0;
    
         System.out.println(" + g + ");
         System.out.println(" + xLogo + ");
         System.out.println(" + yLogo + ");
    
      }
    
       public class toString() {
       	return xLogo();
       	return yLogo();
    
       }
    
    //  public void paintComponent(Graphics g) {
    
     //     super.paintComponent(g);
     //    this.setBackground(Color.GREEN);
     //    g.setColor(Color.red);
     //    g.fillRectangle(0, 0, 100, 100);
    
    //  }


    Tell what's wrong, and how can I fix it.
    Last edited by Eranga; 02-29-2012 at 05:08 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: MyLogoLab

    Can you post the complete error you end up with here to have a look?

    And also please use the code tags next time when you are posting code segments here in the forum. Unformated codes are really hard to read.

  3. #3
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: MyLogoLab

    Sorry, well if u have JCreator or Eclipse. U could copy and paste this code, but name ur file the same as this. It'll tell u the errors.

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

    Default Re: MyLogoLab

    Quote Originally Posted by fire View Post
    Sorry, well if u have JCreator or Eclipse. U could copy and paste this code, but name ur file the same as this. It'll tell u the errors.
    Please post all requested information in your thread.

    Please understand that we are all volunteers helping on our free time. Since you are asking for free advice, is it asking too much for you to put in a little effort to make it easier for us to help you? I would hope not.
    Eranga likes this.

  5. #5
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: MyLogoLab

    Sorry for my statement. I'll post it later since I'm busy right now. But it should be on there about 2 hours. Again sorry for my misunderstanding.

  6. #6
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: MyLogoLab

    Okay here's the errors. 44 errors, lots of errors.

    --------------------Configuration: <Default>--------------------
    F:\Trac\MyLogo.java:18: error: '{' expected
    public class MyLogoOne(String input) {
    ^
    F:\Trac\MyLogo.java:24: error: <identifier> expected
    System.out.println(" + xLogo + "); //takes input for the x variable of logo
    ^
    F:\Trac\MyLogo.java:24: error: illegal start of type
    System.out.println(" + xLogo + "); //takes input for the x variable of logo
    ^
    F:\Trac\MyLogo.java:25: error: <identifier> expected
    System.out.println(" + yLogo + "); //takes input for y variable of logo
    ^
    F:\Trac\MyLogo.java:25: error: illegal start of type
    System.out.println(" + yLogo + "); //takes input for y variable of logo
    ^
    F:\Trac\MyLogo.java:27: error: <identifier> expected
    System.out.println(" + g + "); //gets the input for graphic variable
    ^
    F:\Trac\MyLogo.java:27: error: illegal start of type
    System.out.println(" + g + "); //gets the input for graphic variable
    ^
    F:\Trac\MyLogo.java:33: error: '{' expected
    public class toString() { //the method only returns the logo variables, but doesn't take input
    ^
    F:\Trac\MyLogo.java:34: error: illegal start of type
    return xLogo(); //the x variable of logo is returned
    ^
    F:\Trac\MyLogo.java:34: error: ';' expected
    return xLogo(); //the x variable of logo is returned
    ^
    F:\Trac\MyLogo.java:34: error: illegal start of type
    return xLogo(); //the x variable of logo is returned
    ^
    F:\Trac\MyLogo.java:34: error: <identifier> expected
    return xLogo(); //the x variable of logo is returned
    ^
    F:\Trac\MyLogo.java:35: error: illegal start of type
    return yLogo(); //the y variable of logo is returned
    ^
    F:\Trac\MyLogo.java:35: error: ';' expected
    return yLogo(); //the y variable of logo is returned
    ^
    F:\Trac\MyLogo.java:35: error: illegal start of type

    return yLogo(); //the y variable of logo is returned
    ^
    F:\Trac\MyLogo.java:35: error: <identifier> expected
    return yLogo(); //the y variable of logo is returned
    ^
    F:\Trac\MyLogo.java:40: error: '{' expected
    public class drawMyLogo() { //the method holds the background color of the picture and how big the frame should be
    ^
    F:\Trac\MyLogo.java:42: error: illegal start of type
    super.paintComponent(g);
    ^
    F:\Trac\MyLogo.java:42: error: ';' expected
    super.paintComponent(g);
    ^
    F:\Trac\MyLogo.java:42: error: invalid method declaration; return type required
    super.paintComponent(g);
    ^
    F:\Trac\MyLogo.java:42: error: <identifier> expected
    super.paintComponent(g);
    ^
    F:\Trac\MyLogo.java:43: error: illegal start of type
    this.setBackground(Color.GREEN);
    ^
    F:\Trac\MyLogo.java:43: error: ';' expected
    this.setBackground(Color.GREEN);
    ^
    F:\Trac\MyLogo.java:43: error: invalid method declaration; return type required
    this.setBackground(Color.GREEN);
    ^
    F:\Trac\MyLogo.java:43: error: <identifier> expected
    this.setBackground(Color.GREEN);
    ^
    F:\Trac\MyLogo.java:44: error: <identifier> expected
    g.setColor(Color.red);
    ^
    F:\Trac\MyLogo.java:44: error: <identifier> expected
    g.setColor(Color.red);
    ^
    F:\Trac\MyLogo.java:45: error: <identifier> expected
    g.fillRectangle(xLogo, yLogo, 100, 100);
    ^
    F:\Trac\MyLogo.java:45: error: <identifier> expected
    g.fillRectangle(xLogo, yLogo, 100, 100);
    ^
    F:\Trac\MyLogo.java:45: error: <identifier> expected
    g.fillRectangle(xLogo, yLogo, 100, 100);
    ^
    F:\Trac\MyLogo.java:45: error: illegal start of type
    g.fillRectangle(xLogo, yLogo, 100, 100);
    ^
    F:\Trac\MyLogo.java:45: error: illegal start of type
    g.fillRectangle(xLogo, yLogo, 100, 100);
    ^
    F:\Trac\MyLogo.java:49: error: class, interface, or enum expected
    public void static main(String[] args) { //this method draws the logo which is oval shaped
    ^
    F:\Trac\MyLogo.java:51: error: '{' expected
    public class drawFriscoCorpLogo() {
    ^
    F:\Trac\MyLogo.java:53: error: <identifier> expected
    g.drawOval(xLogo, yLogo, width, height);
    ^
    F:\Trac\MyLogo.java:53: error: <identifier> expected
    g.drawOval(xLogo, yLogo, width, height);
    ^
    F:\Trac\MyLogo.java:53: error: <identifier> expected
    g.drawOval(xLogo, yLogo, width, height);
    ^
    F:\Trac\MyLogo.java:53: error: <identifier> expected
    g.drawOval(xLogo, yLogo, width, height);
    ^
    F:\Trac\MyLogo.java:53: error: <identifier> expected
    g.drawOval(xLogo, yLogo, width, height);
    ^
    F:\Trac\MyLogo.java:56: error: class, interface, or enum expected
    public void setXY() { //this method takes the logo variables and modifies them
    ^
    F:\Trac\MyLogo.java:59: error: class, interface, or enum expected
    System.out.println(" + xLogo + ");
    ^
    F:\Trac\MyLogo.java:60: error: class, interface, or enum expected
    this.yLogo = yLogo;
    ^
    F:\Trac\MyLogo.java:61: error: class, interface, or enum expected
    System.out.println(" + yLogo + ");
    ^
    F:\Trac\MyLogo.java:63: error: class, interface, or enum expected
    }
    ^
    44 errors

    Process completed.

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

    Default Re: MyLogoLab

    Only one public class per file, and you've got three. Each public class there should be in its own file.

  8. #8
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: MyLogoLab

    How can it be done?

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

    Default Re: MyLogoLab

    Quote Originally Posted by fire View Post
    How can it be done?
    How can what be done? Again but each public class in its own file with the file name exactly matching the class name. I don't know how to explain it any better than that.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: MyLogoLab

    Quote Originally Posted by Fubarable View Post
    How can what be done? Again but each public class in its own file with the file name exactly matching the class name. I don't know how to explain it any better than that.
    And I wonder that the OP really has a better understanding about the basis in Java.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: MyLogoLab

    I suspect the first closing bracket should be at the end of the file.
    Then, this is no a method signature:
    Java Code:
    public class MyLogoOne(String input)
    or a valid constructor signature.
    I suggest reading up on both in your notes.

    Moving that bracket and correcting both your methods/constructors should get you closer to having a compileable program.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Tags for this Thread

Posting Permissions

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