Results 1 to 2 of 2
  1. #1
    xduh9 is offline adoi
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default java ClassAverageExam do,while condition

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DateFormat;
    import java.util.Date;

    public class ClassAverageExam extends JFrame
    {

    private JLabel gradeListJLabel;
    private JTextArea gradeListJTextArea;
    private JLabel securityCodeJLabel;
    private JPasswordField securityCodeJPasswordField;



    private JButton getGradesJButton;


    private JButton yesJButton;


    private JButton averageJButton;


    private JLabel ClassAverageExamJLabel;
    private JTextField classAverageJTextField;

    private int total = 0;


    public ClassAverageExam()
    {
    createUserInterface();
    }


    private void createUserInterface()
    {

    Container contentPane = getContentPane();


    contentPane.setLayout( null );


    gradeListJLabel = new JLabel();
    gradeListJLabel.setBounds( 16, 8, 70, 23 );
    gradeListJLabel.setText( "Grade list:" );
    contentPane.add( gradeListJLabel );


    gradeListJTextArea = new JTextArea();
    gradeListJTextArea.setBounds( 16, 32, 88, 180 );
    contentPane.add( gradeListJTextArea );


    getGradesJButton = new JButton();
    getGradesJButton.setBounds( 128, 50, 100, 26 );
    getGradesJButton.setText( "Get Grades" );
    contentPane.add( getGradesJButton );
    getGradesJButton.addActionListener(

    yesJButton = new JButton();
    yesJButton.setBounds( 80, 64, 50, 50 );
    yesJButton.setText( "yes" );
    contentPane.add( yesButton );
    yesButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    getGradesJButtonActionPerformed( event );
    }

    }

    );


    averageJButton = new JButton();
    averageJButton.setBounds( 128, 90, 100, 26 );
    averageJButton.setText( "Average" );
    averageJButton.setEnabled( false );
    contentPane.add( averageJButton );
    averageJButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    averageJButtonActionPerformed( event );
    }

    }

    );


    ClassAverageExamJLabel = new JLabel();
    ClassAverageExamJLabel.setBounds( 128, 132, 90, 23 );
    ClassAverageExamJLabel.setText( "Class average:" );
    contentPane.add( ClassAverageExamJLabel );


    classAverageJTextField = new JTextField();
    classAverageJTextField.setBounds( 128, 156, 100, 21 );
    classAverageJTextField.setEditable( false );
    classAverageJTextField.setHorizontalAlignment(
    JTextField.CENTER );
    contentPane.add( classAverageJTextField );


    setTitle( "Class Average" );
    setSize( 250, 250 );
    setVisible( true );

    }private void yesJButtonActionPerformed( ActionEvent event)
    {
    securityCodeJPasswordField.setText(String.valueOf(
    securityCodeJPasswordField.getPassword() ) + "yes" );
    }
    {
    securityCodeJPasswordField.setText( "" );
    private void enterJButtonActionPerformed( ActionEvent event )
    {
    String message;

    int accessCode = Integer.parseInt( String.valueOf(
    securityCodeJPasswordField.getPassword() ) );

    securityCodeJPasswordField.setText( "" );

    switch ( accessCode )
    {

    }


    private void getGradesJButtonActionPerformed( ActionEvent event )
    {
    total = 0;
    int counter = 1;
    String input;
    int grade;


    gradeListJTextArea.setText( "" );
    classAverageJTextField.setText( "" );

    do
    {

    input = JOptionPane.showInputDialog( null, "Enter Grade" );
    grade = Integer.parseInt( input );


    gradeListJTextArea.append( grade + "\n" );
    total += grade;
    counter++;
    }
    while ( counter <= 10 );

    averageJButton.setEnabled( true );
    averageJButton.requestFocusInWindow();

    }


    private void averageJButtonActionPerformed( ActionEvent event )
    {
    double average = ( double ) total / 10;
    classAverageJTextField.setText( String.valueOf( average ) );

    }


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

    }

    }


    help me master!
    how to loop to display msgbox in condition if i continue to enter another grades.
    thank you master..

    need help!
    Last edited by xduh9; 02-16-2012 at 02:07 AM.

  2. #2
    xduh9 is offline adoi
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: java ClassAverageExam do,while condition

    sir help me on this situation..

Similar Threads

  1. Condition ignored.
    By Pojahn_M in forum New To Java
    Replies: 8
    Last Post: 12-09-2011, 02:21 AM
  2. Waiting on a condition
    By nephos in forum New To Java
    Replies: 9
    Last Post: 04-22-2011, 10:05 AM
  3. basic condition
    By ts96 in forum New To Java
    Replies: 1
    Last Post: 02-16-2011, 12:23 PM
  4. While loop condition
    By counterfox in forum New To Java
    Replies: 3
    Last Post: 10-10-2010, 01:14 AM
  5. IF-Condition in a String
    By lenaz in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •