/**
   * The GPropertiesDialog class constructor.
   *
   * @param gui the GUI class
   */
  public GPropertiesDialog(GUI gui) {
    // superclass constructor
    super(gui, "Properties", false);
    objects = new ObjectContainer();

    // gui
    this.gui = gui;

    // set the fixed size
    setSize(260, 350);
    setResizable(false);
    setLayout(null);

    // set up panels for stuff
    pane = new JTabbedPane();

    // add the tabbed panel
    tabbedPanePanel = new JPanel();
    tabbedPanePanel.add(pane);
    tabbedPanePanel.setLayout(null);
    this.getContentPane().add(tabbedPanePanel);
    tabbedPanePanel.setBounds(0, 0, this.getWidth(), 280);
    pane.setBounds(0, 0, tabbedPanePanel.getWidth(), tabbedPanePanel.getHeight());

    // set up buttons
    apply = new JButton("Apply");
    apply.setBounds(150, 290, 80, 26);
    this.getContentPane().add(apply);

    close = new JButton("Close");
    close.setBounds(50, 290, 80, 26);
    this.getContentPane().add(close);

    addPanel(new GPropertiesPanelCustomObject(gui.getGMap()), "Object");

    // add listeners
    addMouseListener(this);
    apply.addItemListener(this);
    apply.addActionListener(this);
    close.addItemListener(this);
    close.addActionListener(this);
  }
示例#2
0
  ////////////// methods to create the interactive visualizer ////////////////////////
  private void createMainFrame() {
    mainFrame = new JFrame();
    mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    Container contentPane = mainFrame.getContentPane();
    // contentPane.setLayout(new BorderLayout());

    // creates the control panel
    controlPanel = new JPanel(null);
    controlPanel.setLayout(new FlowLayout());
    makeSoundVis();
    mainFrame.addComponentListener(new ResizeHandler());

    // setting up the play sound button
    playBtn = new JButton("Play");
    playBtn.setEnabled(true);
    playBtn.setToolTipText("Play the  sound");
    playBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            stopBtn.setEnabled(true);
            pauseBtn.setEnabled(true);
            playBtn.setEnabled(false);
            playSelectionBtn.setEnabled(false);
            zoomInBtn.setEnabled(false);
            zoomOutBtn.setEnabled(false);
            isPlaying = true;
            myHelper.play();
          }
        });
    controlPanel.add(playBtn);

    // setting up the play selection button
    playSelectionBtn = new JButton("Play Selection");
    playSelectionBtn.setEnabled(false);
    playSelectionBtn.setToolTipText("Play sound between start and stop index");
    playSelectionBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            playSelClicked++;
            stopBtn.setEnabled(true);
            pauseBtn.setEnabled(true);
            playSelectionBtn.setEnabled(false);
            playBtn.setEnabled(false);
            zoomInBtn.setEnabled(false);
            zoomOutBtn.setEnabled(false);
            isPlaying = false;
            if (playSelClicked == 1) {
              myHelper.playInRange(
                  wavePanel.getSelectionStartSample(), wavePanel.getSelectionEndSample());
            } else {
              myHelper.play();
            }
          }
        });
    controlPanel.add(playSelectionBtn);

    // setting up the stop button
    stopBtn = new JButton("Stop");
    stopBtn.setEnabled(false);
    stopBtn.setToolTipText("Stop playing the sound");
    stopBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            myHelper.stop();
            stopBtn.setEnabled(false);
            pauseBtn.setEnabled(false);
            playBtn.setEnabled(true);
            if (wavePanel.moreZoomInScope()) {
              zoomInBtn.setEnabled(true);
              playSelectionBtn.setEnabled(true);
            }

            if (wavePanel.moreZoomOutScope()) {
              zoomOutBtn.setEnabled(true);
            }
            playSelClicked = 0;
            isPlaying = false;
          }
        });
    controlPanel.add(stopBtn);

    // setting up the stop button
    pauseBtn = new JButton("Pause");
    pauseBtn.setEnabled(false);
    pauseBtn.setToolTipText("Pause the sound");
    pauseBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            myHelper.pause();
            if (isPlaying) {
              playBtn.setEnabled(true);
            } else {
              playSelectionBtn.setEnabled(true);
            }
          }
        });
    controlPanel.add(pauseBtn);

    // setting up the zoom  button
    zoomInBtn = new JButton("Zoom In");
    zoomInBtn.setEnabled(false);
    zoomInBtn.setToolTipText("Click to see the samples within your selection");
    zoomInBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            handleZoomIn();
          }
        });
    controlPanel.add(zoomInBtn);

    // setting up the zoom  button
    zoomOutBtn = new JButton("Zoom Out");
    zoomOutBtn.setEnabled(false);
    zoomOutBtn.setToolTipText("Click to zoom out");
    zoomOutBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            handleZoomOut();
          }
        });
    controlPanel.add(zoomOutBtn);

    controlPanel.setBounds(0, controlLocY, frameWidth, controlHeight);
    contentPane.add(controlPanel);

    contentPane.add(wavePanel);
    contentPane.add(overViewPanel);
    wavePanel.setBounds(0, waveLocY, frameWidth, waveHeight);

    // controlPanel.removeAll();
    // controlPanel.setBackground(Color.CYAN);

    mainFrame.setSize(frameWidth, frameHeight);

    overViewPanel.init();
    wavePanel.init();
    //
    // mainFrame.pack();
    // mainFrame.setResizable(false);
    // mainFrame.validate();

    mainFrame.setVisible(true);
    overViewPanel.setBounds(0, 0, frameWidth, overViewHeight);

    // mainFrame.validate();

  }
示例#3
0
文件: TetrisUI.java 项目: kymo/tetris
  /**
   * inti the UI and some params
   *
   * @param none
   */
  public void initUI() {
    // cNextBlockDC.setLayout(new BorderLayout());
    getContentPane().setLayout(null);
    // the total panel
    JPanel outer = new JPanel();
    getContentPane().add(outer);
    outer.setBounds(4, 4, frameWeight - 20, frameHeight - 50);
    outer.setBorder(BorderFactory.createTitledBorder("Game DC"));
    outer.setLayout(null);

    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(null);
    // the panel to show next block
    JPanel tipNext = new JPanel();
    tipNext.setBounds(10, 30, 130, 80);
    tipNext.setBorder(BorderFactory.createTitledBorder("Next Block"));
    tipNext.setLayout(null);
    cNextBlockDC.setBounds(25, 20, 48, 48);
    tipNext.add(cNextBlockDC);
    rightPanel.add(tipNext);

    // the panel to show the score
    JPanel playerScore = new JPanel();
    playerScore.setBounds(10, 110, 130, 40);
    playerScore.setBorder(BorderFactory.createTitledBorder("Score"));
    playerScore.setLayout(null);
    m_lTotalScore.setBounds(40, 15, 100, 20);
    playerScore.add(m_lTotalScore);
    rightPanel.add(playerScore);

    // the panel to show the button
    JPanel buttonArea = new JPanel();
    buttonArea.setBounds(10, 160, 130, 170);
    buttonArea.setBorder(BorderFactory.createTitledBorder("Game Control"));
    buttonArea.setLayout(null);
    m_bGameHalt.setBounds(10, 30, 110, 30);
    buttonArea.add(m_bGameHalt);
    m_bGameStart.setBounds(10, 62, 110, 30);
    buttonArea.add(m_bGameStart);
    m_bGameOver.setBounds(10, 94, 110, 30);
    buttonArea.add(m_bGameOver);
    m_bVoiceControl.setBounds(10, 126, 110, 30);
    buttonArea.add(m_bVoiceControl);

    rightPanel.add(buttonArea);
    // the Panel to show the tips for the game
    JPanel gameTip = new JPanel();
    gameTip.setBounds(10, 330, 130, 160);
    gameTip.setBorder(BorderFactory.createTitledBorder("Game Tip"));
    gameTip.setLayout(null);
    m_lGameTip.setBounds(10, 20, 130, 100);
    Font fnt = new Font("楷体_GB2312", Font.ITALIC, 15);
    m_lGameTip.setText(
        "<html><body>"
            + "<font style='color:#2f4f4f;size:10px;'>"
            + "1.由方向键控制游戏<br/>,向上有变形;<br/>2."
            + "语音控制命令见配<br/>置文件;<br/>3.Author:");
    // the link for blog
    JLabel linkForBlog =
        new JLabel("<html><body><a style='color:#00755e;' href ='#'>kymo</a></body></html>");
    linkForBlog.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkForBlog.setBounds(20, 113, 130, 15);
    // add mouse event
    linkForBlog.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            //// System.out.println("click !");
            try {
              Desktop.getDesktop().browse(new java.net.URI(kymoBlog));
            } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            } catch (URISyntaxException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
          }
        });
    // the link to open voice xml file
    JLabel linkForXml =
        new JLabel(
            "<html><body><a style='color:#00755e;' href ='#'>open voice xml</a></body></html>");
    linkForXml.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkForXml.setBounds(20, 128, 130, 15);
    // add mouse event
    linkForXml.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // JLabel xmlFileContent = new JLabel();
            try {
              Runtime.getRuntime()
                  .exec("cmd /c start " + System.getProperty("user.dir") + "\\voice.xml");
            } catch (IOException ex) {
              //// System.out.println(ex);
            }
          }
        });
    gameTip.add(linkForBlog);
    gameTip.add(linkForXml);
    gameTip.add(m_lGameTip);
    rightPanel.add(gameTip);

    // pack();
    rightPanel.setBounds(340, 30, 150, 500);
    rightPanel.setBorder(BorderFactory.createTitledBorder("Game Control&Tips"));

    outer.add(rightPanel);
    cGameDc = new DrawComponent(this, cTetrisBlock);
    cGameDc.setBounds(30, 30, 300, 500);
    outer.add(cGameDc);
    setVisible(true);
    setResizable(false);
    pack();
    this.setSize(frameWeight, frameHeight);
    this.setLocation(frameLocaX, frameLocaY);
    m_bGameHalt.addActionListener((ActionListener) this);
    m_bGameStart.addActionListener((ActionListener) this);
    m_bGameOver.addActionListener((ActionListener) this);
    m_bVoiceControl.addActionListener((ActionListener) this);
    // if the windows is close ,the game thread will end
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            isGameOver = true;
            System.exit(0);
          }
        });

    // the listen of the keyboard
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              @Override
              public void eventDispatched(AWTEvent event) {
                // TODO Auto-generated method stub
                if (((KeyEvent) event).getID() == KeyEvent.KEY_RELEASED) isKeyPressed = false;
                if (((KeyEvent) event).getID() == KeyEvent.KEY_PRESSED) {
                  // 放入自己的键盘监听事件
                  // ((KeyEvent) event).getKeyCode();// 获取按键的code
                  // ((KeyEvent) event).getKeyChar();//
                  // 获取按键的字符////System.out.println(e.getKeyCode());
                  if (!isGameHalt && isGameStart) {
                    if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_RIGHT) {
                      if (!isCoordinateLock) {
                        isKeyPressed = true;
                        if (!isRightToEnd(cTetrisBlock.m_blockRightX))
                          cTetrisBlock.setCoordinateXY(
                              cTetrisBlock.getTetrisCoordinateX() + 20,
                              cTetrisBlock.getTetrisCoordinateY());
                        cGameDc.repaint();
                      }
                    } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_LEFT) {
                      if (!isCoordinateLock) {
                        isKeyPressed = true;
                        /*
                        for(int j = 0; j < 4; j ++)
                        	//System.out.print(cTetrisBlock.m_blockLeftX[j] + " ");
                        */
                        //// System.out.println();
                        if (!isLeftToEnd(cTetrisBlock.m_blockLeftX))
                          cTetrisBlock.setCoordinateXY(
                              cTetrisBlock.getTetrisCoordinateX() - 20,
                              cTetrisBlock.getTetrisCoordinateY());
                        cGameDc.repaint();
                      }
                    } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_DOWN) {
                      if (!isCoordinateLock) {
                        isKeyPressed = true;
                        if (!isToEnd(cTetrisBlock.m_blockBottomY))
                          cTetrisBlock.setCoordinateXY(
                              cTetrisBlock.getTetrisCoordinateX(),
                              cTetrisBlock.getTetrisCoordinateY() + 20);
                        cGameDc.repaint();
                      }
                    } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_UP) {
                      if (!isCoordinateLock) {
                        isKeyPressed = true;
                        isTransforStart = true;
                        cTetrisBlock.tetrisBlockShapeTransformation(m_blockGrid);
                        cGameDc.repaint();
                        isTransforStart = false;
                      }
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK);
  }