Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Swing and AWT  RSS feed

 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain to me how I can break this down to a driver and a JFrame Class?



Thank you!
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what is meant exactly by a "driver", but it probably means that you should put the main() method (lines 15-18) in a separate class; not inside your MenuDemo class.
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Thanks!

One more question, for the following:



I am trying to assign them with listener objects.

Say for example.



I keep getting an error though, I want it to have a named listener class and named listener object.
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Do wrote:I keep getting an error (...)

What error?
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies for my ambiguity!

cannot find symbol
symbol: method AddActionListener(javax.swing.JMenuItem)
location: variable colorMenu of type javax.swing.JMenu
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Do wrote:Apologies for my ambiguity!

cannot find symbol
symbol: method AddActionListener(javax.swing.JMenuItem)
location: variable colorMenu of type javax.swing.JMenu

The error message is very clear. JMenuItem class does not have AddActionListener method. Did you mean addActionListener?
Remember, Java is case sensitive.
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh sorry.....that shouldnt come up as the error.....it should be something along this line:

method addActionListener in class javax.swing.AbstractButton cannot be applied to given types;
required: java.awt.event.ActionListener
found: javax.swing.JMenuItem
reason: actual argument javax.swing.JMenuItem cannot be converted to java.awt.event.ActionListener by method invocation conversion
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right: A JMenuItem is not an ActionListener - which is what that method needs as a parameter.

I am trying to assign them with listener objects.

What are you trying to accomplish with that? It seems you had working code, and then you changed something to make it not work (making it non-compilable, actually).
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Do wrote:Anyone?
Please read this.
I am moving this discussion to our GUIs forum.

In my opinion, the implementation needs to be separated from the display. Create classes which represent the implementation and have them running with input and output via the command line. Make sure you have a public interface for your implementation. Then put a GUI on top of it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!