my problem is that i dont know how will i start, i have the idea but i cant apply it.,.,. can you help me to put the cation listener??
this is a case study i am a i.t student in the philippines. and my project is a student grades.. the output is to get the name and grde from test one up to test three then it will show the average of the 3 test in the text area please help me out,..,.,..,., please help me
thankyou

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

    public class Login extends JFrame{
        private JLabel myTestLabel1, myTestLabel2, myTestLabel3, myStudentNameLabel, myLabel4,AverageTextFieldLabel;
        private JButton myButton;
        private JRadioButton myRadioButton1, myRadioButton2, myRadioButton3;
        private JTextField myTest1, myTest2, myTest3, myStudentName, AverageTextField;
            private JTextArea myStudentTextArea;

        public Login()
        {
            super("StudentGrades");
                Container container= getContentPane();
                container.setLayout(new FlowLayout());


                myStudentNameLabel= new JLabel("Student Name:");
                myStudentNameLabel.setBounds( 16, 16, 208, 218 );

                container.add(myStudentNameLabel);


                myStudentName= new JTextField(10);
                    myStudentName.setBounds( 16, 16, 208, 218 );
                container.add(myStudentName);




                //test1//
                myTestLabel1= new JLabel("Test 1");
            myTestLabel1.setBounds( 16, 16, 208, 218 );
                container.add(myTestLabel1);


                myTest1= new JTextField(10);
            myTest1.setBounds( 16, 16, 208, 218 );
                container.add(myTest1);

                //test2//
                myTestLabel2= new JLabel("Test 2");
                myTestLabel2.setBounds( 16, 16, 208, 218 );
                container.add(myTestLabel2);

                myTest2= new JTextField(10);
                myTest2.setBounds( 16, 16, 208, 218 );
                container.add(myTest2);

                //test3//
                myTestLabel3= new JLabel("Test 3");
                myTestLabel3.setBounds( 16, 67, 208, 218 );
                container.add(myTestLabel3);
                myTest3= new JTextField(10);
                myTest3.setBounds( 16, 76, 208, 218 );
                container.add(myTest3);


                myButton= new JButton ("Submit Grades");//inserting button
                myButton.setBounds( 16, 45, 208, 218 );
                container.add(myButton);





                //lalam radio button//
                myRadioButton1= new JRadioButton("Letter");
                container.add(myRadioButton1);

                myRadioButton2= new JRadioButton("Numeric");
                container.add(myRadioButton2);


                myLabel4= new JLabel( "TextArea");
                container.add(myLabel4);

                myStudentTextArea= new JTextArea("Two");
                container.add(myStudentTextArea);
                setSize(2341, 1233);
                setVisible(true);


                    AverageTextFieldLabel= new JLabel("Average");
            AverageTextFieldLabel.setBounds( 16, 16, 208, 218 );
                container.add(AverageTextFieldLabel);


                myTest1= new JTextField(10);

                container.add(AverageTextField);






















            }

            private class ButtonHandler implements ActionListener
    {
                public void actionPerformed(ActionEvent event)
                {







                    }
                }





            public static void main(String[]args)
            {
                Login application = new Login();
                application.setDefaultCloseOperation(
                    JFrame.EXIT_ON_CLOSE);
                }
        }

Ok, so in your actionPerformed method, you put whatever code you need to do what you want when the button is pressed. Then you add the action listener to the button by writing the following:

myButton= new JButton ("Submit Grades");//inserting button
myButton.setBounds( 16, 45, 208, 218 );
myButton.addActionListener( new ButtonHandler() );
container.add(myButton);

That's all there is to it really...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.