Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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

Name Game GUI

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting back into Java after a long break, like 5 years and I'm trying to write a java gui program that will take a person name and turn it into the name game lyrics with buttons to generate the lyrics and clear the name. I have most of it done just need to know how I can finish the rest or where I can go to get ideas on what to do.

 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code in code tags.

What do you mean, "how I can finish the rest?" What needs to be done? What help do you need? What problems are you having? Ask specific questions. If you have errors, post them.
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are code tags? Is that an explanation of what each section of the code does?

What need to be done is when the user enter a name or their name, my program should take the name and create a output display like this

Shirley!
Shirley, Shirley bo Birley Bonana fanna fo Firley
Fee fy mo Mirley, Shirley!.

I need to know how to make my generate lyric button perform the task above. I have the needed code commented out but don't know how to link the two.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Raziel Shabazz wrote:What are code tags? Is that an explanation of what each section of the code does?


No, those are special tags that you can use in your post so that the forum software nicely formats it. See: UseCodeTags
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks! Hopefully this will make it more readable.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh, you're wondering how to "link the two."

You have an action listener for your button that calls on something called testField which isn't defined. Do you see that error? What is testField?

I'll assume you mean it to be an entry field for the name to start the name game, maybe a JTextField. If so, please define it and add that to your GUI.

Then when you have the JTextField defined and displayed, there will be an appropriate way to recover the user's entry (see the JTextField API) which will then be assigned to a variable and used to generate the lyric by substituting it into the output.

Think on and work that a bit and come back when you need more help.
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the change now my program is not giving me the GUI I was at least getting. Getting the error "No Main class found"

 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't despair. You probably haven't gone backwards, just wandered down a trail that needs connecting to where you were. Post your updated program.
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably so maybe I need Java for dummies book

 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the Dummies book isn't necessary. We'll get you through the minor problems you're seeing.

You're posting code with significant errors without mentioning them. That's okay, we're here to help you with those, but you don't seem to recognize that the errors exist or aren't being forthright about the problems you're seeing at your end.

Do you see the errors? What is the compiler telling you?
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are the errors I'm getting in the window below

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: javax.swing.JButton.usertext
at thegame.TheGame$buttonButtonHandler.actionPerformed(TheGame.java:48)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
BUILD SUCCESSFUL (total time: 5 seconds)
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so it's not that the GUI you previously saw doesn't show but that your'e getting the errors you've posted. It's important we know that.

If you look at the class buttonButtonHandler, you should see that you've written a method, displayLyrics() inside the actionPerformed() method. Respecting Java naming conventions, the class name should begin with a capital letter, but more importantly, a method should not be (cannot be) defined inside another method. Perhaps you're missing some close braces, but that's not clear to me. Please inspect your code and figure out why there's a method inside another and fix it.
 
Raziel Shabazz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to display the output as part of the GUI, I need to create an appropriate GUI component to hold the lyrics and use its setText() method for display. I hope that is better clarity, I been trying to read as many Java books as I can on the weekend but still is lost on how to implement it.
 
I am going down to the lab. Do NOT let anyone in. Not even 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