![]() |
Having difficulty with Swing.
I'm just starting out with learning about Swing, and I'm running into some trouble already. Basically what's happening is I'm trying to make an array of 9 buttons (well a 3x3 array) but, well, let me show you:
:
import java.awt.*;I've commented the three lines in which the following three errors are reported by the compiler: :
guiTest is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListenerAny help? Thanks in advance! :) |
Why are you inheriting from ActionListener?
|
No offense, but the multitude of fundamental problems with your code most likely indicates that your understanding of the Java language is insufficient to be working with GUIs. Instead of taking the time to write out an explanation for each problem, I rewrote the code for you to study.
:
import java.awt.*; |
Thanks. I am pretty new to Java. Let me ask you one more thing? Is there a way (presumably in actionPerformed()) to tell which button of the array was clicked? Or do I have to use a different method for each one?
|
I prefer to use the getSource() method of the ActionEvent object:
:
public void actionPerformed(ActionEvent evt) {:
public void actionPerformed(ActionEvent evt) { |
Alright, thanks man.
|
| All times are GMT -5. The time now is 2:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC