I have a question about creating my own custom classes. I want my own class - NButton. The idea of this class was to quickly make JButtons, by adding my own custom argument sets. Here's my prototype for this:
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* NButton - Nick's JButton.
*
* @author (Nick Saika)
* @version (1.0 - 2006)
*/
public class NButton
{
/**
* Constructor for objects of class Btn
*/
public NButton(String s)
{
JButton button = new JButton();
button.setText(s);
}
public NButton(String s, ActionListener al)
{
JButton button = new JButton();
button.setText(s);
button.addActionListener(al);
}
}
On it's own, the code compiles fine. But I get the following error when I try to implement it with the following code in the main runtime class with the line npanel.add(new NButton("Exit", new ActionExit(0)));
.
(NOTE: ActionExit is another class I wrote which exits the program - I'm referencing it the same way as I am the NButton class, and it doesn't complain.