public void paintComponent(Graphics g) { super.paintComponent(g); // Clear screen. g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); // draw entire component grey g.setColor(Fonts.sub_color); g.fillRect(0, 0, getWidth(), getHeight()); // Write title. g.setColor(Color.BLACK); g.setFont(Fonts.big); g.drawString("Ear", 20, 150); g.drawString("Training", 20, 200); // Write "Choose Difficulty". g.setFont(Fonts.italic); g.drawString("Choose Difficulty", 20, 300); // Draw piano image keyboard.setDimensions(250, 0, getWidth(), getHeight()); keyboard.paintComponent(g); mainMenu.paintComponent(g); }
public void mouseClicked(MouseEvent e) { keyboard.mouseClicked(e); if (mainMenu.setMouseClicked(e.getX(), e.getY())) { JFrameStack.popPanel(); } }
@Override public void mouseMoved(MouseEvent e) { mainMenu.computeMouseEntered(e.getX(), e.getY()); mainMenu.computeMouseExited(e.getX(), e.getY()); keyboard.mouseMoved(e); this.repaint(); }
/** * Returns if keyboard visible or not. * @return false if keyboard instance null. */ protected boolean isKeyBoardVisible(){ if(mKeyboard != null){ if(mKeyboard.getVisibility() == View.VISIBLE){ return true; } else { return false; } } else { return false; } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final Keyboard keyboard = getKeyboard(); if (keyboard != null) { final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); final int height = keyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); setMeasuredDimension(width, height); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
public EarTrainingUI() { super(); NotesToPlayData data = new NotesToPlayData(); data.minKey = 60; data.maxKey = 71; data.numOctaves = 1; HashMap<Integer, String> menuData = new HashMap<Integer, String>(); menuData.put(62, "Pitch Training"); menuData.put(64, "Advanced Pitch Training"); menuData.put(65, "Interval Training"); menuData.put(67, "Chord Training"); menuData.put(69, "Advanced Chord Training"); HashMap<Integer, Color> colorData = new HashMap<Integer, Color>(); colorData.put(62, Color.RED); colorData.put(64, Color.YELLOW); colorData.put(65, Color.GREEN); colorData.put(67, Color.BLUE); colorData.put(69, Color.MAGENTA); keyboard = new KeyboardView(this, menuData, data); keyboard.addColorData(colorData); mainMenu = new MainMenuButton("< Back", 5, 5, 100, 20); }
/** * Hides the custom keykoard. */ protected void hideKeyBoard() { if(mKeyboard != null){ mKeyboard.setVisibility(View.GONE); } }
/** * Makes custom keyboard visible. */ protected void showKeyBoard() { if(mKeyboard != null){ mKeyboard.setVisibility(View.VISIBLE); } }
@Override public void setKeyboard(Keyboard keyboard) { super.setKeyboard(keyboard); mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); }
@Override public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { // Mini keyboard needs no pop-up key preview displayed, so we pass always false with a // delay of 0. The delay does not matter actually since the popup is not shown anyway. super.setKeyPreviewPopupEnabled(false, 0); }