Please Download This
http://www.mediafire.com/file/xikt4zotccrkrv4/GPA_Arid.jar

I am facing Reset Problem. It Reset but when I Change Credit Hours it restore previous entered Value.

Reset Button

private void Reset(java.awt.event.ActionEvent evt) {                       
        _M1.setEditable(false);
        _M2.setEditable(false);
        _M3.setEditable(false);
        _M4.setEditable(false);
        _M5.setEditable(false);
        _M6.setEditable(false);
        _M1.setText("");
        _M2.setText("");
        _M3.setText("");
        _M4.setText("");
        _M5.setText("");
        _M6.setText("");
        _C1.setSelectedIndex(0);
        _C2.setSelectedIndex(0);
        _C3.setSelectedIndex(0);
        _C4.setSelectedIndex(0);
        _C5.setSelectedIndex(0);
        _C6.setSelectedIndex(0);
        Master.setSelectedIndex(0);
        _C1.requestFocus();
    }

Master Credit Hours ComboBox

private void MasterActionPerformed(java.awt.event.ActionEvent evt) {                                       
        JComboBox cb = (JComboBox)evt.getSource();
        _C1.setSelectedItem(cb.getSelectedItem());
        _C2.setSelectedItem(cb.getSelectedItem());
        _C3.setSelectedItem(cb.getSelectedItem());
        _C4.setSelectedItem(cb.getSelectedItem());
        _C5.setSelectedItem(cb.getSelectedItem());
        _C6.setSelectedItem(cb.getSelectedItem());
        _M1.requestFocus();
    }

Thanks

please post here runnable code that contains per once of JComponents ...,

be sure that by creating this example you'll find this mistake

First off, I love the gui.
I have a Math Loop program using JComboBox and JTextFields. I used arrays so idk if my code will be helpful. but. . .

if(event.getStateChange()== ItemEvent.SELECTED){
                NumberOfQuestions = o[box.getSelectedIndex()];

Using and array would be helpful in assuring everything is reset.

I can not tell were it is storing the value for your marks.
Is it ever being stored temp in another variable?
Put Print Statements in your code so that you can see what each variable is doing after each method.
Ex. during reset. System.out.println("All your variables") all of them*

I also noticed that you have some small errors. 7s are not bold when entered like the rest are. numbers are jumbled together in your error message telling user to fill all boxes

Em Using these Variables to Get Values from TextFields...

s1 = Integer.parseInt(_M1.getText());
                    s2 = Integer.parseInt(_M2.getText());
                    s3 = Integer.parseInt(_M3.getText());
                    s4 = Integer.parseInt(_M4.getText());
                    s5 = Integer.parseInt(_M5.getText());
                    s6 = Integer.parseInt(_M6.getText());

Em not Setting Values of any TextField from Code.. User can input there only..


and I didn't had any other idea about error message so I combined them togather in error dialog...

String s="";
            if(_M1.getText().equals(""))
            {
                s=s+" 1";
            }
            if(_M2.getText().equals(""))
            {
                s=s+" 2";
            }
            if(_M3.getText().equals(""))
            {
                s=s+" 3";
            }
            if(_M4.getText().equals(""))
            {
                s=s+" 4";
            }
            if(_M5.getText().equals(""))
            {
                s=s+" 5";
            }
            if(_M6.getText().equals(""))
            {
                s=s+" 6";
            }
            JOptionPane.showMessageDialog(null, "Please Enter Marks of Subject : "+s, "Error", JOptionPane.ERROR_MESSAGE);
                        _M1.requestFocus();

Same for Wrong Marks...


And Reset Problem exist in JFormattedField.... If I JTextField Then there isn't any Error...

Didn't Know why 7 wasn't Bold Now used Font.BOLD .. every digit is Bold now..

Updated Now... Check and give suggestion :)

http://www.mediafire.com/?txe9w97ghnn269f

Having the user fixing one error at a time worked well enough.
Like the clear instruction in the note at the bottom.
Try using try and catch to catch if user does not enter an integer for marks.
This should cover user not entering a value or entering a letter.
What happens if the user does not have 6 classes?
Maybe make it if the the credit hourse for the course changed then try to parse it.
Just an example.
Try{
If CreditHours1 changed then parse int of text field
If Credit hours2 changes then parse int of text filed
Just a suggestion

I like how you have the textfield set to enabled(false) if the course selection has not been changed.
With the same logic you used to do that is the same logic you can use to determine how many course to average

Round your final calculations down to display only one place after decimal
I am in a community college so IDK how marks work. Is there only 20 per hour?

Edited 5 Years Ago by J-Dub: sent to early

Just to clarify.
If I enter "a" in one of the text fields I get the same error as if I entered nothing.It would be better if I got a different massage telling me to enter a numeric value for each of the inputs. Something generic like that would be perfectly fine. No absolute need to tell user exactly were the problem is in this case. But generic is the easy way out so. . .

Try catches should be used just about anytime something is going to be parsed.
I know that is what is suppose to be done. I cannot tell you exactly why but i know it should be done. It is useful because
Lets say I have alot of text fields and I need the user to enter int for all so I can do some sort of calc. Rather then go through all of them and make if statements, I can a a try and catch block try to parse all textfields that need an int input at once.

I like how you have the textfield set to enabled(false) if the course selection has not been changed.
With the same logic you used to do that is the same logic you can use to determine how many course to average

Nice Suggestion I will modify it today,,,
Solved 2nd Problem you mentioned about numeric value only,,,

I have used plaindocument to restrict use to enter numeric only,, now changed error message for non numeric values,, :)

You helped alot... thanks alot,,,

This article has been dead for over six months. Start a new discussion instead.