Results 1 to 3 of 3
- 01-12-2011, 04:44 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
JButton and Command Pattern help
Hi,
I am making a GUI which implements a command pattern that will output a simple message saying "hello". I have a class Client within a package gmit. I have a button called connect which does the following:
class connect implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Command command = (Command)e.getSource();
command.run();
}
}
every time i press the button i get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to gmit.Command
at gmit.Client$connect.actionPerformed(Client.java:57 ).
could someone please help me...Last edited by gavo87; 01-12-2011 at 05:57 PM.
-
The error is telling you what you're doing wrong. e.getSource returns the JButton object, and you can't use this as a Command object (whatever that is). You'll have to find another way to get the reference to your Command object, and we can't help you with this given the information presented so far. If you need more help, you'll need to give us more information including code with code tags please.
Last edited by Fubarable; 01-12-2011 at 05:20 PM.
-
Similar Threads
-
strategy pattern and bridge pattern
By jomypgeorge in forum New To JavaReplies: 2Last Post: 12-13-2010, 05:13 AM -
Better way of Command pattern implementation
By Galian in forum Advanced JavaReplies: 4Last Post: 11-06-2010, 07:34 PM -
Class pattern to generate following pattern:-
By vxs in forum New To JavaReplies: 5Last Post: 07-14-2010, 11:15 PM -
Command design pattern
By hannes in forum AWT / SwingReplies: 10Last Post: 01-28-2010, 06:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks