コード例 #1
0
ファイル: Console.java プロジェクト: palex65/consolePG
 private static Clip getClip(String wavFile) {
   String soundName = "sound\\" + wavFile + ".wav";
   InputStream sound = null;
   Clip clip = null;
   try {
     sound = new FileInputStream(soundName);
   } catch (FileNotFoundException ex) {
     sound = ClassLoader.getSystemResourceAsStream(soundName);
     if (sound == null) {
       System.out.println("Cant open file " + soundName);
       return null;
     }
   }
   try {
     AudioInputStream audioIn = AudioSystem.getAudioInputStream(sound);
     clip = AudioSystem.getClip();
     clip.open(audioIn);
   } catch (Exception ex) {
     System.out.println("Error in sound " + wavFile);
     System.out.println(ex.getMessage());
     if (clip != null) {
       clip.close();
       return null;
     }
     try {
       sound.close();
     } catch (IOException e) {
     }
   }
   return clip;
 }
コード例 #2
0
  public static void main(final String[] args) {
    final JFrame frame = new JFrame();
    frame.setTitle(Globals.getLocalizedString("programName"));
    frame.setBackground(VComponentGlobals.BACKGROUND_COLOR);

    try {
      frame.setIconImage(
          ICODecoder.read(ClassLoader.getSystemResourceAsStream("Art Assets/Icons/Frame_Icon.ico"))
              .get(0));
    } catch (final IOException e) {
      Logger.writeLog(
          Globals.getLocalizedString("DC_error_UnableToLoadIcon"), Logger.LOG_TYPE_ERROR);
    }

    frame.addWindowListener(
        new WindowListener() {
          @Override
          public void windowOpened(WindowEvent e) {}

          @Override
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }

          @Override
          public void windowClosed(WindowEvent e) {
            System.exit(0);
          }

          @Override
          public void windowIconified(WindowEvent e) {}

          @Override
          public void windowDeiconified(WindowEvent e) {}

          @Override
          public void windowActivated(WindowEvent e) {}

          @Override
          public void windowDeactivated(WindowEvent e) {}
        });

    frame.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            final Dimension currentDimensions = frame.getSize();
            final Dimension minimumDimensions = frame.getMinimumSize();

            if (currentDimensions.width < minimumDimensions.width) {
              currentDimensions.width = minimumDimensions.width;
            }

            if (currentDimensions.height < minimumDimensions.height) {
              currentDimensions.height = minimumDimensions.height;
            }

            frame.setSize(currentDimensions);
          }
        });

    frame.add(new ConnectionScreenController(frame).getView());
    frame.setResizable(false);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }