⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.java

📁 Java程序设计大学教程程序源代码
💻 JAVA
字号:
/* * MainForm.java * * Created on 2005年6月28日, 上午11:34 * * @author  Liu Yi  ( http://www.liu-yi.net ) */package wordwinner;import java.io.*;import java.awt.*;import javax.swing.*;import java.util.*;public class MainForm extends javax.swing.JFrame {        public MainForm() {        initComponents();        //加入组件        Container container =getContentPane();        mainPanel=new MainPanel();        container.add(mainPanel);        int width=600;        int height=400;        setSize(600,400);//设置框架大小        setTitle("单词赢家");//设置框架标题        //将框架显示在屏幕正中        Toolkit kit= Toolkit.getDefaultToolkit();        Dimension screenSize=kit.getScreenSize();        int x=(screenSize.width-width)/2;        int y=(screenSize.height-height)/2;        setLocation(x,y);//设置框架位置            }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        menuBar = new javax.swing.JMenuBar();        menuFile = new javax.swing.JMenu();        menuItemOpen = new javax.swing.JMenuItem();        menuItemExit = new javax.swing.JMenuItem();        menuView = new javax.swing.JMenu();        menuItemSetup = new javax.swing.JMenuItem();        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);        setFont(new java.awt.Font("宋体", 0, 14));        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                formWindowClosing(evt);            }        });        menuFile.setText("\u6587\u4ef6");        menuItemOpen.setText("\u6253\u5f00");        menuItemOpen.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuItemOpenActionPerformed(evt);            }        });        menuFile.add(menuItemOpen);        menuItemExit.setText("\u9000\u51fa");        menuItemExit.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuItemExitActionPerformed(evt);            }        });        menuFile.add(menuItemExit);        menuBar.add(menuFile);        menuView.setText("\u89c6\u56fe");        menuItemSetup.setText("\u8bbe\u7f6e");        menuItemSetup.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuItemSetupActionPerformed(evt);            }        });        menuView.add(menuItemSetup);        menuBar.add(menuView);        setJMenuBar(menuBar);        pack();    }//GEN-END:initComponents    private void menuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemExitActionPerformed        //退出程序        exit();    }//GEN-LAST:event_menuItemExitActionPerformed    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing        //退出程序        exit();    }//GEN-LAST:event_formWindowClosing    private void menuItemSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSetupActionPerformed        // 功能设置       mainPanel.setup();    }//GEN-LAST:event_menuItemSetupActionPerformed            private void menuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemOpenActionPerformed        // 打开词库文件        mainPanel.open();    }//GEN-LAST:event_menuItemOpenActionPerformed        public static void main(String args[]) {        try {            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");        } catch (Exception e){            e.printStackTrace();        }        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new MainForm().setVisible(true);            }        });    }     private void exit(){         int selection=JOptionPane.showConfirmDialog(this,"是否立即退出系统?","操作提示",                JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);        if (selection==JOptionPane.OK_OPTION)                   System.exit(0);         }        // 变量声明 - 不进行修改//GEN-BEGIN:variables    private javax.swing.JMenuBar menuBar;    private javax.swing.JMenu menuFile;    private javax.swing.JMenuItem menuItemExit;    private javax.swing.JMenuItem menuItemOpen;    private javax.swing.JMenuItem menuItemSetup;    private javax.swing.JMenu menuView;    // 变量声明结束//GEN-END:variables    private MainPanel mainPanel;//主面板    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -