i have tried to add action listener to the buttons in my source code but i get a contenuos error that says "you can add action listener to your abstruct buttons"
so i was wondering how i would do that...some one pliz help me i have just started learning this java language
What I have tried:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class My_name extends JPanel
{
JButton b1,b2,b3,b4,b5,b6,b7;
GridBagConstraints gbc = new GridBagConstraints();
JTextField f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12;
JLabel l1,l2,l3,l4;
public My_name()
{
setLayout (new GridBagLayout());
gbc.insets = new Insets(8,8,8,8);
l1 = new JLabel("Mark Entry");
gbc.gridx = 0;
gbc.gridy = 0;
add(l1,gbc);
f1 = new JTextField("100%");
f1.setEditable(false);
gbc.gridx = 1;
gbc.gridy = 0;
add(f1,gbc);
l2 = new JLabel("%");
gbc.gridx = 1;
gbc.gridy = 2;
add(l2,gbc);
l3 = new JLabel("Grade");
gbc.gridx = 2;
gbc.gridy = 2;
add(l3,gbc);
b1 = new JButton("Business inteligence");
gbc.gridx = 0;
gbc.gridy = 3;
add(b1,gbc);
b2 = new JButton("DataBase Systems ");
gbc.gridx = 0;
gbc.gridy = 4;
add(b2,gbc);
b3 = new JButton(" Networks ");
gbc.gridx = 0;
gbc.gridy = 5;
add(b3,gbc);
b4 = new JButton("Programming ");
gbc.gridx = 0;
gbc.gridy = 6;
add(b4,gbc);
b5 = new JButton("System Security ");
gbc.gridx = 0;
gbc.gridy = 7;
add(b5,gbc);
f1 = new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 3;
add(f1,gbc);
f2 = new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 4;
add(f2,gbc);
f3 = new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 5;
add(f3,gbc);
f4= new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 6;
add(f4,gbc);
f5 = new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 7;
add(f5,gbc);
f6 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 3;
add(f6,gbc);
f7 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 4;
add(f7,gbc);
f8 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 5;
add(f8,gbc);
f9 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 6;
add(f9,gbc);
f10 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 7;
add(f10,gbc);
f11 = new JTextField(5);
gbc.gridx = 1;
gbc.gridy = 9;
add(f11,gbc);
f12 = new JTextField(5);
gbc.gridx = 2;
gbc.gridy = 9;
add(f12,gbc);
l1 = new JLabel("Over All");
gbc.gridx = 0;
gbc.gridy = 9;
add(l1,gbc);
b6 = new JButton("Over All");
gbc.gridx = 1;
gbc.gridy = 10;
add(b6,gbc);
b7 = new JButton("Clear ");
gbc.gridx = 2;
gbc.gridy = 10;
add(b7,gbc);
}
public static void main(String[] args)
{
My_name m = new My_name();
JFrame f = new JFrame();
f.setTitle("My work");
f.setSize(600,800);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.add(m);
}
}