• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Word Drag Program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are to design and code a Java application and Applet which allows the user to move words about a container. There are a number of ways to implement this problem, and the following is a suggestion of a recommended way:

Create two classes: a class BoxWord, which represents the moveable word objects, and a Frame(Applet-based) driver class. I construct the word object with the following parameters: a reference to the parent, a String (the actual word), a color, a font, a width and a height. You may not need all those for a basic working program. The object must delegate a MouseMotionListener and mouseListener to pick up a mousePressed (word select), mouseReleased (word deselect), and mouseDragged (word moved) events. To move the words you can use the setLocation method, inherited from the Component class. You can use the Component method getLocation method to find out where the word is currently located. I use an extended Canvas to create my words, but a Label might work as well.

The motion is accomplished by setting the x-coordinate location of the word to the current word x-coord location, plus the x-coord of the mouseDragged event, minus the the x-coord of the original selection location (note that a selection of a word can occur anywhere in that object). The y-coord is done similarly.

The driver program has an array of String, as well as an array of BoxWord. As it loops through the array of String, it will construct the word objects and place them randomly in the driver container. The layout manager should be null, i.e. no layout manger. To have the objects apprear on the GUI you will use the setBounds method.
[ August 31, 2006: Message edited by: Bear Bibeault ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like a homework assignment, so do you have any specific questions you would like to ask? We are not going to do it for you.

Dave
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I removed the "urgent" from the title, please read this to understand why.

Also, please reserve this forum for truly advanced questions. I've moved this to the intermediate forum.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic