Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,408 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,474 people online right now. Registration is fast and FREE... Join Now!




project graphical letters spell hello

2 Pages V  1 2 >  
Reply to this topicStart new topic

project graphical letters spell hello, Double post... topic merged

jmuckey2
14 Oct, 2008 - 02:31 PM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
the following is the hellocomponent then viewer then the files for the letters helo the compoent file has 10 errors and i don't know what to do

CODE

import javax.swing.JOptionPane;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
   Draws "HELLO".
*/
public class HelloComponent extends JComponent
{
   public void paintComponent(Graphics g)
   {
      Graphics2D g2 = (Graphics2D) g;

      final int WIDTH = 30;
      final int SPACING = 5;

      double x = 0;
      double y = 0;

      LetterH h = new LetterH(x, y);
      h.draw(g2);

      x = x + WIDTH + SPACING;
      LetterE e = new LetterE(x, y);
      e.draw(g2);

      x = x + WIDTH + SPACING;
      LetterL l1 = new LetterL(x, y);
      l1.draw(g2);

      x = x + WIDTH + SPACING;
      LetterL l2 = new LetterL(x, y);
      l2.draw(g2);

      x = x + WIDTH + SPACING;
      LetterO o = new LetterO(x, y);
      o.draw(g2);
   }
}

import javax.swing.JFrame;

public class HelloViewer
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      final int FRAME_WIDTH = 200;
      final int FRAME_HEIGHT = 100;

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setTitle("ExP5_11");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      HelloComponent component = new HelloComponent();
      frame.add(component);

      frame.setVisible(true);
   }
}


public class LetterH
{
   /**
      Constructs a large letter H
   */
   public LetterH()
   {
   }

   /**
      Gets the large letter H
      @return large letter H
   */
   public String getLetter()
   {
      return "*   *\n*   *\n*****\n*   *\n*   *\n";
   }
}
public class LetterE
{
   /**
      Constructs a large letter E
   */
   public LetterE()
   {
   }

   /**
      Gets the large letter E
      @return large letter E
   */
   public String getLetter()
   {
      return "*****\n*\n*****\n*\n*****\n";
   }
}

public class LetterL
{
   /**
      Constructs a large letter L
   */
   public LetterL()
   {
   }

   /**
      Gets the large letter L
      @return large letter L
   */
   public String getLetter()
   {
      return "*\n*\n*\n*\n*****\n";
   }
}

public class LetterO
{
   /**
      Constructs a large letter O
   */
   public LetterO()
   {
   }

   /**
      Gets the large letter O
      @return large letter O
   */
   public String getLetter()
   {
      return " ***\n*   *\n*   *\n*   *\n ***\n";
   }
}


Mod edit - Please code.gif
~BetaWar
User is offlineProfile CardPM
+Quote Post

pbl
RE: Project Graphical Letters Spell Hello
14 Oct, 2008 - 02:43 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
your import javax.swing... is in the middle of the file... all imports must be at the top of the file

your "letter" constructors do not have the parameter x & y
so
Letter l2 = new LetterL();

or have the constructor

LetterL(int x, int y)

classes inside a .java belonging to another class cannot be public, they have to be private ... if you want them public put them in their own .java file
User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
14 Oct, 2008 - 03:25 PM
Post #3

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:22: cannot find symbol
symbol : method draw(java.awt.Graphics2D)
location: class LetterH
h.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:26: cannot find symbol
symbol : method draw(java.awt.Graphics2D)
location: class LetterE
e.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:29: cannot find symbol
symbol : class Letter
location: class HelloComponent
LetterL l1 = new Letter();
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:30: cannot find symbol
symbol : method draw(java.awt.Graphics2D)
location: class LetterL
l1.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:34: cannot find symbol
symbol : method draw(java.awt.Graphics2D)
location: class LetterL
l2.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:37: cannot find symbol
symbol : constructor LetterO(double,double)
location: class LetterO
LetterO o = new LetterO(x, y);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:38: cannot find symbol
symbol : method draw(java.awt.Graphics2D)
location: class LetterO
o.draw(g2);
^
7 errors

User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
14 Oct, 2008 - 03:34 PM
Post #4

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
When I compile the files seperatly, i dont have a problem. So why is it that when i compile as nessicary, i get all these errors???
User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
14 Oct, 2008 - 05:14 PM
Post #5

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
Here is the Viewer....

import javax.swing.JFrame;

public class HelloViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();

final int FRAME_WIDTH = 200;
final int FRAME_HEIGHT = 100;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("ExP5_11");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

HelloComponent component = new HelloComponent();
frame.add(component);

frame.setVisible(true);
}
}


It says I have many errors.. Why, I dont know..

Here is the COmponent...WIth more errors...

import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
Draws "HELLO".
*/
public class HelloComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;

final int WIDTH = 30;
final int SPACING = 5;

double x = 0;
double y = 0;

LetterH h = new LetterH();
H.draw(g2);

x = x + WIDTH + SPACING;
LetterE e = new LetterE();
E.draw(g2);

x = x + WIDTH + SPACING;
LetterL l1 = new Letter();
L1.draw(g2);

