⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 source.java

📁 mp3播放功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	private void dealPlay() {
		PausePlay.setText("||");
		playPauseState = Characters.PLAY;
		playSelectedSong();
	}

	/**
	 * Method to get the index of next song
	 * 
	 * @return int the index
	 */
	private int getNextSongIndex() {
		int nextIndex = -1;
		int currentindex = getCurrentSelectedIndex();
		if (currentindex >= 0) {
			boolean isRotate = Rotate.isSelected();
			boolean isShuffle = Shuffle.isSelected();
			boolean isOrder = Order.isSelected();
			boolean isSingle = Single.isSelected();
			if (isOrder) {
				if (currentindex == playlist.Playlist.getItemCount() - 1)
					nextIndex = 0;
				else
					nextIndex = currentindex + 1;
			} else if (isRotate) {
				if (currentindex == playlist.Playlist.getItemCount() - 1)
					nextIndex = 0;
				else
					nextIndex = currentindex + 1;
			} else if (isShuffle)
				nextIndex = (int) (Math.random() * (playlist.Playlist
						.getItemCount()));
			else if (isSingle) {
				nextIndex = 0;
			} else
				nextIndex = currentindex;

		}
		return nextIndex;
	}

	/**
	 * Invoked when press the button Stop Method to stop the playing song
	 * 
	 * @param e
	 *            ActionEvent object
	 */
	private void StopActionPerformed(ActionEvent e) {
		// TODO add your code here
		control.stop();
		Progress.setValue(0);
		TotalTime.setText("00:00");
		PlayTime.setText("00:00");
		playPauseState = Characters.STOP;
		PausePlay.setText("Play");
		Progress.setEnabled(false);

	}

	/**
	 * Invoked when drag the JSlider Volume Method to chage the volume
	 * 
	 * @param e          ActionEvent object
	 */
	private void VolumeStateChanged(ChangeEvent e) {
		// TODO add your code here
		setVolumn();
	}

	private void setVolumn() {
		if (Volume.isEnabled()) {
			double gain = Volume.getValue() * 1.0 / Volume.getMaximum();
			control.setVolumnGain(gain);
		} else {
			control.setVolumnGain(0);
		}
	}

	/**
	 * Invoked when press the button button1 Method to minimum the window
	 * 
	 * @param e   ActionEvent object
	 */
	private void MinimumActionPerformed(ActionEvent e) {
		// TODO add your code here
		setExtendedState(Source.ICONIFIED);
		playlist.setExtendedState(Playlist.ICONIFIED);
	} // 最小化主从窗口

	private void MiniSizeActionPerformed(ActionEvent e) {
		// TODO add your code here
		msize.setLocation(new Point(100, 5));
		msize.setVisible(true);
		playlist.setVisible(false);
		this.setVisible(false);
	} // 迷你化主从窗口

	/**
	 * Invoked when press the button List Method to show the Playlist
	 * 
	 * @param e   ActionEvent object
	 */
	private void ListActionPerformed(ActionEvent e) {
		showPlayList();
	}

	private void showPlayList() {
		if (playlistState == Characters.PLSTATE_HIDE) {
			playlist.setLocation(this.getX(), this.getY() + this.getHeight());
			playlist.setVisible(true);
			playlistState = Characters.PLSTATE_SHOW;
		} else {
			playlist.setVisible(false);
			playlistState = Characters.PLSTATE_HIDE;

		}
	}

	/**
	 * Save the all list information into the file "All.dat"
	 * 
	 */
	private void LoadList() {
		int count = playlist.model.getSize();
		try {
			output = new ObjectOutputStream(new FileOutputStream("All.dat"));
			Object order1;
			for (int i = 0; i < count; i++) {
				order1 = playlist.model.get(i);
				output.writeObject(order1);
				output.flush();
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException io) {
			io.printStackTrace();
		}
	}

	/**
	 * Init the components display on the JFrame Add each listeners to each
	 * components
	 */
	private void initComponents() {

		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner non-commercial license
		panel2 = new JPanel();
		label1 = new JLabel();
		minimum = new JButton();
		exit = new JButton();
		miniSize = new JButton();
		panel8 = new JPanel();
		panel15 = new JPanel();
		Information = new JLabel();
		panel10 = new JPanel();
		panel16 = new JPanel();
		PlayTime = new JLabel();
		TotalTime = new JLabel();
		panel12 = new JPanel();
		silent = new JButton();
		Volume = new JSlider();
		panel11 = new JPanel();
		mode = new JMenu("ModeSelection");
		Rotate = new JRadioButtonMenuItem("Rotate");
		Shuffle = new JRadioButtonMenuItem("Shuffle");
		Order = new JRadioButtonMenuItem("Order");
		Single = new JRadioButtonMenuItem("Single");
		SingleRotate = new JRadioButtonMenuItem("SingleRotate");
		modeBar = new JMenuBar();
		group = new ButtonGroup();

		Order.setSelected(true);
		mode.add(Order);
		mode.add(Rotate);
		mode.add(Shuffle);
		mode.add(Single);
		mode.add(SingleRotate);

		group.add(Order);
		group.add(Rotate);
		group.add(Shuffle);
		group.add(Single);
		group.add(SingleRotate);

		modeBar.add(mode);

		panel14 = new JPanel();
		Progress = new JSlider();
		List = new JButton();
		panel1 = new JPanel();
		AddPack = new JButton();
		Previous = new JButton();
		PausePlay = new JButton();
		Next = new JButton();
		Stop = new JButton();
		CellConstraints cc = new CellConstraints();

		setDragable(); // 调用setDragable方法,使组件可拖拽

		control.setTVShow(spectrum);

		Container contentPane = getContentPane();
		panel = new JPanel();
		panel.setBounds(new Rectangle(290, 185));
		panel.setBorder(BorderFactory.createMatteBorder(4, 3, 2, 3, new Color(
				219, 222, 143)));
		panel.setLayout(new FormLayout(ColumnSpec.decodeSpecs("default"),
				new RowSpec[] {
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.LINE_GAP_ROWSPEC,
						new RowSpec(RowSpec.FILL, Sizes.dluY(52),
								FormSpec.NO_GROW),
						FormFactory.LINE_GAP_ROWSPEC,
						new RowSpec(Sizes.dluY(20)),
						FormFactory.LINE_GAP_ROWSPEC,
						new RowSpec(Sizes.dluY(17)) }));

		// ======== panel2 ========
		{
			panel2.setLayout(new FormLayout(new ColumnSpec[] {
					new ColumnSpec(Sizes.dluX(43)),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
					new ColumnSpec(Sizes.dluX(95)),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
					new ColumnSpec(Sizes.dluX(13)),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
					new ColumnSpec(Sizes.dluX(13)),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
					new ColumnSpec(Sizes.dluX(13)) }, RowSpec
					.decodeSpecs("13dlu")));

			// ---- label1 ----
			label1.setText("   Player");
			label1.setForeground(new Color(255, 255, 255));
			label1.setFont(new Font("Book Antiqua", Font.BOLD, 16));
			panel2.add(label1, cc.xywh(1, 1, 2, 1));

			// ---- minimum ----
			minimum.setText("_");
			minimum.setFont(new Font("Book Antiqua", Font.BOLD, 16));
			panel2.add(minimum, cc.xy(5, 1));
			minimum.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					MinimumActionPerformed(e);

				}
			});

			// ---- miniSize ----
			miniSize.setText("T");
			miniSize.setFont(new Font("Book Antiqua", Font.BOLD, 16));
			panel2.add(miniSize, cc.xy(7, 1));
			miniSize.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					MiniSizeActionPerformed(e);

				}
			});

			// ---- exit ----
			exit.setText("X");
			exit.setFont(new Font("Book Antiqua", Font.BOLD, 16));
			panel2.add(exit, cc.xy(9, 1));
			exit.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent event) {
					LoadList();
					System.exit(0);
					try {
						output.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});

		}
		panel.add(panel2, cc.xy(1, 1));

		// ======== panel8 ========
		{
			panel8.setLayout(new FormLayout(new ColumnSpec[] {
					new ColumnSpec(Sizes.dluX(93)),
					FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
					new ColumnSpec(Sizes.dluX(91)) }, RowSpec
					.decodeSpecs("49dlu")));

			// ======== panel15 ========
			{
				panel15.setLayout(new FormLayout(ColumnSpec
						.decodeSpecs("93dlu"), new RowSpec[] {
						new RowSpec(Sizes.dluY(33)),
						FormFactory.LINE_GAP_ROWSPEC,
						new RowSpec(Sizes.dluY(13)) }));

				// ======== SpectrumTimeAnalyzer ========
				{

					spectrum.setPreferredSize(new Dimension(154, 55));
					// spectrum.setBorder(BorderFactory.createEtchedBorder());

				}
				panel15.add(spectrum, cc.xy(1, 1));

				// ---- Information ----
				Information.setText("");
				panel15.add(Information, cc.xy(1, 3));

			}
			panel8.add(panel15, cc.xy(1, 1));

			// ======== panel10 ========
			{
				panel10.setLayout(new FormLayout(ColumnSpec
						.decodeSpecs("91dlu"), new RowSpec[] {
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.LINE_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.LINE_GAP_ROWSPEC,
						new RowSpec(Sizes.dluY(15)) }));

				// ======== panel16 ========
				{
					panel16.setLayout(new FormLayout(new ColumnSpec[] {
							new ColumnSpec(Sizes.dluX(46)),
							FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
							new ColumnSpec(Sizes.dluX(47)) }, RowSpec
							.decodeSpecs("default")));

					// ---- PlayTime ----
					PlayTime.setText("00:00");
					panel16.add(PlayTime, cc.xy(1, 1));

					// ---- TotalTime ----
					TotalTime.setText("00:00");
					panel16.add(TotalTime, cc.xy(3, 1));
				}
				panel10.add(panel16, cc.xy(1, 1));

				// ======== panel12 ========
				{
					panel12.setLayout(new FormLayout(new ColumnSpec[] {
							new ColumnSpec(Sizes.dluX(16)),
							FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
							new ColumnSpec(Sizes.dluX(62)) }, RowSpec
							.decodeSpecs("default")));

					// ---- silent ----
					silent.setText("

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -