📄 main.java
字号:
import javax.swing.*;import javax.swing.event.*;import java.awt.event.*;import java.awt.*;import java.awt.print.*;import java.io.*;public class main extends JFrame implements mainInterface, InternalFrameListener{ splash_frame splash = new splash_frame(); public main() { super("main"); splash(); int inset = 0; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize((screenSize.width-100), (screenSize.height-100)); //setBounds(inset, inset, // screenSize.width, // screenSize.height - 30); setIconImage(getToolkit().getImage("icon.jpg")); //Quit this app when the big window closes. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); /* //to enable the enter key UIManager.getDefaults().put("Button.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "ENTER", "pressed", "released ENTER", "released" }));*/ setContentPane(desktop); USERName.setFont (new Font ("Impact", Font.PLAIN, 16)); USERName.setForeground(Color.black); USERName.setBounds(250,0,600,50); desktop.add(USERName); add.setEnabled(false); setJMenuBar(createMenuBar()); int paintx = (screenSize.width); int painty = (screenSize.height); logo.setIcon( accLogo ); logo.setBounds( (paintx - 800)/2 , ((painty-100) - 500)/2, 800,600); desktop.add(logo); desktop.setBackground(Color.gray); } public void getPassword() { desktop.add( app ); try { app.setSelected( true ); } catch( java.beans.PropertyVetoException pvex ) { } } protected JMenuBar createMenuBar() { menu.setMnemonic(KeyEvent.VK_F); add.setMnemonic(KeyEvent.VK_L); rtn.setMnemonic(KeyEvent.VK_W); report.setMnemonic(KeyEvent.VK_R); help.setMnemonic(KeyEvent.VK_H); //items for help menuItemhelp1.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F1, ActionEvent.CTRL_MASK)); menuItemhelp1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "\n1. To Add a record, fill in all the fields and click on Add." + "\n\n2. To Update A Record, Search for the record first and click on Save." + "\n\n3. To Delete A Record, Search for the record and click Delete." + "\n\n4. To Clear Fields, click on Clear." + "\n\n5. To Exit this module, click on Close." + "\n\n6. To View the report, click on report." + "\n\n7. To change the Skin, selected skin under window menu. " + "\n\n8. For More help Please Contact us at dh002211@ex.apiit.edu.my."); } }); menuItemhelp2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createSplash(); } }); menuItemhelp3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { aboutUs aboutus = new aboutUs(); aboutus.setVisible(true); desktop.add(aboutus); try { aboutus.setSelected(true); } catch (java.beans.PropertyVetoException ex) {} } }); //items for file menuItem3.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_L, ActionEvent.CTRL_MASK)); menuItem3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { app.show(); } }); menuItem3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getPassword(); } }); menuItem6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int confirm = JOptionPane.showConfirmDialog(null, "Are you sure want to Log Out?", "Log Out", JOptionPane.YES_NO_OPTION); if( confirm == JOptionPane.YES_OPTION ) { add.setEnabled(false); menuItem6.setEnabled(false); menuItem3.setEnabled(true); USERName.setText("Welcome Lecturer/Student,if you are a member please login"); } } }); menuItem5.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int confirm = JOptionPane.showConfirmDialog(null, "Are you sure want to exit?", "Exit Application", JOptionPane.YES_NO_OPTION); if( confirm == JOptionPane.YES_OPTION ) { JOptionPane.showMessageDialog( null, "Thanks for using our System"); dispose(); System.exit(0); } } }); //items for return returnItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { desktop.getSelectedFrame().setClosed(true); } catch (java.beans.PropertyVetoException pve) {} } }); returnItem2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JInternalFrame Frames[] = desktop.getAllFrames(); // get all open frames for(int FrameLoop=0; FrameLoop < Frames.length; FrameLoop++) { try { Frames[FrameLoop].setClosed(true); // close the frame } catch (Exception CloseExc) { // if we can't close it then we have a problem JOptionPane.showMessageDialog(null, CloseExc); } } } }); //items for library bk_mast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createBookMaster(); } }); bk_loan.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createBookLoan(); } }); bk_ret.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createFrame3(); } }); j_master.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createJournal(); } }); j_loan.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createBookLoan(); } }); j_ret.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createFrame3(); } }); v_master.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createVideo(); } }); v_loan.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createBookLoan(); } }); v_ret.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createFrame3(); } }); pt_mast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add.setEnabled(false); createFrame2(); } }); //items for report reportItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { patronReport rep = new patronReport(); } }); reportItem2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { bookReport rep = new bookReport(); //reateReport(); } }); ItemHandler handler = new ItemHandler(); for( int i = 0; i < radio.length ; i++ ) { radio[i] = new JRadioButtonMenuItem( strings[i] ); radio[i].setMnemonic( mne[i] ); radio[i].addItemListener( handler ); group.add( radio[i] ); returnItem3.add( radio[i] ); } returnItem4.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { Color color = new Color( 86,1,46 ); color = JColorChooser.showDialog( main.this, "Choose background color", color ); if( color == null )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -