📄 facultybooklist_main.java
字号:
/**
* Main screen/program, using MDI method
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class FacultyBookList_Main extends JFrame implements ActionListener,
InternalFrameListener {
//-------------------------------------------- FacultyBookList Constructor
public FacultyBookList_Main() {
//<!-- INIT_MENUS - For File Menu
jmnuFile.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuFile.setText("File");
jmnuFile.setActionCommand("File");
jmnuFile.setBorderPainted(false);
jmnuFile.setMnemonic((int)'F');
jmnuMain.add(jmnuFile);
jmnuiNew.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiNew.setText("New");
jmnuiNew.setActionCommand("New");
jmnuiNew.setBorderPainted(false);
jmnuiNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
jmnuiNew.setMnemonic((int)'N');
jmnuFile.add(jmnuiNew);
jmnuiSave.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiSave.setText("Save");
jmnuiSave.setActionCommand("Save");
jmnuiSave.setBorderPainted(false);
jmnuiSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
jmnuiSave.setMnemonic((int)'S');
jmnuFile.add(jmnuiSave);
jmnuFile.addSeparator();
jmnuiDelete.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiDelete.setText("Delete");
jmnuiDelete.setActionCommand("Delete");
jmnuiDelete.setBorderPainted(false);
jmnuiDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
jmnuiDelete.setMnemonic((int)'D');
jmnuFile.add(jmnuiDelete);
jmnuiCancel.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiCancel.setText("Cancel");
jmnuiCancel.setActionCommand("Cancel");
jmnuiCancel.setBorderPainted(false);
jmnuiCancel.setMnemonic((int)'A');
jmnuFile.add(jmnuiCancel);
jmnuFile.addSeparator();
jmnuiExit.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiExit.setText("Exit");
jmnuiExit.setActionCommand("Exit");
jmnuiExit.setBorderPainted(false);
jmnuiExit.setMnemonic((int)'X');
jmnuFile.add(jmnuiExit);
// For Edit Menu
jmnuEdit.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuEdit.setText("Edit");
jmnuEdit.setActionCommand("Edit");
jmnuEdit.setBorderPainted(false);
jmnuEdit.setMnemonic((int)'E');
jmnuMain.add(jmnuEdit);
jmnuiFind.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiFind.setText("Find");
jmnuiFind.setActionCommand("Find");
jmnuiFind.setBorderPainted(false);
jmnuiFind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
jmnuiFind.setMnemonic((int)'F');
jmnuEdit.add(jmnuiFind);
// For View Menu
jmnuView.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuView.setText("View");
jmnuView.setActionCommand("View");
jmnuView.setBorderPainted(false);
jmnuView.setMnemonic((int)'V');
jmnuMain.add(jmnuView);
jmnuiFB.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiFB.setText("Faculty Books Details");
jmnuiFB.setActionCommand("Faculty Books Details");
jmnuiFB.setBorderPainted(false);
jmnuiFB.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, Event.CTRL_MASK));
jmnuiFB.setMnemonic((int)'U');
jmnuView.add(jmnuiFB);
jmnuiBooks.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiBooks.setText("Book Details");
jmnuiBooks.setActionCommand("Book Details");
jmnuiBooks.setBorderPainted(false);
jmnuiBooks.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK));
jmnuiBooks.setMnemonic((int)'B');
jmnuView.add(jmnuiBooks);
jmnuiCourses.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiCourses.setText("Course Details");
jmnuiCourses.setActionCommand("Course Details");
jmnuiCourses.setBorderPainted(false);
jmnuiCourses.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
jmnuiCourses.setMnemonic((int)'O');
jmnuView.add(jmnuiCourses);
jmnuView.addSeparator();
jmnuiFBL.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiFBL.setText("Faculty Books List");
jmnuiFBL.setActionCommand("Faculty Books List");
jmnuiFBL.setBorderPainted(false);
jmnuiFBL.setMnemonic((int)'L');
jmnuView.add(jmnuiFBL);
jmnuView.addSeparator();
jmnuiBack.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiBack.setText("Back");
jmnuiBack.setActionCommand("Back");
jmnuiBack.setBorderPainted(false);
jmnuiBack.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
jmnuiBack.setMnemonic((int)'k');
jmnuView.add(jmnuiBack);
jmnuiNext.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiNext.setText("Next");
jmnuiNext.setActionCommand("Next");
jmnuiNext.setBorderPainted(false);
jmnuiNext.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK));
jmnuiNext.setMnemonic((int)'t');
jmnuView.add(jmnuiNext);
// For Help Menu
jmnuHelp.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuHelp.setText("Help");
jmnuHelp.setActionCommand("Help");
jmnuHelp.setBorderPainted(false);
jmnuHelp.setMnemonic((int)'H');
jmnuMain.add(jmnuHelp);
jmnuiAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
jmnuiAbout.setText("About...");
jmnuiAbout.setActionCommand("About...");
jmnuiAbout.setBorderPainted(false);
jmnuiAbout.setMnemonic((int)'A');
jmnuHelp.add(jmnuiAbout);
//-->
//<!-- INIT_TOOLBARS
jbtnNew.setToolTipText("Create new record");
jbtnSave.setToolTipText("Save the change(s)");
jbtnDelete.setToolTipText("Delete this record");
jbtnCancel.setToolTipText("Cancel the change(s) and/or close");
jbtnFind.setToolTipText("Find");
jbtnFB.setToolTipText("Faculty books details");
jbtnBooks.setToolTipText("Book details");
jbtnCourses.setToolTipText("Course details");
jbtnFBL.setToolTipText("View faculty books list");
jbtnBack.setToolTipText("Show previous record");
jbtnNext.setToolTipText("Show next record");
jtbrMain.add(jbtnNew);
jtbrMain.add(jbtnSave);
jtbrMain.addSeparator();
jtbrMain.add(jbtnDelete);
jtbrMain.add(jbtnCancel);
jtbrMain.addSeparator();
jtbrMain.add(jbtnFB);
jtbrMain.add(jbtnBooks);
jtbrMain.add(jbtnCourses);
jtbrMain.add(jbtnFBL);
jtbrMain.addSeparator();
jtbrMain.add(jbtnFind);
jtbrMain.add(jbtnBack);
jtbrMain.add(jbtnNext);
//-->
//<!-- REGISTER_LISTENERS
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
mtd_exitApplication();
}
});
// For Menu Listeners
jmnuiNew.addActionListener(this);
jmnuiSave.addActionListener(this);
jmnuiDelete.addActionListener(this);
jmnuiCancel.addActionListener(this);
jmnuiExit.addActionListener(this);
jmnuiFind.addActionListener(this);
jmnuiFB.addActionListener(this);
jmnuiBooks.addActionListener(this);
jmnuiCourses.addActionListener(this);
jmnuiFBL.addActionListener(this);
jmnuiBack.addActionListener(this);
jmnuiNext.addActionListener(this);
jmnuiAbout.addActionListener(this);
// For Toolbars Listeners
jbtnNew.addActionListener(this);
jbtnSave.addActionListener(this);
jbtnDelete.addActionListener(this);
jbtnCancel.addActionListener(this);
jbtnFind.addActionListener(this);
jbtnFB.addActionListener(this);
jbtnBooks.addActionListener(this);
jbtnCourses.addActionListener(this);
jbtnFBL.addActionListener(this);
jbtnBack.addActionListener(this);
jbtnNext.addActionListener(this);
//-->
//<!-- INIT_CONTROLS
setSize(600,500);
setVisible(false);
setResizable(false);
setJMenuBar(jmnuMain);
setTitle("USQ Faculty Book List");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// Made the screen appear center
setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth())/2,
(Toolkit.getDefaultToolkit().getScreenSize().height - getHeight())/2);
// Show time at the status bar (JLabel)
jlblStatusBar.setHorizontalAlignment(SwingConstants.RIGHT);
jlblStatusBar.setForeground(Color.black);
jlblStatusBar.setFont(new Font("Dialog", Font.PLAIN, 10));
new clsTimerTime(jlblStatusBar, 1);
// When you drag a internal frame you will only see the outline
// and it doesnt repaint until you stop dragging this makes dragging faster.
jdpDesktop.putClientProperty("JDesktopPane.dragMode", "outline");
getContentPane().add(jtbrMain, BorderLayout.NORTH);
getContentPane().add(jdpDesktop, BorderLayout.CENTER);
getContentPane().add(jlblStatusBar, BorderLayout.SOUTH);
// Load data from text file into array(s)
objFileHdl = new clsFileHdl();
arrBook = objFileHdl.mtd_BookFile();
arrCourse = objFileHdl.mtd_CourseFile();
arrFaculty = objFileHdl.mtd_FacultyBookFile();
//-->
}
//-------------------------------------------- FacultyBookList Action performer
private void mtd_exitApplication() {
try {
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(this,
"Do you really want to exit?",
"USQ Faculty Book List - Exit" ,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION) {
// Make sure all array have the latest copy
mtd_JInternalFrame("");
// Write Array into text file
objFileHdl.mtd_BookFile(arrBook);
objFileHdl.mtd_CourseFile(arrCourse);
objFileHdl.mtd_FacultyBookFile(arrFaculty);
setVisible(false); // hide the Frame
dispose(); // free the system resources
System.exit(0); // close the application
}
} catch(Exception e) {}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -