📄 facultybooklist_main.java
字号:
}
// Make sure there is a selected JInternalFrame & compare which
// JInternalFrame is selected & perform action accordingly
private void mtd_doSelectedFrame(int intEvent) {
String strFrameTitle;
if(jdpDesktop.getSelectedFrame() != null) {
strFrameTitle = jdpDesktop.getSelectedFrame().getTitle();
if(strFrameTitle.equalsIgnoreCase("Faculty Books Details"))
mtd_jfrmFacultyBook(intEvent);
else if(strFrameTitle.equalsIgnoreCase("Book Details"))
mtd_jfrmBook(intEvent);
else if(strFrameTitle.equalsIgnoreCase("Course Details"))
mtd_jfrmCourse(intEvent);
}
}
private void mtd_jfrmFacultyBook(int intEvent) {
switch(intEvent) {
case 0: // New event
objFacultyBook.mtd_New(); break;
case 1: // Save event
objFacultyBook.mtd_Save(); break;
case 2: // Delete event
objFacultyBook.mtd_Delete(); break;
case 3: // Cancel event
objFacultyBook.setVisible(false);
arrFaculty = objFacultyBook.mtd_getarrFacultyBook();
objFacultyBook.dispose(); break;
case 4: // Find event
int intPosition = -1;
arrFaculty = objFacultyBook.mtd_getarrFacultyBook();
jfrmFind objFind = new jfrmFind(this, true, arrFaculty, true);
objFind.show();
intPosition = objFind.mtd_getPosition();
objFind.dispose();
objFacultyBook.mtd_Search(intPosition);
break;
case 5: // Back event
objFacultyBook.mtd_Navigation(-1); break;
case 6: // Next event
objFacultyBook.mtd_Navigation(1); break;
}
}
private void mtd_jfrmBook(int intEvent) {
switch(intEvent) {
case 0: // New event
objBook.mtd_New(); break;
case 1: // Save event
objBook.mtd_Save(); break;
case 2: // Delete event
objBook.mtd_Delete(); break;
case 3: // Cancel event
objBook.setVisible(false); // Get the frame invisible
arrBook = objBook.mtd_getarrBook(); // Get latest Array frm class
objBook.dispose(); break; // release system resources
case 4: // Find event
int intPosition = -1;
arrBook = objBook.mtd_getarrBook(); // Get latest Array frm class
jfrmFind objFind = new jfrmFind(this, true, arrBook);
objFind.show(); // Show the Find frame
intPosition = objFind.mtd_getPosition(); // Get the position of data
objFind.dispose(); // release system resources
objBook.mtd_Search(intPosition); break; // Reflecting the find
case 5: // Back event
objBook.mtd_Navigation(-1); break;
case 6: // Next event
objBook.mtd_Navigation(1); break;
}
}
private void mtd_jfrmCourse(int intEvent) {
switch(intEvent) {
case 0: // New event
objCourse.mtd_New(); break;
case 1: // Save event
objCourse.mtd_Save(); break;
case 2: // Delete event
objCourse.mtd_Delete(); break;
case 3: // Cancel event
objCourse.setVisible(false); // Get the frame invisible
arrCourse = objCourse.mtd_getarrCourse(); // Get latest Array frm class
objCourse.dispose(); break; // release system resources
case 4: // Find event
int intPosition = -1;
arrCourse = objCourse.mtd_getarrCourse(); // Get latest Array frm class
jfrmFind objFind = new jfrmFind(this, true, arrCourse);
objFind.show(); // Show the Find frame
intPosition = objFind.mtd_getPosition(); // Get the position of data
objFind.dispose(); // release system resources
objCourse.mtd_Search(intPosition); // Reflecting the find
break;
case 5: // Back event
objCourse.mtd_Navigation(-1); break;
case 6: // Next event
objCourse.mtd_Navigation(1); break;
}
}
// Loop through all the opened JInternalFrame and perform required tasks
private boolean mtd_JInternalFrame(String strTitle) {
JInternalFrame[] jifChild = jdpDesktop.getAllFrames();
for(int i=0; i < jifChild.length; i++) {
if(strTitle.length() < 1) {
// Make sure the array have latest copy from the respective class
if(jifChild[i].getTitle().equalsIgnoreCase("Course Details"))
arrCourse = objCourse.mtd_getarrCourse();
else if(jifChild[i].getTitle().equalsIgnoreCase("Book Details"))
arrBook = objBook.mtd_getarrBook();
else if(jifChild[i].getTitle().equalsIgnoreCase("Faculty Books Details"))
arrFaculty = objFacultyBook.mtd_getarrFacultyBook();
} else if(jifChild[i].getTitle().equalsIgnoreCase(strTitle)) {
// Check whether the JInterFrame is already open,
// if yes, brings it to the front instead open.
jifChild[i].show();
return true;
}
}
return false;
}
// For opening JInternalFrame
private void jmnuiOpen_actionPerformed(ActionEvent event, String strTitle, int intWhich) {
if(mtd_JInternalFrame(strTitle)) return;
// Check which frame want to open
switch(intWhich) {
case 0: // Faculty Books Details frame
mtd_JInternalFrame(""); // Get the latest array
objFacultyBook = new jfrmFacultyBook(strTitle, arrFaculty,
arrBook, arrCourse);
jdpDesktop.add(objFacultyBook);
objFacultyBook.addInternalFrameListener(this); // Listen for events
objFacultyBook.setVisible(true);
break;
case 1: // Book Details frame
objBook = new jfrmBook(strTitle, arrBook);
jdpDesktop.add(objBook);
objBook.addInternalFrameListener(this); // Listen for events
objBook.setVisible(true);
break;
case 2: // Course Details frame
objCourse = new jfrmCourse(strTitle, arrCourse);
jdpDesktop.add(objCourse);
objCourse.addInternalFrameListener(this); // Listen for events
objCourse.setVisible(true);
break;
case 3: // Faculty Books List
mtd_JInternalFrame(""); // Get the latest array
objFacultyBookList = new jfrmFacultyBookList(strTitle, arrBook,
arrCourse, arrFaculty);
jdpDesktop.add(objFacultyBookList);
objFacultyBookList.addInternalFrameListener(this);
objFacultyBookList.setVisible(true);
break;
case 4: // About box...
objAbout = new jfrmAbout(this); objAbout.setVisible(true);
break;
}
}
//-------------------------------------------- FacultyBookList Listener
public void actionPerformed(ActionEvent event) {
Object object = event.getSource();
// For Menu/Toolbar Action listener
if(object == jmnuiNew || object == jbtnNew) mtd_doSelectedFrame(0);
else if(object == jmnuiSave || object == jbtnSave) mtd_doSelectedFrame(1);
else if(object == jmnuiDelete || object == jbtnDelete) mtd_doSelectedFrame(2);
else if(object == jmnuiCancel || object == jbtnCancel) mtd_doSelectedFrame(3);
else if(object == jmnuiFind || object == jbtnFind) mtd_doSelectedFrame(4);
else if(object == jmnuiBack || object == jbtnBack) mtd_doSelectedFrame(5);
else if(object == jmnuiNext || object == jbtnNext) mtd_doSelectedFrame(6);
else if(object == jmnuiFB || object == jbtnFB)
jmnuiOpen_actionPerformed(event, "Faculty Books Details", 0);
else if(object == jmnuiBooks || object == jbtnBooks)
jmnuiOpen_actionPerformed(event, "Book Details", 1);
else if(object == jmnuiCourses || object == jbtnCourses)
jmnuiOpen_actionPerformed(event, "Course Details", 2);
else if(object == jmnuiFBL || object == jbtnFBL)
jmnuiOpen_actionPerformed(event, "Faculty Books List", 3);
else if(object == jmnuiAbout)
jmnuiOpen_actionPerformed(event, "About", 4);
else if(object == jmnuiExit) mtd_exitApplication();
}
// For JInternalFrameListener
public void internalFrameClosing(InternalFrameEvent e) {
Object object = e.getSource();
if(object == objFacultyBook)
mtd_jfrmFacultyBook(3);
else if(object == objBook)
mtd_jfrmBook(3);
else if(object == objCourse)
mtd_jfrmCourse(3);
}
// Empty method required by InternalFrameListener
public void internalFrameClosed(InternalFrameEvent e) { }
public void internalFrameOpened(InternalFrameEvent e) { }
public void internalFrameIconified(InternalFrameEvent e) { }
public void internalFrameDeiconified(InternalFrameEvent e) { }
public void internalFrameActivated(InternalFrameEvent e) { }
public void internalFrameDeactivated(InternalFrameEvent e) { }
//-------------------------------------------- FacultyBookList Main
public static void main(String[] args) {
try {
// Create a "Splash Screen" and make it visible while wait for program to load
jfrmSplashScreen objSplash = new jfrmSplashScreen("images/FacultyBookList.jpg");
objSplash.setVisible(true);
// Create a new instance of our application's frame, and make it visible.
FacultyBookList_Main objMain = new FacultyBookList_Main();
for(int i=0; i< 200; i++) System.out.println("loading...");
objSplash.mtd_Close();
objMain.setVisible(true);
} catch(Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
//<!-- DECLARE_CONTROLS/VARIABLES
private jfrmBook objBook;
private jfrmAbout objAbout;
private jfrmCourse objCourse;
private jfrmFacultyBook objFacultyBook;
private jfrmFacultyBookList objFacultyBookList;
private clsFileHdl objFileHdl;
private clsBookListEntry[] arrBook, arrCourse, arrFaculty;
private JLabel jlblStatusBar = new JLabel();
private JDesktopPane jdpDesktop = new JDesktopPane();
//-->
//<!-- DECLARE_MENUS
private JMenuBar jmnuMain = new JMenuBar();
private JMenu jmnuFile = new JMenu();
private JMenuItem jmnuiNew = new JMenuItem();
private JMenuItem jmnuiSave = new JMenuItem();
private JMenuItem jmnuiDelete = new JMenuItem();
private JMenuItem jmnuiCancel = new JMenuItem();
private JMenuItem jmnuiExit = new JMenuItem();
private JMenu jmnuEdit = new JMenu();
private JMenuItem jmnuiFind = new JMenuItem();
private JMenu jmnuView = new JMenu();
private JMenuItem jmnuiFB = new JMenuItem();
private JMenuItem jmnuiBooks = new JMenuItem();
private JMenuItem jmnuiCourses = new JMenuItem();
private JMenuItem jmnuiFBL = new JMenuItem();
private JMenuItem jmnuiBack = new JMenuItem();
private JMenuItem jmnuiNext = new JMenuItem();
private JMenu jmnuHelp = new JMenu();
private JMenuItem jmnuiAbout = new JMenuItem();
//-->
//<!-- DECLARE_BUTTONS - For Toolbar
private JToolBar jtbrMain = new JToolBar();
private JButton jbtnNew = new JButton(new ImageIcon("images/new.gif"));
private JButton jbtnSave = new JButton(new ImageIcon("images/save.gif"));
private JButton jbtnDelete = new JButton(new ImageIcon("images/delete.gif"));
private JButton jbtnCancel = new JButton(new ImageIcon("images/cancel.gif"));
private JButton jbtnFB = new JButton(new ImageIcon("images/fb.gif"));
private JButton jbtnBooks = new JButton(new ImageIcon("images/books.gif"));
private JButton jbtnCourses = new JButton(new ImageIcon("images/courses.gif"));
private JButton jbtnFBL = new JButton(new ImageIcon("images/fbl.gif"));
private JButton jbtnFind = new JButton(new ImageIcon("images/find.gif"));
private JButton jbtnBack = new JButton(new ImageIcon("images/back.gif"));
private JButton jbtnNext = new JButton(new ImageIcon("images/next.gif"));
//-->
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -