//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 ();
}
}
caierhui 0 Newbie Poster
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.