库的表结构,如图1.19所示。
(点击查看大图)图1.19 查询分析器运行效果 1.5 主窗体设计
主窗体界面也是该系统的欢迎界面。应用程序的主窗体必须设计层次清晰的系统菜单和工具栏,其中系统菜单包含系统中所有功能的菜单项,而工具栏主要提供常用功能的快捷访问按钮。企业进销存管理系统采用导航面板,综合了系统菜单和工具栏的优点,而且其界面更加美观,操作更快捷。主窗体的运行效果如图1.20所示。
(点击查看大图)图1.20 程序主窗体界面效果 1.5.1 创建主窗体 创建主窗体的步骤如下:
(1)创建JXCFrame类,在类中创建并初始化窗体对象,为窗体添加桌面面板,并设置背景图片。关键代码如下:
例程01 代码位置:光盘\\TM\\01\\JXCManager\\src\\com\\lzw\\JXCFrame.java
1. 2. 3. 4. 5. 6.
private JDesktopPane desktopPane; private JFrame frame; private JLabel backLabel;
private Preferences preferences; //创建窗体的Map类型集合对象
private Map
public JXCFrame() {
frame = new JFrame(\企业进销存管理系统\//创建窗体对象
frame.addComponentListener(new FrameListener()); //添加窗体事件监听器
10. frame.getContentPane().setLayout(new BorderLayout());
//设置布局管理器
11. frame.setBounds(100, 100, 800, 600);
//设置窗体位置和大小
12. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置窗体默认的关闭方式
13. backLabel = new JLabel();
//背景标签
14. backLabel.setVerticalAlignment(SwingConstants.TOP);
//设置背景标签垂直对齐方式
15. backLabel.setHorizontalAlignment(SwingConstants.CENTER);
//设置背景标签水平对齐方式
16. updateBackImage();
//调用初始化背景标签的方法
17. desktopPane = new JDesktopPane();
//创建桌面面板
18. desktopPane.add(backLabel, new Integer(Integer.MIN_VALUE));
//将背景标签添加到桌面面板中
19. frame.getContentPane().add(desktopPane);
//添加桌面面板到窗体中
20. JTabbedPane navigationPanel = createNavigationPanel();
//创建导航面板
21. frame.getContentPane().add(navigationPanel, BorderLayout.NORTH);
//添加导航面板到窗体中
22. frame.setVisible(true);
//显示窗体 23. }
(2)编写updateBackImage()方法,在该方法中初始化背景标签,背景标签使用HTML超文本语言设置了主窗体的背景图片,该图片将随主窗体的大小自动缩放。关键代码如下: 例程02 代码位置:光盘\\TM\\01\\JXCManager\\src\\com\\lzw\\JXCFrame.java
1. 2. 3. 4. 5. 6. 7. 8. 9.
private void updateBackImage() { if (backLabel != null) {
int backw = JXCFrame.this.frame.getWidth(); int backh = frame.getHeight();
backLabel.setSize(backw, backh); //初始化背景标签的大小
backLabel.setText(\
+ JXCFrame.this.getClass().getResource(\)
+ \>\//设置背景标签的图像 10. } 11. }
(3)在类的静态代码段中设置进销存管理系统的外观样式。Swing支持跨平台特性,它可以在不同的操作系统中保持一致的外观风格,但是本系统使用UIManager类的setLookAndFeel()方法设置程序界面使用本地外观,这样可以使程序更像本地应用程序。关键代码如下:
例程03 代码位置:光盘\\TM\\01\\JXCManager\\src\\com\\lzw\\JXCFrame.java
1. 2. 3. 4. 5. 6. 7.
static { try {
UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } }
(4)编写主窗体的main()入口方法,在该方法中创建登录窗体对象,登录窗体会验证登录信息,并显示主窗体界面。关键代码如下:
例程04 代码位置:光盘\\TM\\01\\JXCManager\\src\\com\\lzw\\JXCFrame.java
1. 2. 3. 4. 5. 6. 7.
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { public void run() { new Login(); } }); }
1.5.2 创建导航面板(1) 创建导航面板的步骤如下:
(1)在JXCFrame类中编写createNavigationPanel()方法,在该方法中创建JTabbedPane选项卡面板对象;为突出选项卡的立体效果,设置其使用BevelBorder边框效果;然后依次创建\基础信息管理\、\库存管理\、\销售管理\、\查询统计\、\进货管理\和\系统管理\选项卡。关键代码如下: 例程05 代码位置:光盘\\TM\\01\\JXCManager\\src\\com\\lzw\\JXCFrame.java
1. 2. 3. 4. 5. 6. 7. 8. 9.
private JTabbedPane createNavigationPanel() { //创建导航面板的方法 JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setFocusable(false);
tabbedPane.setBackground(new Color(211, 230, 192));
tabbedPane.setBorder(new BevelBorder(BevelBorder.RAISED)); JPanel baseManagePanel = new JPanel(); //“基础信息管理”面板
baseManagePanel.setBackground(new Color(215, 223, 194)); baseManagePanel.setLayout(new BoxLayout (baseManagePanel, BoxLayout.X_AXIS));
baseManagePanel.add(createFrameButton(\客户信息管理\\
10. baseManagePanel.add(createFrameButton(\商品信息管理\
\
11. baseManagePanel.add(createFrameButton(\供应商信息管理\
\
12. JPanel depotManagePanel = new JPanel();
//“库存管理”面板
13. depotManagePanel.setBackground(new Color(215, 223, 194)); 14. depotManagePanel.setLayout(new BoxLayout
(depotManagePanel, BoxLayout.X_AXIS));
15. depotManagePanel.add(createFrameButton(\库存盘点\
\
16. depotManagePanel.add(createFrameButton(\价格调整\
\
17. JPanel sellManagePanel = new JPanel();
//“销售管理”面板
18. sellManagePanel.setBackground(new Color(215, 223, 194)); 19. sellManagePanel.setLayout(new BoxLayout
(sellManagePanel, BoxLayout.X_AXIS));
20. sellManagePanel.add(createFrameButton(\销售单\
\
21. sellManagePanel.add(createFrameButton(\销售退货\
\
22. JPanel searchStatisticPanel = new JPanel();
//“查询统计”面板
23. searchStatisticPanel.setBounds(0, 0, 600, 41);
24. searchStatisticPanel.setName(\
25. searchStatisticPanel.setBackground(new Color(215, 223, 194)); 26. searchStatisticPanel.setLayout(new BoxLayout
(searchStatisticPanel, BoxLayout.X_AXIS)); 27. searchStatisticPanel.add(createFrameButton
(\客户信息查询\
28. searchStatisticPanel.add(createFrameButton
(\商品信息查询\
29. searchStatisticPanel.add(createFrameButton
(\供应商信息查询\ 30. searchStatisticPanel.add(createFrameButton
(\销售信息查询\
31. searchStatisticPanel.add(createFrameButton
(\销售退货查询\
32. searchStatisticPanel.add(createFrameButton
(\入库查询\
33. searchStatisticPanel.add(createFrameButton
(\入库退货查询\
34. searchStatisticPanel.add(createFrameButton
(\销售排行\
35. JPanel stockManagePanel = new JPanel();
//“进货管理”面板
36. stockManagePanel.setBackground(new Color(215, 223, 194)); 37. stockManagePanel.setLayout(new BoxLayout
(stockManagePanel, BoxLayout.X_AXIS));
38. stockManagePanel.add(createFrameButton(\进货单\ 39. stockManagePanel.add(createFrameButton(\进货退货
\
40. JPanel sysManagePanel = new JPanel();
//“系统管理”面板