示例#1
0
  /**
   * Creates a new configuration method
   *
   * @param backMenu Menu instance used to control its music
   */
  public Config(Menu backMenu) {

    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      try (ObjectInputStream entradaObjs =
          new ObjectInputStream(new FileInputStream("Saves" + File.separator + "config.dat"))) {
        configSave = (float[]) entradaObjs.readObject();
      }
    } catch (ClassNotFoundException
        | IOException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
      System.out.println(e.getMessage());
    }

    this.setSize(800, 300);
    this.add(fondo = new Fondo("fondoConfig.png"));
    this.setUndecorated(true);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images" + File.separator + "logo.png"));
    this.backMenu = backMenu;

    icon = new ImageIcon("Images/brick.png");

    fondo.setLayout(new BorderLayout());

    returns = CustomButton.createButton("Go Back", this.getGraphicsConfiguration(), 18);
    returns.addActionListener(this);

    musicSlider = new JSlider(JSlider.HORIZONTAL, -30, 0, (int) configSave[0]);
    musicSlider.setOpaque(false);
    musicSlider.setMajorTickSpacing(10);
    musicSlider.setMinorTickSpacing(2);
    musicSlider.setPaintTicks(true);

    volumeSlider = new JSlider(JSlider.HORIZONTAL, -30, 0, (int) configSave[1]);
    volumeSlider.setOpaque(false);
    volumeSlider.setMajorTickSpacing(10);
    volumeSlider.setMinorTickSpacing(2);
    volumeSlider.setPaintTicks(true);

    fondo.add(returns, BorderLayout.SOUTH);
    fondo.add(musicSlider, BorderLayout.NORTH);
    fondo.add(volumeSlider, BorderLayout.CENTER);

    try {
      this.getContentPane()
          .setCursor(
              Toolkit.getDefaultToolkit()
                  .createCustomCursor(
                      CompatibleImage.toCompatibleImage(
                          ImageIO.read(new File("Images" + File.separator + "cursor.png"))),
                      new Point(0, 0),
                      "cursor"));
    } catch (IOException ex) {
      Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
    }

    this.setVisible(true);
  }