📄 polleditor.java
字号:
/*Contains PollEditor. This is the GUI for editiong questions.Copyright (C) 2005-2006 Igor Partola, Michael J. Krikonis, Clark UniversityThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/package PollEditor;import SharedClasses.*;import javax.swing.*;import java.io.*;public class PollEditor extends javax.swing.JFrame { public PollEditor() { setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); initComponents(); } private void initComponents() {//GEN-BEGIN:initComponents QuestionEditor = new SharedClasses.QuestionEditorPanel(); jMenuBar1 = new javax.swing.JMenuBar(); FileMenu = new javax.swing.JMenu(); NewMenuItem = new javax.swing.JMenuItem(); OpenMenuItem = new javax.swing.JMenuItem(); SaveMenuItem = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JSeparator(); ExitMenuItem = new javax.swing.JMenuItem(); HelpMenu = new javax.swing.JMenu(); AboutMenuItem = new javax.swing.JMenuItem(); getContentPane().setLayout(null); setTitle("JustPoll Question Editor"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); QuestionEditor.setJPQuestionVector(QuestionVector); getContentPane().add(QuestionEditor); QuestionEditor.setBounds(10, 10, 400, 410); FileMenu.setText("File"); NewMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SharedClasses/graphics/New16.gif"))); NewMenuItem.setText("New"); NewMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { NewMenuItemActionPerformed(evt); } }); FileMenu.add(NewMenuItem); OpenMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SharedClasses/graphics/Open16.gif"))); OpenMenuItem.setText("Open..."); OpenMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { OpenMenuItemActionPerformed(evt); } }); FileMenu.add(OpenMenuItem); SaveMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SharedClasses/graphics/Save16.gif"))); SaveMenuItem.setText("Save..."); SaveMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SaveMenuItemActionPerformed(evt); } }); FileMenu.add(SaveMenuItem); FileMenu.add(jSeparator1); ExitMenuItem.setText("Exit"); ExitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ExitMenuItemActionPerformed(evt); } }); FileMenu.add(ExitMenuItem); jMenuBar1.add(FileMenu); HelpMenu.setText("Help"); AboutMenuItem.setText("About"); AboutMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AboutMenuItemActionPerformed(evt); } }); HelpMenu.add(AboutMenuItem); jMenuBar1.add(HelpMenu); setJMenuBar(jMenuBar1); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-430)/2, (screenSize.height-483)/2, 430, 483); }//GEN-END:initComponents private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed SharedClasses.AboutDialog MyAboutFrame = new SharedClasses.AboutDialog(this, true); MyAboutFrame.show(); }//GEN-LAST:event_AboutMenuItemActionPerformed private void SaveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveMenuItemActionPerformed String filename; JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new SharedClasses.JPQFileFilter()); // Show open dialog; this method does not return until the dialog is closed fc.showSaveDialog(new JFrame()); File selFile = fc.getSelectedFile(); if (selFile == null) return; filename = selFile.getAbsolutePath(); if (!filename.endsWith(".jpq")) filename = filename + ".jpq"; QuestionVector.saveToFile(filename); }//GEN-LAST:event_SaveMenuItemActionPerformed private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitMenuItemActionPerformed exitForm(null); }//GEN-LAST:event_ExitMenuItemActionPerformed private void OpenMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenMenuItemActionPerformed JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new SharedClasses.JPQFileFilter()); // Show open dialog; this method does not return until the dialog is closed fc.showOpenDialog(new JFrame()); File selFile = fc.getSelectedFile(); if (selFile == null) return; QuestionVector.loadFromFile(selFile.getAbsolutePath()); }//GEN-LAST:event_OpenMenuItemActionPerformed private void NewMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewMenuItemActionPerformed QuestionVector.deleteAllQuestions(); }//GEN-LAST:event_NewMenuItemActionPerformed private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm int ans = JOptionPane.showConfirmDialog(this, "Save changes?", "Save", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (ans == JOptionPane.YES_OPTION) { SaveMenuItemActionPerformed(null); System.exit(0); } if (ans == JOptionPane.NO_OPTION) System.exit(0); if (ans == JOptionPane.CANCEL_OPTION) return; }//GEN-LAST:event_exitForm public static void main(String args[]) { new PollEditor().show(); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem AboutMenuItem; private javax.swing.JMenuItem ExitMenuItem; private javax.swing.JMenu FileMenu; private javax.swing.JMenu HelpMenu; private javax.swing.JMenuItem NewMenuItem; private javax.swing.JMenuItem OpenMenuItem; private SharedClasses.QuestionEditorPanel QuestionEditor; private javax.swing.JMenuItem SaveMenuItem; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JSeparator jSeparator1; // End of variables declaration//GEN-END:variables private JPQuestionVector QuestionVector = new JPQuestionVector(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -