📄 mainwindow.java
字号:
package labraryManager;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class MainWindow extends JFrame implements ActionListener{
public static final int WIDTH=500;
public static final int HEIGHT=400;
public static String lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
public MainWindow(){
setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowDestroyer());
setTitle("图书管理系统");
Container x=getContentPane();
x.setLayout(new BorderLayout());
JPanel jp=new JPanel();
jp.setLayout(new BorderLayout());
JLabel j=new JLabel();
ImageIcon i=new ImageIcon("D:\\workspace\\LabraryManageSystem\\labraryManager\\leaves.jpg");
j.setIcon(i);
JLabel z=new JLabel("图书管理系统");
Font a=new Font("隶书",Font.PLAIN,50);
z.setFont(a);
z.setBorder(new EmptyBorder(10,100,10,10));
jp.add(z,BorderLayout.NORTH);
jp.add(j,BorderLayout.SOUTH);
x.add(jp,BorderLayout.CENTER);
JPanel y=new JPanel();
y.setLayout(new FlowLayout());
JButton b1=new JButton("图书查询");
b1.addActionListener(this);
y.add(b1);
JButton b2=new JButton("图书流通");
b2.addActionListener(this);
y.add(b2);
JButton b3=new JButton("系统操作");
b3.addActionListener(this);
y.add(b3);
JButton b4=new JButton("帮助");
b4.addActionListener(this);
y.add(b4);
JButton b5=new JButton("退出");
b5.addActionListener(this);
y.add(b5);
x.add(y,BorderLayout.SOUTH);
setLnf(lnfName);
}
private void setLnf(String lnfName)
{
try
{
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(this);
}
catch(UnsupportedLookAndFeelException ex1)
{
System.err.println("UnsupportLookAndFeel" + lnfName);
}
catch(ClassNotFoundException ex2)
{
System.err.println("ClassNotFound: " + lnfName);
}
catch(InstantiationException ex3)
{
System.err.println("InstantiationException" + lnfName);
}
catch(IllegalAccessException ex4)
{
System.err.println("IllegalAccessException" + lnfName);
}
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("图书查询"))
{
CheckWindow manager=new CheckWindow();
manager.setVisible(true);
dispose();
}
else if(e.getActionCommand().equals("图书流通"))
{
if(Main.entered==false){
ManagerWindow x=new ManagerWindow("图书流通");
x.setVisible(true);
dispose();
}
else{
CirculateWindow manager=new CirculateWindow();
manager.setVisible(true);
dispose();
}
}
else if(e.getActionCommand().equals("系统操作"))
{
if(Main.entered==false){
ManagerWindow x=new ManagerWindow("系统操作");
x.setVisible(true);
dispose();}
else{
SystemManageWindow x=new SystemManageWindow();
x.setVisible(true);
dispose();
}
}
else if(e.getActionCommand().equals("帮助"))
{
JOptionPane.showMessageDialog(null, "当前版本1.0,运行本系统时请勿在系统外对数据库进行操作,否则后果自负");
}
else if(e.getActionCommand().equals("退出"))
{
ConfirmWindow x=new ConfirmWindow();
x.setVisible(true);
}
else
System.out.println("Error!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -