This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

APPLETS: How to replace a character within a string with fillPolygon using array's.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am required to enter a word/sentence into a text box and then print out what I have input, however when I have a special character (in my case 'H' or 'h') it will print out my fillPolygon shape.
I have used an array to try and replace the character H/h with the polygon using an If statement, however I keep on getting the error message: "[line: 49]
Error: method drawH in class Stringpoly cannot be applied to given types;
required: java.awt.Graphics,int,int
found: java.awt.Graphics,int[],int[]
reason: actual argument int[] cannot be converted to int by method invocation conversion



Thanks in advance. I have literally spent hours trying to work out the problem.

 
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making the display class implement a Listener interface is usually poor practice, and I think this is no exception. Create a class which implements the Listener.
As for the compiler error: if you read the message it is quite clear. You must pass an int, not an int[].
Why do you need to use fillPolygon? Why are you using that particular technique?
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Harman Bunder
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed the code now that my special character 'h' is now printed, however it appears in the top corners where I initially plotted it with the co-ordinates to create the shape.
For example, when I print "elephant", the H is missing but is instead in the top left hand corner, and when I type in 'Morning' a'h' won't appear.

Also in regards to the previous answer, I am using fillpolygon because I need it to be a block of the letter to replace the original special character.
Also, thanks!

Here is my current code:
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic