I'm new to Java, and for the life of me I don't understand the whole inheritance concept apparently. I'm trying to create and exit button on a JWindow.
my main Class reads like this
Add my ExitButton Class Reads
I'm new to java so at the moment I'm just playing around trying to learn some skills. But the problem I'm having with first off all is when the JWindow Shows up the button also shows up but there is no label. From what I understand when I create "Fred" it should run my Class of ExitButton which tells it to create a button with "Exit" printed on it, all I get is a button that is blank. The other problem is the button isn't doing anything.
More importantly than just fixing my code, I want to know what is wrong with it.
Thank You,
casey
my main Class reads like this
Code:
public static void main(String[] args) {
JWindow MainWindow = new JWindow();
MainWindow.setVisible(true);
MainWindow.setSize(500,500);
MainWindow.setLocation(100,100);
ExitButton Fred = new ExitButton();
MainWindow.add(Fred);
}
Code:
public class ExitButton extends JButton implements ActionListener {
JButton button = new JButton("Exit");
ExitButton()
{
addActionListener(this);
setSize(10,10);
setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource()==button)
{
System.exit(0);
}
}
}
More importantly than just fixing my code, I want to know what is wrong with it.
Thank You,
casey
Comment