예제 #1
0
 public void actionPerformed(ActionEvent event) {
   if (typePanel.getSelection().equals("Confirm"))
     JOptionPane.showConfirmDialog(
         OptionDialogFrame.this,
         getMessage(),
         "Title",
         getType(optionTypePanel),
         getType(messageTypePanel));
   else if (typePanel.getSelection().equals("Input")) {
     if (inputPanel.getSelection().equals("Text field"))
       JOptionPane.showInputDialog(
           OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
     else
       JOptionPane.showInputDialog(
           OptionDialogFrame.this,
           getMessage(),
           "Title",
           getType(messageTypePanel),
           null,
           new String[] {"Yellow", "Blue", "Red"},
           "Blue");
   } else if (typePanel.getSelection().equals("Message"))
     JOptionPane.showMessageDialog(
         OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
   else if (typePanel.getSelection().equals("Option"))
     JOptionPane.showOptionDialog(
         OptionDialogFrame.this,
         getMessage(),
         "Title",
         getType(optionTypePanel),
         getType(messageTypePanel),
         null,
         getOptions(),
         getOptions()[0]);
 }
 public void saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           try {
             PrintStream stream = new PrintStream(new FileOutputStream(target), true);
             save(stream);
             stream.close();
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 this,
                 new JLabel("Error: " + ex.getMessage()),
                 "Error",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }