//their is an error in my program... and i dont know what it is...

//and i need to make two columns how can i do that?


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



public class Assign_1 extends JFrame
{
    private JLabel quizOneL,quizTwoL,quizThreeL,quizFourL,AverageScoreL;
    private JTextField quizOneTF,quizTwoTF,quizThreeTF,quizFourTF,AverageScoreTF;
    private JButton calculateB, exitB;

    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;

    private static final int WIDTH = 500;
    private static final int HEGHT = 400;

    public Assign_1()
    {

           quizOneL = new JLabel("Quiz One: ", SwingConstants.RIGHT);
           quizTwoL = new JLabel("Quiz Two: ", SwingConstants.RIGHT);
           quizThreeL = new JLabel("Quiz Three: ", SwingConstants.RIGHT);
           quizFourL = new JLabel("Quiz Four: ", SwingConstants.RIGHT);
           AverageScoreL = new JLabel ("Average Score: ", SwingConstants.RIGHT);

           quizOneTF = new JTextField(10);
           quizTwoTF = new JTextField(10);
           quizThreeTF = new JTextField(10);
           quizFourTF = new JTextField(10);
           AverageScoreTF = new JTextField (10);

           calculateB = new JButton ("Calculate");
           cbHandler = new CalculateButtonHandler ();
           calculateB.addActionListener(cbHandler);

           exitB = new JButton ("Quit");
           ebHandler = new ExitButtonHandler ();
           exitB.addActionListener(cbHandler);

           setTitle ("Weighted Average Computation");

           Container pane = getContentPane ();

           pane.setLayout(new GridLayout (5,2));

           pane.add(quizOneL);
           pane.add(quizOneTF);
           pane.add(quizTwoL);
           pane.add(quizTwoTF);
           pane.add(quizThreeL);
           pane.add(quizThreeTF);
           pane.add(quizFourL);
           pane.add(quizFourTF);
           pane.add(AverageScoreL);
           pane.add(AverageScoreTF);

           setSize(WIDTH, HEIGHT);
           setVisible (true);
           setDefaultCloseOperation(EXIT_ON_CLOSE);
           }

	
    private class CalculateButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            double quizOne,quizTwo,quizThree,quizFour,AverageScore;

            quizOne = Double.parseDouble(quizOneTF.getText());
            quizTwo = Double.parseDouble(quizTwoTF.getText());
            quizThree = Double.parseDouble(quizThreeTF.getText());
            quizFour = Double.parseDouble(quizFourTF.getText());
            AverageScore = (quizOne+quizTwo+quizThree+quizFour)/4
           AverageScoreTF.setText("");


        }
    }

	
    private class ExitButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
			System.exit (0);
        }
    }

	
    public static void main(String[] args)
    {
			Assign_1 rectObject = new Assign_1 ();
    }
}

im using a mac now.. i dont know if it is different.. but when ever i run this program the calculate button and the exit button does not appear.. what should i do?

im using netbeans and eclipse

Hi

You have not added the buttons to the pane that is the reason why you can not see them.

This line has no ; and that will give you an error when compiling.

AverageScore = (quizOne+quizTwo+quizThree+quizFour)/4

If you want to split your window area in to two columns that is easiest done by creating a left panel and a right panel. Then you add the labels, text fields and buttons on these two panels the way you want them to be and last you add the panels on the pane.

Hope this gave you some help.
Good luck =)

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.