x = x + WIDTH + SPACING;
LetterL l2 = new LetterL();
L2.draw(g2);

x = x + WIDTH + SPACING;
LetterO o = new LetterO(x, y);
O.draw(g2);
}
}



Now here are the Letter Classes....Wich all Compile fine...
public class LetterH
{
/**
Constructs a large letter H
*/
public LetterH()
{
}

/**
Gets the large letter H
@return large letter H
*/
public String getLetter()
{
return "* *\n* *\n*****\n* *\n* *\n";
}
}




public class LetterE
{
/**
Constructs a large letter E
*/
public LetterE()
{
}

/**
Gets the large letter E
@return large letter E
*/
public String getLetter()
{
return "*****\n*\n*****\n*\n*****\n";
}
}





public class LetterL
{
/**
Constructs a large letter L
*/
public LetterL()
{
}

/**
Gets the large letter L
@return large letter L
*/
public String getLetter()
{
return "*\n*\n*\n*\n*****\n";
}
}



public class LetterO
{
/**
Constructs a large letter O
*/
public LetterO()
{
}

/**
Gets the large letter O
@return large letter O
*/
public String getLetter()
{
return " ***\n* *\n* *\n* *\n ***\n";
}
}




The Letter Classes as I said are fine. PLease help me figure this out.

User is offlineProfile CardPM
+Quote Post

pbl
RE: Project Graphical Letters Spell Hello
14 Oct, 2008 - 08:27 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(jmuckey2 @ 14 Oct, 2008 - 04:34 PM) *

When I compile the files seperatly, i dont have a problem. So why is it that when i compile as nessicary, i get all these errors???

Did you made the corrections I told you do do ?

I guess you will have to repost your code.

Separate between different [ code] [ /code] tags the content of every file.
User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 04:02 PM
Post #7

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
[ code] [ /code] i must br pretty dumb because i dont know what you mean by that
User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 05:22 PM
Post #8

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
QUOTE(jmuckey2 @ 15 Oct, 2008 - 05:02 PM) *

[ code] [ /code] i must br pretty dumb because i dont know what you mean by that


import javax.swing.JOptionPane;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
Draws "HELLO".
*/
public class HelloComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;

LetterH h = new LetterH();
LetterE e = new LetterE();
LetterL l1 = new LetterL();
LetterL l2 = new LetterL();
LetterO o = new LetterO();


LetterH.draw(g2);
LetterE.draw(g2);
LetterL1.draw(g2);
LetterL2.draw(g2);
LetterO.draw(g2);




C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:22: cannot find symbol
symbol : variable Letterh
location: class HelloComponent
Letterh.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:23: cannot find symbol
symbol : variable Lettere
location: class HelloComponent
Lettere.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:24: cannot find symbol
symbol : variable Letterl1
location: class HelloComponent
Letterl1.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:25: cannot find symbol
symbol : variable Letterl2
location: class HelloComponent
Letterl2.draw(g2);
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\HelloComponent.java:26: cannot find symbol
symbol : variable Lettero
location: class HelloComponent
Lettero.draw(g2);
^
5 errors

Tool completed with exit code 1
User is offlineProfile CardPM
+Quote Post

pbl
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 05:35 PM
Post #9

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
None of you LetterX classes implements the method draw(Graphic g)

LetterH.draw(g2);
LetterE.draw(g2);
LetterL1.draw(g2);
LetterL2.draw(g2);
LetterO.draw(g2);


And difficult to be clearer than that

code.gif



[ code]
class LetterH...
.....
[ /code]

would produce

CODE

class LetterH...
.....

User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 06:16 PM
Post #10

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
are you refeering to the individual letter classes such as h e l l o

because to be honest i m not that skilled at this kinda stuff yet still learning and i have noi idea what would go into the individual classes


User is offlineProfile CardPM
+Quote Post

pbl
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 06:35 PM
Post #11

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(jmuckey2 @ 15 Oct, 2008 - 07:16 PM) *

are you refeering to the individual letter classes such as h e l l o

because to be honest i m not that skilled at this kinda stuff yet still learning and i have noi idea what would go into the individual classes


you are calling the draw() method of your LetterXXX class
These classes do not have a drw() method. The only method they have is a getLetter() method that returns a String
User is offlineProfile CardPM
+Quote Post

jmuckey2
RE: Project Graphical Letters Spell Hello
15 Oct, 2008 - 06:47 PM
Post #12

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 35


My Contributions
import java.awt.Graphics;
import java.awt.Graphics2D;





public class LetterH
{
public void draw(Graphics2D g2);
{
/**
Constructs a large letter H
*/

public Letter();

{
}

/**
Gets the large letter H
@return large letter H
*/
public String getLetter();
{
return "* *\n* *\n*****\n* *\n* *\n";
}
}
}






C:\Documents and Settings\default\Desktop\Josh's Java Stuff\LetterH.java:16: illegal start of expression
public Letter();
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\LetterH.java:25: illegal start of expression
public String getLetter();
^
C:\Documents and Settings\default\Desktop\Josh's Java Stuff\LetterH.java:25: ';' expected
public String getLetter();
^
3 errors

Tool completed with exit code





User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:17PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month