Code:
package button;
import javax.swing.*;
import java.awt.event.*;
public class Actions extends JFrame implements ActionListener
{
JPanel pnl = new JPanel();
public static void main (String[] args)
{
Actions gui = new Actions();
}
JButton btn1 = new JButton("Submit");
JButton btn2 = new JButton("Cancel");
JTextField txt1 = new JTextField("Message to:",38);
JTextField tx1 = new JTextField("Subject:",38);
JTextArea txt = new JTextArea("Essay:",5,37);
JScrollPane pane = new JScrollPane(txt);
public Actions()
{
super ("Button");
setSize(500,250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(pnl);
setVisible(true);
pnl.add(txt1);
pnl.add(tx1);
pnl.add(pane);
pnl.add(btn1);
pnl.add(btn2);
btn2.setEnabled(false);
btn1.addActionListener(this);
btn2.addActionListener(this);
if (event.getSource() == btn1)
{btn2.setEnabled(true); btn1.setEnabled(false);}
if (event.getSource() == btn2)
{btn2.setEnabled(false); btn1.setEnabled(true);}
}
}
Errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type Actions must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
event cannot be resolved
event cannot be resolved
at button.Actions.<init>(Actions.java:4)
at button.Actions.main(Actions.java:9)