komlaaa
asked on
java.lang.StackOverflowError
Hi,
I am working on a GUI application. What could i check if i am having *java.lang.StackOverflowEr ror*
error message. That is all i am getting as error message. For this reason, my GUI compenent are NOT being displayed.
I am working on a GUI application. What could i check if i am having *java.lang.StackOverflowEr
error message. That is all i am getting as error message. For this reason, my GUI compenent are NOT being displayed.
ASKER
>>the stack trace should give you a good clue where it is occurring
all i am getting printed on my screen is: java.lang.StackOverflowErr or.
Thats hard to know where that occured
all i am getting printed on my screen is: java.lang.StackOverflowErr
Thats hard to know where that occured
can you post your code
ASKER
king of long though, but i think the problem is at architecture and constructors level
============== MAIN CLASS ============
public class StudentSupportServices extends JFrame
{
private StudentPanel studentPanel;
private CoursePanel coursePanel;
private JPanel studentCourseProfessorExam Panel;
private ProfessorPanel professorPanel;
private ExamPanel examPanel;
private ControlPanel controls;
private String url;
private JTextArea output;
private Connection accessCon;// = null;
private Container c;
/** Creates a new instance of StudentInformations */
public StudentSupportServices( )
{
super("Student Support Services");
if (!startApplication() ) System.exit(0);
c = getContentPane();
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new RenewDatabase());
menuBar.add( fileMenu );
setJMenuBar(menuBar);
output = new JTextArea();
output.setEditable(false);
setDefaultCloseOperation( EXIT_ON_CLOSE );
try
{
//Connect to ess database.
url = "jdbc:odbc:Driver={Microso ft Access Driver (*.mdb)};DBQ=" +
"C:/accessDb/Students.mdb" ;
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
accessCon = DriverManager.getConnectio n( url );
output.append("Connection successful\n");
}
catch( SQLException sqlex )
{
//process SQLException
sqlex.printStackTrace();
output.append("Connection Uncessful\n" + sqlex.toString() );
}
catch( Exception ex )
{
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
// course = new CoursePanel();
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL ayout(new GridLayout(1,2));
StudentProfessorPanel.add( studentPanel );
StudentProfessorPanel.add( professorPanel );
studentCourseProfessorExam Panel = new JPanel();
studentCourseProfessorExam Panel.setL ayout( new GridLayout(3,1) );
studentCourseProfessorExam Panel.add( StudentProfessorPanel );
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam Panel.add( coursePanel );
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam Panel.add( examPanel );
c.setLayout( new BorderLayout() );
c.add( studentCourseProfessorExam Panel, BorderLayout.CENTER ) ;
controls = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controls, BorderLayout.NORTH );
c.add( output, BorderLayout.SOUTH );
pack();
show();
}///////////////////// END OF CONSTRUCTOR
//tells the user the state of any request
public void setQueryInfo(String text)
{
output.setText("");
output.append( text );
}
public void showErrorMessages( String err )
{
Toolkit.getDefaultToolkit( ).beep();
JOptionPane.showMessageDia log(this,e rr, "Error",
JOptionPane.ERROR_MESSAGE );
return;
}
//check if there is a compenent on the panel already.
//if yes, remove it and place a the current one.
public void displayCourseTable( ResultSet rs, JTable table )
{
if( coursePanel.getComponentCo unt() > 0 )
coursePanel.removeAll();
try{
displayJTables( rs, table, "No courses found.");
}
catch(SQLException sqlex )
{
sqlex.printStackTrace();
}
//these two columns should be displayed to the user.
table.removeColumn( table.getColumnModel().get Column( 0 ) );
table.removeColumn( table.getColumnModel().get Column( 4 ) );
table.getColumnModel().get Column( 4 ).setPreferredWidth( 200 );
JScrollPane scroller = new JScrollPane( table );
coursePanel.add( scroller );
}
public void displayExamsTable(ResultSe t rs, JTable table)
{
try{
displayJTables( rs, table, "No courses found.");
}
catch(SQLException sqlex )
{
sqlex.printStackTrace();
}
/**these two columns should be displayed to the user.:
* ===> remove them from the table view
*Note that after removing the first column,
*the column which was at index 1, is shifted
*to index 0:====> remove at index 0 twice.
*/
table.removeColumn( table.getColumnModel( ).getColumn(0) );
table.removeColumn( table.getColumnModel( ).getColumn(0) );
table.getColumnModel().get Column(6). setPreferr edWidth(20 0);
JScrollPane scroller = new JScrollPane( table );
examPanel.add( scroller );
}
public Vector getNextRow(ResultSet rs, ResultSetMetaData meta)
throws SQLException
{
Vector currentRow = new Vector();
for(int i = 1; i <= meta.getColumnCount(); i++)
switch(meta.getColumnType( i) )
{
case Types.DOUBLE:
{
double x = rs.getDouble(i);
int u = (int)x;
currentRow.addElement( u + "" );
break;
}
case Types.VARCHAR:
case Types.LONGVARCHAR:
currentRow.addElement(rs.g etString(i ) );
break;
case Types.INTEGER:
currentRow.addElement( new Long( rs.getLong( i )) );
break;
case Types.DATE:
currentRow.addElement( rs.getDate( i ) );
break;
case Types.TIME:
currentRow.addElement(rs.g etTime( i ) );
break;
case Types.TIMESTAMP:
currentRow.addElement(rs.g etTimestam p( i ) );
break;
case Types.OTHER:
case Types.JAVA_OBJECT:
currentRow.addElement(rs.g etObject( i ) );
break;
}
return currentRow;
}
/////////////////// display exams
public void displayJTables( ResultSet rs, JTable table, String err )
throws SQLException
{
//position to first record
boolean moreRecords = rs.next();
//if there is no records, display a message
if( !moreRecords )
{
showErrorMessages( err );
}
Vector columnHeads = new Vector();
Vector rows = new Vector();
try
{
//get column heads
ResultSetMetaData rsmd = rs.getMetaData();
for( int i = 1; i <= rsmd.getColumnCount(); ++i )
columnHeads.addElement( rsmd.getColumnName( i ) );
//get row data
do {
rows.addElement( getNextRow(rs, rsmd) );
}while( rs.next() );
table.setModel( new DefaultTableModel(rows, columnHeads) );
}
catch (SQLException sqlex )
{
sqlex.printStackTrace();
}
}
....
///////////// MAIN ////////////////////////// //////
public static void main( String [] args )
{
new StudentSupportServices();
}
}//END OF MAIN CLASS
===================== CLASS CoursePanel ===============
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT , 10, 10));
setBorder(new CompoundBorder(
BorderFactory.createLineBo rder(Color .BLACK,1),
BorderFactory.createBevelB order(Beve lBorder.RA ISED)));
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
/**================= refresh the GUI ========================== ========*/
refresh = new JButton("Refresh");
new ImageIcon( getClass().getResource("im ages/Refre sh24.gif") );
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven t e)
{
refreshGUI();
}
}
);
add(refresh);
/**================= find courses ========================== ========*/
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe source("im ages/Bookm arks24.gif ")));
findCourse.setMnemonic('C' );
//add actionListner later
findCourse.addActionListen er
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
/**================= find Exams ========================== ========*/
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe source("im ages/Edit2 4.gif")));
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
/**================= add new Student ========================== =====*/
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe source("im ages/Add24 .gif")));
//add actionListner later
//addData.addActionListene r( new AddRecord(con, s, p, c, e) );
add( addData );
addData.setMnemonic('S');
/**================= update Student info ========================== ===*/
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe source("im ages/Save2 4.gif")));
//add actionListner later
add(updateData);
updateData.setMnemonic('s' );
help = new JButton( "Help",
new ImageIcon(getClass().getRe source("im ages/Help2 4.gif")));
//add actionListner later
add(help);
help.setMnemonic('H');
}
private void displayCourseTable()
{
coursePanel.populateCourse Table();
}
private void displayExamTable()
{
examPanel.populateExamTabl e();
}
private void refreshGUI()
{
studentPanel.clearSutdentP anel();
professorPanel.clearProfes sorPanel() ;
coursePanel.initCourseTabl e();
examPanel.initExamsTable() ;
studentPanel.refreshCombo( );
}
}
================= CLASS MyPanelModel ================
public abstract class MyPanelModel extends JPanel
{
/** Creates a new instance of MyPanelModel
*will be used as parent panel to initialize studentPanel, professorPanel
*coursePanel, examsPanel
*/
public MyPanelModel( String panelTitle )
{
super();
setLayout( new BorderLayout() );
setBorder(new TitledBorder(new EtchedBorder(), panelTitle));
}
}
================= CLASS ExamPanel ================
public class ExamPanel extends MyPanelModel
{
private JTable examsTable;
private Connection connection;
private CoursePanel coursePanel;
private ProfessorPanel professorPanel;
private StudentSupportServices sss;
/** Creates a new instance of ExamTable */
public ExamPanel(StudentSupportSe rvices sss, CoursePanel coursePanel,
Connection connection)
{
super("Exams");
setLayout( new BorderLayout() );
this.connection = connection;
this.coursePanel = coursePanel;
this.connection = connection;
this.sss = sss;
initExamsTable();
}
/**initialize examsTale */
public void initExamsTable()
{
examsTable = new JTable(new DefaultTableModel(
new Object [][]{ {"", "", "", "", "", "",""},
{"", "", "", "", "", "",""},{"", "", "", "", "", "",""},
{"", "", "", "", "", "",""}, {"", "", "", "", "", "",""},
{"", "", "", "", "", "",""} },
new Object[]{"Date", "Time", "Time In", "Time Out",
"Delivred by", "Total Time","Special Instruction"}) );
JScrollPane examScroll = new JScrollPane ( examsTable );
}
//popublate examsTable based on the course selected
public void populateExamTable()
{
int cID = 0;
int profID = 0;
//cehck to see if there is a compenent on panel already. If yes, remove it
// and place a new one.
if( this.getComponentCount() > 0 )
this.removeAll();
if(coursePanel.getComponen tCount() > 0 )
{
if( coursePanel.getSelectedRow Count() == 1 )
{
//these value are being retrieved from the Tablemodel not from the visible table.
cID = coursePanel.getCourseID();
profID = coursePanel.getProfessorID ();
}
else
{
sss.showErrorMessages("You must first select a course.");
return;
}
}
else
{
sss.showErrorMessages("1.) Find the couses\n 2.) select the a course\n" +
"3.) And find the exams for that course.");
}
System.out.println("class Num:" + cID);
System.out.println("profID : " + profID);
Statement profStm = null;
Statement examStm = null;
ResultSet profRs = null;
ResultSet examRs = null;
try{
profStm = connection.createStatement ();
examStm = connection.createStatement ();
profRs = profStm.executeQuery("SELE CT * FROM professor WHERE "+
"professorID =" + profID + ";");
examRs = examStm.executeQuery("SELE CT * FROM Exam WHERE CourseID" +
"=" + cID +";");
professorPanel.displayProf essor( profRs, profID );
sss.displayExamsTable( examRs, examsTable);
sss.setQueryInfo( "\nQuery Successful" );
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
}
finally
{
try
{
if( profStm != null ) profStm.close();
if( examStm != null ) examStm.close();
// if( profRs != null ) profRs.close();
// if( examRs != null ) examRs.close();
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
}
}
}
}//end of Class ExamPanel
================= CLASS CoursePanel ================
follow same logic as ExamPanel above
================= CLASS StudentPanel ================
public class StudentPanel extends MyPanelModel
implements ActionListener
{
private final JTextField firstField, idField, phoneField, boxField, accomField;
private final JComboBox lastCombo;
private JPanel fields ;
private Connection connection;
/** Creates a new instance of StudentPanel */
public StudentPanel(Connection connection)
{
super("Student");
this.connection = connection;
JPanel labels = new JPanel();
labels.setLayout( new GridLayout(6,1,0,3) );
JLabel lastLabel = new JLabel("Last Name: ", SwingConstants.RIGHT);
JLabel firstLabel = new JLabel("First Name: ", SwingConstants.RIGHT);
JLabel idLabel = new JLabel("Student Num: ", SwingConstants.RIGHT);
JLabel phoneLabel = new JLabel("Phone #: ", SwingConstants.RIGHT);
JLabel boxLabel = new JLabel("Box #: ", SwingConstants.RIGHT);
JLabel accomLabel = new JLabel("Accomodation: ", SwingConstants.RIGHT);
labels.add(lastLabel );
labels.add( firstLabel);
labels.add(idLabel );
labels.add(phoneLabel );
labels.add( boxLabel );
labels.add( accomLabel);
fields = new JPanel();
fields.setLayout( new GridLayout(6,1,0,3) );
lastCombo = new JComboBox( );
lastCombo.addActionListene r(this );//
// lastCombo.addItemListener( this);
lastCombo.setEditable(true );
firstField = new JTextField( ) ;
//firstField.setEditable(t rue);
idField = new JTextField();
phoneField = new JTextField(5);
boxField = new JTextField(5);
accomField = new JTextField();
fields.add( lastCombo );
fields.add( firstField );
fields.add(idField );
fields.add(phoneField );
fields.add( boxField );
fields.add( accomField);
add( labels, BorderLayout.WEST);
add(fields, BorderLayout.CENTER);
}
public void actionPerformed(ActionEven t event)
{
Statement studentStm = null;
ResultSet rs = null;
if (connection==null) {
System.out.println("You are missing a connection to the database");
}
String last = ((String)lastCombo.getSele ctedItem() ).trim();
System.out.println("Last Name: " + last);
if(last.length() !=0 ) // would this actually occur?
{
try{
studentStm = connection.createStatement ();
rs = studentStm.executeQuery("S ELECT * FROM Student" +
" WHERE [Last Name] = '" + last + "';");
displayStudent(rs);
}
catch( SQLException sqlex )
{
sqlex.printStackTrace();
}
finally
{
try
{
if (studentStm!=null) studentStm.close();
if (rs!=null) rs.close();
}
catch( SQLException sqlex )
{
//sqlex.printStackTrace();
}
}
}
}/////////////end of actionPerformed()
//display query result if not rs not null.
public void displayStudent( ResultSet rs )
{
int sId = 0;
try{
if( rs.next() )
{
sId = rs.getInt( 1 );
}
System.out.println("Studen t id2:" + sId);
if( sId != 0 )
{
lastCombo.setSelectedItem( rs.getString( 2 ) );
firstField.setText( rs.getString( 3 ) );
idField.setText( rs.getString( 4 ) );
phoneField.setText( rs.getString( 5 ) );
boxField.setText( rs.getString( 6 ) );
accomField.setText(rs.getS tring( 7 ) );
}
else
{
;// sss.setQueryInfo( " No record Found\n");
}
}
catch( SQLException sqlex )
{
sqlex.printStackTrace();
}
}// end of displayStudent( ).
//assign a new dataModel to the comboBox.
public void refreshCombo()
{
Statement s = null;
ResultSet rs = null;
try
{
s = connection.createStatement ();
rs = s.executeQuery("SELECT [Last Name] FROM Student");
// Vector firstNames = new Vector();
Vector lastNames = new Vector();
lastNames.addElement("-- SELECT --");
while( rs.next() )
{
lastNames.addElement( rs.getString("Last Name") );
}
lastCombo.setModel( new DefaultComboBoxModel(lastN ames) );
s.close();
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
}
}
//return last name
public String getLast()
{
return ((String)lastCombo.getSele ctedItem() ).trim();
}
//return first name
public String getFirst()
{
return ( (String)firstField.getText ()).trim() ;
}
//return student num
public String getStudentNum()
{
return ( (String)idField.getText() ).trim();
}
//return phone #
public String getPhoneNum()
{
return ( (String)phoneField.getText () ).trim();
}
//return Box num
public String getBoxNum()
{
return ( (String)boxField.getText() ).trim();
}
public String getAccom()
{
return ( (String)accomField.getText () ).trim();
}
public void setLastName( String text )
{
lastCombo.setSelectedItem( text );
}
public void setFirstName ( String text )
{
firstField.setText( text );
}
public void setStudentNum ( String text )
{
idField.setText( text );
}
public void setPhoneNum ( String text )
{
phoneField.setText( text );
}
public void setBoxNum ( String text )
{
boxField.setText( text );
}
public void setAccom ( String text )
{
accomField.setText( text );
}
public void clearSutdentPanel()
{
for(int i = 1; i < fields.getComponentCount() ; i++ )
((JTextField)fields.getCom ponent(i)) .setText(" ");
}
}
================= CLASS ProfessorPanel ================
follow same logic as StudentPanel above
================= CLASS ControlPanel =================
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT , 10, 10));
setBorder(new CompoundBorder(
BorderFactory.createLineBo rder(Color .BLACK,1),
BorderFactory.createBevelB order(Beve lBorder.RA ISED)));
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
/**================= refresh the GUI ========================== ========*/
refresh = new JButton("Refresh");
new ImageIcon( getClass().getResource("im ages/Refre sh24.gif") );
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven t e)
{
refreshGUI();
}
}
);
add(refresh);
/**================= find courses ========================== ========*/
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe source("im ages/Bookm arks24.gif ")));
findCourse.setMnemonic('C' );
//add actionListner later
findCourse.addActionListen er
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
/**================= find Exams ========================== ========*/
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe source("im ages/Edit2 4.gif")));
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
/**================= add new Student ========================== =====*/
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe source("im ages/Add24 .gif")));
//add actionListner later
//addData.addActionListene r( new AddRecord(con, s, p, c, e) );
add( addData );
addData.setMnemonic('S');
/**================= update Student info ========================== ===*/
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe source("im ages/Save2 4.gif")));
//add actionListner later
add(updateData);
updateData.setMnemonic('s' );
help = new JButton( "Help",
new ImageIcon(getClass().getRe source("im ages/Help2 4.gif")));
//add actionListner later
add(help);
help.setMnemonic('H');
}
private void displayCourseTable()
{
coursePanel.populateCourse Table();
}
private void displayExamTable()
{
examPanel.populateExamTabl e();
}
private void refreshGUI()
{
studentPanel.clearSutdentP anel();
professorPanel.clearProfes sorPanel() ;
coursePanel.initCourseTabl e();
examPanel.initExamsTable() ;
studentPanel.refreshCombo( );
}
}
============== MAIN CLASS ============
public class StudentSupportServices extends JFrame
{
private StudentPanel studentPanel;
private CoursePanel coursePanel;
private JPanel studentCourseProfessorExam
private ProfessorPanel professorPanel;
private ExamPanel examPanel;
private ControlPanel controls;
private String url;
private JTextArea output;
private Connection accessCon;// = null;
private Container c;
/** Creates a new instance of StudentInformations */
public StudentSupportServices( )
{
super("Student Support Services");
if (!startApplication() ) System.exit(0);
c = getContentPane();
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new RenewDatabase());
menuBar.add( fileMenu );
setJMenuBar(menuBar);
output = new JTextArea();
output.setEditable(false);
setDefaultCloseOperation( EXIT_ON_CLOSE );
try
{
//Connect to ess database.
url = "jdbc:odbc:Driver={Microso
"C:/accessDb/Students.mdb"
Class.forName("sun.jdbc.od
accessCon = DriverManager.getConnectio
output.append("Connection successful\n");
}
catch( SQLException sqlex )
{
//process SQLException
sqlex.printStackTrace();
output.append("Connection Uncessful\n" + sqlex.toString() );
}
catch( Exception ex )
{
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
// course = new CoursePanel();
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL
StudentProfessorPanel.add(
StudentProfessorPanel.add(
studentCourseProfessorExam
studentCourseProfessorExam
studentCourseProfessorExam
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam
c.setLayout( new BorderLayout() );
c.add( studentCourseProfessorExam
controls = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controls, BorderLayout.NORTH );
c.add( output, BorderLayout.SOUTH );
pack();
show();
}///////////////////// END OF CONSTRUCTOR
//tells the user the state of any request
public void setQueryInfo(String text)
{
output.setText("");
output.append( text );
}
public void showErrorMessages( String err )
{
Toolkit.getDefaultToolkit(
JOptionPane.showMessageDia
JOptionPane.ERROR_MESSAGE );
return;
}
//check if there is a compenent on the panel already.
//if yes, remove it and place a the current one.
public void displayCourseTable( ResultSet rs, JTable table )
{
if( coursePanel.getComponentCo
coursePanel.removeAll();
try{
displayJTables( rs, table, "No courses found.");
}
catch(SQLException sqlex )
{
sqlex.printStackTrace();
}
//these two columns should be displayed to the user.
table.removeColumn( table.getColumnModel().get
table.removeColumn( table.getColumnModel().get
table.getColumnModel().get
JScrollPane scroller = new JScrollPane( table );
coursePanel.add( scroller );
}
public void displayExamsTable(ResultSe
{
try{
displayJTables( rs, table, "No courses found.");
}
catch(SQLException sqlex )
{
sqlex.printStackTrace();
}
/**these two columns should be displayed to the user.:
* ===> remove them from the table view
*Note that after removing the first column,
*the column which was at index 1, is shifted
*to index 0:====> remove at index 0 twice.
*/
table.removeColumn( table.getColumnModel( ).getColumn(0) );
table.removeColumn( table.getColumnModel( ).getColumn(0) );
table.getColumnModel().get
JScrollPane scroller = new JScrollPane( table );
examPanel.add( scroller );
}
public Vector getNextRow(ResultSet rs, ResultSetMetaData meta)
throws SQLException
{
Vector currentRow = new Vector();
for(int i = 1; i <= meta.getColumnCount(); i++)
switch(meta.getColumnType(
{
case Types.DOUBLE:
{
double x = rs.getDouble(i);
int u = (int)x;
currentRow.addElement( u + "" );
break;
}
case Types.VARCHAR:
case Types.LONGVARCHAR:
currentRow.addElement(rs.g
break;
case Types.INTEGER:
currentRow.addElement( new Long( rs.getLong( i )) );
break;
case Types.DATE:
currentRow.addElement( rs.getDate( i ) );
break;
case Types.TIME:
currentRow.addElement(rs.g
break;
case Types.TIMESTAMP:
currentRow.addElement(rs.g
break;
case Types.OTHER:
case Types.JAVA_OBJECT:
currentRow.addElement(rs.g
break;
}
return currentRow;
}
/////////////////// display exams
public void displayJTables( ResultSet rs, JTable table, String err )
throws SQLException
{
//position to first record
boolean moreRecords = rs.next();
//if there is no records, display a message
if( !moreRecords )
{
showErrorMessages( err );
}
Vector columnHeads = new Vector();
Vector rows = new Vector();
try
{
//get column heads
ResultSetMetaData rsmd = rs.getMetaData();
for( int i = 1; i <= rsmd.getColumnCount(); ++i )
columnHeads.addElement( rsmd.getColumnName( i ) );
//get row data
do {
rows.addElement( getNextRow(rs, rsmd) );
}while( rs.next() );
table.setModel( new DefaultTableModel(rows, columnHeads) );
}
catch (SQLException sqlex )
{
sqlex.printStackTrace();
}
}
....
///////////// MAIN //////////////////////////
public static void main( String [] args )
{
new StudentSupportServices();
}
}//END OF MAIN CLASS
===================== CLASS CoursePanel ===============
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT
setBorder(new CompoundBorder(
BorderFactory.createLineBo
BorderFactory.createBevelB
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
/**================= refresh the GUI ==========================
refresh = new JButton("Refresh");
new ImageIcon( getClass().getResource("im
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven
{
refreshGUI();
}
}
);
add(refresh);
/**================= find courses ==========================
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe
findCourse.setMnemonic('C'
//add actionListner later
findCourse.addActionListen
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
/**================= find Exams ==========================
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
/**================= add new Student ==========================
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe
//add actionListner later
//addData.addActionListene
add( addData );
addData.setMnemonic('S');
/**================= update Student info ==========================
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe
//add actionListner later
add(updateData);
updateData.setMnemonic('s'
help = new JButton( "Help",
new ImageIcon(getClass().getRe
//add actionListner later
add(help);
help.setMnemonic('H');
}
private void displayCourseTable()
{
coursePanel.populateCourse
}
private void displayExamTable()
{
examPanel.populateExamTabl
}
private void refreshGUI()
{
studentPanel.clearSutdentP
professorPanel.clearProfes
coursePanel.initCourseTabl
examPanel.initExamsTable()
studentPanel.refreshCombo(
}
}
================= CLASS MyPanelModel ================
public abstract class MyPanelModel extends JPanel
{
/** Creates a new instance of MyPanelModel
*will be used as parent panel to initialize studentPanel, professorPanel
*coursePanel, examsPanel
*/
public MyPanelModel( String panelTitle )
{
super();
setLayout( new BorderLayout() );
setBorder(new TitledBorder(new EtchedBorder(), panelTitle));
}
}
================= CLASS ExamPanel ================
public class ExamPanel extends MyPanelModel
{
private JTable examsTable;
private Connection connection;
private CoursePanel coursePanel;
private ProfessorPanel professorPanel;
private StudentSupportServices sss;
/** Creates a new instance of ExamTable */
public ExamPanel(StudentSupportSe
Connection connection)
{
super("Exams");
setLayout( new BorderLayout() );
this.connection = connection;
this.coursePanel = coursePanel;
this.connection = connection;
this.sss = sss;
initExamsTable();
}
/**initialize examsTale */
public void initExamsTable()
{
examsTable = new JTable(new DefaultTableModel(
new Object [][]{ {"", "", "", "", "", "",""},
{"", "", "", "", "", "",""},{"", "", "", "", "", "",""},
{"", "", "", "", "", "",""}, {"", "", "", "", "", "",""},
{"", "", "", "", "", "",""} },
new Object[]{"Date", "Time", "Time In", "Time Out",
"Delivred by", "Total Time","Special Instruction"}) );
JScrollPane examScroll = new JScrollPane ( examsTable );
}
//popublate examsTable based on the course selected
public void populateExamTable()
{
int cID = 0;
int profID = 0;
//cehck to see if there is a compenent on panel already. If yes, remove it
// and place a new one.
if( this.getComponentCount() > 0 )
this.removeAll();
if(coursePanel.getComponen
{
if( coursePanel.getSelectedRow
{
//these value are being retrieved from the Tablemodel not from the visible table.
cID = coursePanel.getCourseID();
profID = coursePanel.getProfessorID
}
else
{
sss.showErrorMessages("You
return;
}
}
else
{
sss.showErrorMessages("1.)
"3.) And find the exams for that course.");
}
System.out.println("class Num:" + cID);
System.out.println("profID
Statement profStm = null;
Statement examStm = null;
ResultSet profRs = null;
ResultSet examRs = null;
try{
profStm = connection.createStatement
examStm = connection.createStatement
profRs = profStm.executeQuery("SELE
"professorID =" + profID + ";");
examRs = examStm.executeQuery("SELE
"=" + cID +";");
professorPanel.displayProf
sss.displayExamsTable( examRs, examsTable);
sss.setQueryInfo( "\nQuery Successful" );
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
}
finally
{
try
{
if( profStm != null ) profStm.close();
if( examStm != null ) examStm.close();
// if( profRs != null ) profRs.close();
// if( examRs != null ) examRs.close();
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
}
}
}
}//end of Class ExamPanel
================= CLASS CoursePanel ================
follow same logic as ExamPanel above
================= CLASS StudentPanel ================
public class StudentPanel extends MyPanelModel
implements ActionListener
{
private final JTextField firstField, idField, phoneField, boxField, accomField;
private final JComboBox lastCombo;
private JPanel fields ;
private Connection connection;
/** Creates a new instance of StudentPanel */
public StudentPanel(Connection connection)
{
super("Student");
this.connection = connection;
JPanel labels = new JPanel();
labels.setLayout( new GridLayout(6,1,0,3) );
JLabel lastLabel = new JLabel("Last Name: ", SwingConstants.RIGHT);
JLabel firstLabel = new JLabel("First Name: ", SwingConstants.RIGHT);
JLabel idLabel = new JLabel("Student Num: ", SwingConstants.RIGHT);
JLabel phoneLabel = new JLabel("Phone #: ", SwingConstants.RIGHT);
JLabel boxLabel = new JLabel("Box #: ", SwingConstants.RIGHT);
JLabel accomLabel = new JLabel("Accomodation: ", SwingConstants.RIGHT);
labels.add(lastLabel );
labels.add( firstLabel);
labels.add(idLabel );
labels.add(phoneLabel );
labels.add( boxLabel );
labels.add( accomLabel);
fields = new JPanel();
fields.setLayout( new GridLayout(6,1,0,3) );
lastCombo = new JComboBox( );
lastCombo.addActionListene
// lastCombo.addItemListener(
lastCombo.setEditable(true
firstField = new JTextField( ) ;
//firstField.setEditable(t
idField = new JTextField();
phoneField = new JTextField(5);
boxField = new JTextField(5);
accomField = new JTextField();
fields.add( lastCombo );
fields.add( firstField );
fields.add(idField );
fields.add(phoneField );
fields.add( boxField );
fields.add( accomField);
add( labels, BorderLayout.WEST);
add(fields, BorderLayout.CENTER);
}
public void actionPerformed(ActionEven
{
Statement studentStm = null;
ResultSet rs = null;
if (connection==null) {
System.out.println("You are missing a connection to the database");
}
String last = ((String)lastCombo.getSele
System.out.println("Last Name: " + last);
if(last.length() !=0 ) // would this actually occur?
{
try{
studentStm = connection.createStatement
rs = studentStm.executeQuery("S
" WHERE [Last Name] = '" + last + "';");
displayStudent(rs);
}
catch( SQLException sqlex )
{
sqlex.printStackTrace();
}
finally
{
try
{
if (studentStm!=null) studentStm.close();
if (rs!=null) rs.close();
}
catch( SQLException sqlex )
{
//sqlex.printStackTrace();
}
}
}
}/////////////end of actionPerformed()
//display query result if not rs not null.
public void displayStudent( ResultSet rs )
{
int sId = 0;
try{
if( rs.next() )
{
sId = rs.getInt( 1 );
}
System.out.println("Studen
if( sId != 0 )
{
lastCombo.setSelectedItem(
firstField.setText( rs.getString( 3 ) );
idField.setText( rs.getString( 4 ) );
phoneField.setText( rs.getString( 5 ) );
boxField.setText( rs.getString( 6 ) );
accomField.setText(rs.getS
}
else
{
;// sss.setQueryInfo( " No record Found\n");
}
}
catch( SQLException sqlex )
{
sqlex.printStackTrace();
}
}// end of displayStudent( ).
//assign a new dataModel to the comboBox.
public void refreshCombo()
{
Statement s = null;
ResultSet rs = null;
try
{
s = connection.createStatement
rs = s.executeQuery("SELECT [Last Name] FROM Student");
// Vector firstNames = new Vector();
Vector lastNames = new Vector();
lastNames.addElement("-- SELECT --");
while( rs.next() )
{
lastNames.addElement( rs.getString("Last Name") );
}
lastCombo.setModel( new DefaultComboBoxModel(lastN
s.close();
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
}
}
//return last name
public String getLast()
{
return ((String)lastCombo.getSele
}
//return first name
public String getFirst()
{
return ( (String)firstField.getText
}
//return student num
public String getStudentNum()
{
return ( (String)idField.getText() ).trim();
}
//return phone #
public String getPhoneNum()
{
return ( (String)phoneField.getText
}
//return Box num
public String getBoxNum()
{
return ( (String)boxField.getText()
}
public String getAccom()
{
return ( (String)accomField.getText
}
public void setLastName( String text )
{
lastCombo.setSelectedItem(
}
public void setFirstName ( String text )
{
firstField.setText( text );
}
public void setStudentNum ( String text )
{
idField.setText( text );
}
public void setPhoneNum ( String text )
{
phoneField.setText( text );
}
public void setBoxNum ( String text )
{
boxField.setText( text );
}
public void setAccom ( String text )
{
accomField.setText( text );
}
public void clearSutdentPanel()
{
for(int i = 1; i < fields.getComponentCount()
((JTextField)fields.getCom
}
}
================= CLASS ProfessorPanel ================
follow same logic as StudentPanel above
================= CLASS ControlPanel =================
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT
setBorder(new CompoundBorder(
BorderFactory.createLineBo
BorderFactory.createBevelB
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
/**================= refresh the GUI ==========================
refresh = new JButton("Refresh");
new ImageIcon( getClass().getResource("im
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven
{
refreshGUI();
}
}
);
add(refresh);
/**================= find courses ==========================
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe
findCourse.setMnemonic('C'
//add actionListner later
findCourse.addActionListen
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
/**================= find Exams ==========================
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
/**================= add new Student ==========================
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe
//add actionListner later
//addData.addActionListene
add( addData );
addData.setMnemonic('S');
/**================= update Student info ==========================
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe
//add actionListner later
add(updateData);
updateData.setMnemonic('s'
help = new JButton( "Help",
new ImageIcon(getClass().getRe
//add actionListner later
add(help);
help.setMnemonic('H');
}
private void displayCourseTable()
{
coursePanel.populateCourse
}
private void displayExamTable()
{
examPanel.populateExamTabl
}
private void refreshGUI()
{
studentPanel.clearSutdentP
professorPanel.clearProfes
coursePanel.initCourseTabl
examPanel.initExamsTable()
studentPanel.refreshCombo(
}
}
Can you add System.out.println(....)
in StudentSupportServices before the creation
of each one of your classes (StudentSupportServices, ProfessorPanel, CoursePanel, ...)
That will help to isolate your problem.
in StudentSupportServices before the creation
of each one of your classes (StudentSupportServices, ProfessorPanel, CoursePanel, ...)
That will help to isolate your problem.
ASKER
i actually did. I was able to print
I didn't see it in your code.
Did you post the println results?
If so, where is the last line of println
before you got StackOverflow exception?
Did you post the println results?
If so, where is the last line of println
before you got StackOverflow exception?
ASKER
>>I didn't see it in your code.
I did in most recent version
The GUI is displayed. All the component are there but i have to click on each one before i can see them,... strange.
.....
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
// course = new CoursePanel();
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL ayout( new GridLayout(1,2) );
StudentProfessorPanel.add( studentPanel );
StudentProfessorPanel.add( professorPanel );
studentCourseProfessorExam Panel = new JPanel();
studentCourseProfessorExam Panel.setL ayout( new GridLayout(3,1) );
studentCourseProfessorExam Panel.add( StudentProfessorPanel );
System.out.println("before StudentPanle");
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam Panel.add( coursePanel );
System.out.println("before ExamPanel");
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam Panel.add( examPanel );
c.setLayout( new BorderLayout() );
c.add( studentCourseProfessorExam Panel, BorderLayout.CENTER ) ;
System.out.println("before controPanle");
controlPanel = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controlPanel, BorderLayout.NORTH );
System.out.println("after controPanle");
c.add( output, BorderLayout.SOUTH );
pack();
show();
}///////////////////// END OF CONSTRUCTOR
I did in most recent version
The GUI is displayed. All the component are there but i have to click on each one before i can see them,... strange.
.....
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
// course = new CoursePanel();
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL
StudentProfessorPanel.add(
StudentProfessorPanel.add(
studentCourseProfessorExam
studentCourseProfessorExam
studentCourseProfessorExam
System.out.println("before
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam
System.out.println("before
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam
c.setLayout( new BorderLayout() );
c.add( studentCourseProfessorExam
System.out.println("before
controlPanel = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controlPanel, BorderLayout.NORTH );
System.out.println("after controPanle");
c.add( output, BorderLayout.SOUTH );
pack();
show();
}///////////////////// END OF CONSTRUCTOR
Does the exception come after all the printouts?
ASKER
>Does the exception come after all the printouts?
yes
yes
Never tried to see what happens when you
add a container (panel) to a container which is
already its child. If java does not dectect such error during the add operation then that might lead to infinte recursion during the presentation.
add a container (panel) to a container which is
already its child. If java does not dectect such error during the add operation then that might lead to infinte recursion during the presentation.
ASKER
>Never tried to see what happens when you
>add a container (panel) to a container which is
>already its child
Where do you mean? where did i do that?
>add a container (panel) to a container which is
>already its child
Where do you mean? where did i do that?
Just rasing a posibility though I could not find it in your code so far.
You are printing the stack-trace of all exceptions, I guess. Were you not able to catch which line it occurs at? (Check your console.)
ASKER
>Were you not able to catch which line it occurs at?
all i am geting prited on my srcreen is *java.lang.StackOverflowEr ror* JUST THAT otherwise i could have fixed it.
all i am geting prited on my srcreen is *java.lang.StackOverflowEr
ASKER
Also all the components appeared on my main Frame but i have click on each one before they become visible.
are you running this code in an ide? try running it from the command line so we get a proper stack trace out of it, and post..
1. You may try to comment out all the database stuffs, and try if there is still StackOverFlowError.
2. If StackOverFlowError still occurs, try to isolate each component by adding one component at a time.
Since the program is very long for others to trace, please try my suggestion to get your problem easier to be solved.
2. If StackOverFlowError still occurs, try to isolate each component by adding one component at a time.
Since the program is very long for others to trace, please try my suggestion to get your problem easier to be solved.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>The reason for only visible after clicking buttons are you are trying to add the components inside your actionlisteners >>of the buttons.If this is not your intension, you need to call the displayXXX inside your constructor.
I think u r right. The StackOverFlowError is gonne but then i am running into NullPointerException eventhough i have initialized all my constructor before using them:
java.lang.NullPointerExcep tion
at sss2.StudentPanel.getLast( StudentPan el.java:19 4)
at sss2.CoursePanel.populateC ourseTable (CoursePan el.java:67 )
at sss2.ControlPanel.displayC ourseTable (ControlPa nel.java:1 25)
at sss2.ControlPanel.<init>(C ontrolPane l.java:119 )
at sss2.StudentSupportService s.<init>(S tudentSupp ortService s.java:108 )
at sss2.StudentSupportService s.main(Stu dentSuppor tServices. java:796)
I think u r right. The StackOverFlowError is gonne but then i am running into NullPointerException eventhough i have initialized all my constructor before using them:
java.lang.NullPointerExcep
at sss2.StudentPanel.getLast(
at sss2.CoursePanel.populateC
at sss2.ControlPanel.displayC
at sss2.ControlPanel.<init>(C
at sss2.StudentSupportService
at sss2.StudentSupportService
ASKER
================ New Version of Contropanel ==========
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT , 5, 5));
// setBorder(new CompoundBorder(
// BorderFactory.createLineBo rder(Color .BLACK,1),
// BorderFactory.createBevelB order(Beve lBorder.RA ISED)));
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
System.out.println("before refresh");
/**================= refresh the GUI ========================== ========*/
refresh = new JButton("Refresh",
new ImageIcon( getClass().getResource("im ages/Refre sh24.gif") ));
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven t e)
{
refreshGUI();
}
}
);
add(refresh);
System.out.println("before findCourse");
/**================= find courses ========================== ========*/
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe source("im ages/Bookm arks24.gif ")));
findCourse.setMnemonic('C' );
//add actionListner later
findCourse.addActionListen er
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
System.out.println("before findExam");
/**================= find Exams ========================== ========*/
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe source("im ages/Edit2 4.gif")));
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
System.out.println("before add new Student");
/**================= add new Student ========================== =====*/
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe source("im ages/Add24 .gif")));
//add actionListner later
//addData.addActionListene r( new AddRecord(con, s, p, c, e) );
add( addData );
addData.setMnemonic('S');
/**================= update Student info ========================== ===*/
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe source("im ages/Save2 4.gif")));
//add actionListner later
add(updateData);
updateData.setMnemonic('s' );
help = new JButton( "Help",
new ImageIcon(getClass().getRe source("im ages/Help2 4.gif")));
//add actionListner later
add(help);
help.setMnemonic('H');
displayCourseTable();
displayExamTable();
}
private void displayCourseTable()
{
coursePanel.populateCourse Table();
}
private void displayExamTable()
{
examPanel.populateExamTabl e();
}
private void refreshGUI()
{
studentPanel.clearSutdentP anel();
professorPanel.clearProfes sorPanel() ;
coursePanel.initCourseTabl e();
examPanel.initExamsTable() ;
studentPanel.refreshCombo( );
}
}
===========StudentSupportS ervices=== =========
public StudentSupportServices( )
{
super("Student Support Services");
if (!startApplication() ) System.exit(0);
c = getContentPane();
c.setLayout( new BorderLayout() );
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new RenewDatabase());
menuBar.add( fileMenu );
setJMenuBar(menuBar);
output = new JTextArea();
output.setEditable(false);
setDefaultCloseOperation( EXIT_ON_CLOSE );
try
{
//Connect to ess database.
url = "jdbc:odbc:Driver={Microso ft Access Driver (*.mdb)};DBQ=" +
"C:/accessDb/Students.mdb" ;
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
accessCon = DriverManager.getConnectio n( url );
output.append("Connection successful\n");
}
catch( SQLException sqlex )
{
//process SQLException
sqlex.printStackTrace();
output.append("Connection Uncessful\n" + sqlex.toString() );
}
catch( Exception ex )
{
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL ayout( new GridLayout(1,2) );
StudentProfessorPanel.add( studentPanel );
StudentProfessorPanel.add( professorPanel );
studentCourseProfessorExam Panel = new JPanel();
studentCourseProfessorExam Panel.setL ayout( new GridLayout(3,1) );
studentCourseProfessorExam Panel.add( StudentProfessorPanel );
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam Panel.add( coursePanel );
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam Panel.add( examPanel );
c.add( studentCourseProfessorExam Panel, BorderLayout.CENTER ) ;
controlPanel = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controlPanel, BorderLayout.NORTH );
c.add( output, BorderLayout.SOUTH );
pack();
show();
}
public class ControlPanel extends JPanel
{
private JButton findCourse,findExam, addData, updateData, refresh, help;
private CoursePanel coursePanel;
private ExamPanel examPanel;
private ProfessorPanel professorPanel;
private StudentPanel studentPanel;
/** Creates a new instance of ControlPanel */
public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
ProfessorPanel professorPanel, StudentPanel studentPanel)
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT
// setBorder(new CompoundBorder(
// BorderFactory.createLineBo
// BorderFactory.createBevelB
this.coursePanel = coursePanel;
this.examPanel = examPanel;
this.studentPanel = studentPanel;
this.professorPanel = professorPanel;
System.out.println("before
/**================= refresh the GUI ==========================
refresh = new JButton("Refresh",
new ImageIcon( getClass().getResource("im
refresh.setMnemonic('R');
refresh.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven
{
refreshGUI();
}
}
);
add(refresh);
System.out.println("before
/**================= find courses ==========================
findCourse = new JButton( "Get Courses",
new ImageIcon(getClass().getRe
findCourse.setMnemonic('C'
//add actionListner later
findCourse.addActionListen
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if(findCourse == e.getSource() )
displayCourseTable();
}
}
);
add( findCourse );
System.out.println("before
/**================= find Exams ==========================
findExam = new JButton( "Get Exams",
new ImageIcon(getClass().getRe
findExam.setMnemonic('E');
/**add actionListner */
findExam.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( findExam == e.getSource() )
displayExamTable();
}
}
);
add(findExam);
System.out.println("before
/**================= add new Student ==========================
addData = new JButton( "Add New Student",
new ImageIcon(getClass().getRe
//add actionListner later
//addData.addActionListene
add( addData );
addData.setMnemonic('S');
/**================= update Student info ==========================
updateData = new JButton( "Save",
new ImageIcon(getClass().getRe
//add actionListner later
add(updateData);
updateData.setMnemonic('s'
help = new JButton( "Help",
new ImageIcon(getClass().getRe
//add actionListner later
add(help);
help.setMnemonic('H');
displayCourseTable();
displayExamTable();
}
private void displayCourseTable()
{
coursePanel.populateCourse
}
private void displayExamTable()
{
examPanel.populateExamTabl
}
private void refreshGUI()
{
studentPanel.clearSutdentP
professorPanel.clearProfes
coursePanel.initCourseTabl
examPanel.initExamsTable()
studentPanel.refreshCombo(
}
}
===========StudentSupportS
public StudentSupportServices( )
{
super("Student Support Services");
if (!startApplication() ) System.exit(0);
c = getContentPane();
c.setLayout( new BorderLayout() );
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new RenewDatabase());
menuBar.add( fileMenu );
setJMenuBar(menuBar);
output = new JTextArea();
output.setEditable(false);
setDefaultCloseOperation( EXIT_ON_CLOSE );
try
{
//Connect to ess database.
url = "jdbc:odbc:Driver={Microso
"C:/accessDb/Students.mdb"
Class.forName("sun.jdbc.od
accessCon = DriverManager.getConnectio
output.append("Connection successful\n");
}
catch( SQLException sqlex )
{
//process SQLException
sqlex.printStackTrace();
output.append("Connection Uncessful\n" + sqlex.toString() );
}
catch( Exception ex )
{
//process remaining Exception here
ex.printStackTrace();
output.append( ex.toString() );
}
studentPanel = new StudentPanel( accessCon );
professorPanel = new ProfessorPanel();
JPanel StudentProfessorPanel = new JPanel();
StudentProfessorPanel.setL
StudentProfessorPanel.add(
StudentProfessorPanel.add(
studentCourseProfessorExam
studentCourseProfessorExam
studentCourseProfessorExam
coursePanel = new CoursePanel(this, studentPanel, accessCon);
studentCourseProfessorExam
examPanel = new ExamPanel(this, coursePanel, accessCon);
studentCourseProfessorExam
c.add( studentCourseProfessorExam
controlPanel = new ControlPanel(coursePanel, examPanel,
professorPanel, studentPanel);
c.add( controlPanel, BorderLayout.NORTH );
c.add( output, BorderLayout.SOUTH );
pack();
show();
}
ASKER
Good point from pkwan,
although that did not solve my entire problem that was the solution that solve the StackOverFlowError problem.
I appreciate that. Thanks
ASKER
CAN THE ADMINISTRATOR OF THIS PAGE DELETE THIS QUESTION. TOO LONG
the stack trace should give you a good clue where it is occurring