Dear members.

I have written small program to calculate the grades
of two courses. My program consists of 4 small
programs. One piece is to create dialog to display two
courses from which the can select.The second dialog is
to input the marks obtained for each course and also
displays the output(grades). The third piece is to
create JFrame window which is the parent. the fouth
part is for application.

Input/Output dialog is called after the user selects
the two courses displayed in the first dialog.
I have put the function for computing the grade
in Input/Output dialog program. Also I have put
another function to determine whether the course is
selected or not in the same program.

The prgoram is compiling, but after I click the
button on Input/Output dialog to compute the
grades I get strange message that I don't understand 
such as "Exception occur during event dispatching",
etc.

however the program is working fine if I use only one
dialog for both displaying the courses  to be selected
and receiving input(marks) and displaying
output(grades). But what is to use two separate
dialogs.

I am posting the codes for this program, and I would
be grateful if you you could examine these codes and 
find the errors for me. Please help solve this
problem.
====================================================
JBuilder 4.0
=====================================================

package grade;


import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;

public class Course extends JDialog {
  JPanel panel1 = new JPanel();
  XYLayout xYLayout1 = new XYLayout();
  JCheckBox check_course1 = new JCheckBox();
  JCheckBox check_course2 = new JCheckBox();
  JLabel course_label = new JLabel();
  JButton next_button = new JButton();
  InputOutput io=new InputOutput();
  XYLayout xYLayout2 = new XYLayout();

  public Course(Frame frame, String title, boolean
modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public Course() {
    this(null, "", false);
  }
  void jbInit() throws Exception {
    panel1.setLayout(xYLayout1);
    check_course1.setText("Basic Computing
Principles");
    check_course2.setText("Business Organization");
    course_label.setText("You must select both
courses:");
    this.setTitle("Grade Compute");
    this.getContentPane().setLayout(xYLayout2);
    next_button.setText("NEXT");
    next_button.addActionListener(new
java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        next_button_actionPerformed(e);
      }
    });
    xYLayout2.setWidth(325);
    xYLayout2.setHeight(303);
    getContentPane().add(panel1, new XYConstraints(0,
0, -1, -1));
    panel1.add(check_course2, new XYConstraints(77,
167, -1, -1));
    panel1.add(check_course1, new XYConstraints(76,
135, -1, -1));
    panel1.add(course_label, new XYConstraints(75, 93,
181, 32));
    panel1.add(next_button, new XYConstraints(117,
256, 113, 30));
  }

  void next_button_actionPerformed(ActionEvent e) {
    io.setVisible(true);
  }
}

package grade;

import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;

public class InputOutput extends JDialog {
  JPanel panel1 = new JPanel();
  JLabel course_label1 = new JLabel();
  XYLayout xYLayout1 = new XYLayout();
  JTextField mark_field1 = new JTextField();
  JLabel mark_label1 = new JLabel();
  JLabel grade_label1 = new JLabel();
  JTextField grade_field1 = new JTextField();
  JLabel mark_label2 = new JLabel();
  JLabel grade_label2 = new JLabel();
  JTextField mark_field2 = new JTextField();
  JTextField grade_field2 = new JTextField();
  JLabel course_label2 = new JLabel();
  JLabel title_label = new JLabel();
  JButton compute_button = new JButton();
  XYLayout xYLayout2 = new XYLayout();

  Course cs;

  public InputOutput(Frame frame, String title,
boolean modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public InputOutput() {
    this(null, "", false);
  }
  void jbInit() throws Exception {
    panel1.setLayout(xYLayout1);
    course_label1.setText("Basic Computing
Principles");
    mark_field1.setText("0");
    mark_label1.setText("Marks");
    grade_label1.setText("Grade");
    grade_field1.setText("");
    mark_label2.setText("Marks");
    grade_label2.setText("Grade");
    mark_field2.setText("0");
    grade_field2.setText("");
    course_label2.setText("Business Organization:");
    title_label.setText("You must enter marks of both
courses");
    compute_button.setText("COMPUTE");
    compute_button.addActionListener(new
java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        compute_button_actionPerformed(e);
      }
    });
    this.getContentPane().setLayout(xYLayout2);
    xYLayout2.setWidth(396);
    xYLayout2.setHeight(359);
    getContentPane().add(panel1, new XYConstraints(0,
0, -1, -1));
    panel1.add(title_label, new XYConstraints(20, 13,
219, 27));
    panel1.add(course_label1, new XYConstraints(21,
49, 164, 26));
    panel1.add(mark_field1, new XYConstraints(187, 88,
84, 29));
    panel1.add(mark_label1, new XYConstraints(31, 88,
104, 28));
    panel1.add(grade_field1, new XYConstraints(186,
127, 86, 30));
    panel1.add(grade_label1, new XYConstraints(29,
130, 69, 28));
    panel1.add(course_label2, new XYConstraints(26,
173, 146, 21));
    panel1.add(mark_field2, new XYConstraints(188,
201, 82, 32));
    panel1.add(mark_label2, new XYConstraints(26, 203,
73, 25));
    panel1.add(grade_field2, new XYConstraints(188,
246, 81, 33));
    panel1.add(grade_label2, new XYConstraints(26,
252, 82, 28));
    panel1.add(compute_button, new XYConstraints(104,
302, 169, 42));
  }


  public void checkedCourse() //check the checkbox
selected
    {
     
if((cs.check_course1.isSelected()==true)&&(cs.check_course2.isSelected()==true)){
        result();
        }
      }
//xxxxxxxxxxxxxxxxxxxxxxx

public void course1() // find the grade for course 1
  {
  String mark_str1,grade_str1;
   int marks1;
   mark_str1=mark_field1.getText();
   marks1=Integer.parseInt(mark_str1);

if((marks1<40)&&(marks1>0)){
      grade_field1.setText("F");
      }
  else
   if((marks1>=40)&&(marks1<60)){
      grade_field1.setText("C");
      }
  else
   if((marks1>=60)&&(marks1<80)){
      grade_field1.setText("B");
      }
  else
   if((marks1>=80)&&(marks1<=100)){
      grade_field1.setText("A");
      }
    }

//xxxxxxxxxxxxxxxxxxxxxxxxx

  public void course2() // find the grade for course 2
  {
    String mark_str2,grade_str2;
     int marks2;
     mark_str2=mark_field2.getText();

     marks2=Integer.parseInt(mark_str2);
if((marks2<40)&&(marks2>0)){
      grade_field2.setText("F");
      }
  else
   if((marks2>=40)&&(marks2<60)){
      grade_field2.setText("C");
      }
  else
   if((marks2>=60)&&(marks2<80)){
      grade_field2.setText("B");
      }
  else
   if((marks2>=80)&&(marks2<=100)){
      grade_field2.setText("A");
      }
    }
  public void result()
   {
   course1();
   course2();
    }

  void compute_button_actionPerformed(ActionEvent e) {
  checkedCourse();
  }
}


package grade;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;

public class MainFrame extends JFrame {
  JPanel contentPane;
  XYLayout xYLayout1 = new XYLayout();
  JButton compute_button = new JButton();
  Course cs= new Course();
  XYLayout xYLayout2 = new XYLayout();

  /**Construct the frame*/
  public MainFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception  {
    compute_button.setText("Compute Grade");
    compute_button.addActionListener(new
java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        compute_button_actionPerformed(e);
      }
    });
   
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your
Icon]")));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(429, 330));
    this.setTitle("COMPUTE GRADE");
    cs.getContentPane().setLayout(xYLayout2);
    contentPane.add(compute_button, new
XYConstraints(89, 119, 227, 65));
  }
  /**Overridden so we can exit when window is closed*/
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void compute_button_actionPerformed(ActionEvent e) {
   cs.setVisible(true);
  }
}

package grade;

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

public class GradeApplication {
  boolean packFrame = false;

  /**Construct the application*/
  public GradeApplication() {
  MainFrame frame = new MainFrame();
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size
info, e.g. from their layout
    if (packFrame) {
      frame.pack();
    }
    else {
      frame.validate();
    }
    //Center the window
    Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width -
frameSize.width) / 2, (screenSize.height -
frameSize.height) / 2);
    frame.setVisible(true);
  }
  /**Main method*/
  public static void main(String[] args) {
    try {
     
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    new GradeApplication();
  }
}





__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to