Java仿千千静听音乐播放器源代码

更新时间:2023-06-09 09:33:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Java仿千千静听音乐播放器源代码 自己收集的。

JAVA仿千千静听音乐播放器源代码

CrystalButton.java

package eb.cstop.swing;

import java.awt.*;

import java.awt.event.*;

import javax.swing.ImageIcon;

import javax.swing.JButton;

public class CrystalButton extends JButton implements MouseListener {

private float alpha = 1.0f; private Color borderColor = new Color(0x00, 0x00, 0x00); private Color exitedBorderColor = new Color(0x33, 0x33, 0x33);

Java仿千千静听音乐播放器源代码 自己收集的。

private boolean pressed = false; public CrystalButton() { } public CrystalButton(String text) { } public CrystalButton(String text, ImageIcon icon) { } public CrystalButton(String text, ImageIcon icon, String toolTip) { } public void setAlpha(float alpha) { } public float getAlpha() { } public void paintBorder(Graphics g) { } public void paintComponent(Graphics g) { Graphics2D cs = (Graphics2D) g; int width = this.getSize().width; int height = this.getSize().height; cs.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); return alpha; this.alpha = alpha; this.repaint(); this.addMouseListener(this); this.setText(text); if (icon != null) this.setIcon(icon); this.setContentAreaFilled(false); this.setFont(new Font("宋体", 0, 12)); this.setForeground(Color.white); this.setToolTipText(toolTip); this(text, icon, ""); this(text, null); this("");

Java仿千千静听音乐播放器源代码 自己收集的。

int comparison = 0; if (exited && !pressed) cs.setColor(exitedBorderColor); cs.setColor(borderColor); else cs.drawRect(0, 0, width - 1, height - 1); while (i < height - 1) { } cs.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); super.paintComponent(g); cs.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); comparison = (i - 1) * 100 / (height - 3); if (comparison < 36) { } i++; if (exited && !pressed) cs.setColor(new Color(255 - (comparison + comparison * 2), 255 - (comparison + comparison * 2), 255 - (comparison + comparison * 2))); else cs.setColor(new Color(235 - (comparison + comparison * 2), 235 - (comparison + comparison * 2), 235 - (comparison + comparison * 2))); cs.drawLine(1, i, width - 2, i); if (i != 1) { } if (exited && !pressed) cs.setColor(new Color(comparison - 16, comparison - 16, comparison - 16)); if (exited && !pressed) cs.setColor(new Color(204 - comparison * 2, 204 - comparison * 2, 204 - comparison * 2)); else cs.setColor(new Color(184 - comparison * 2, 184 - comparison * 2, 184 - comparison * 2)); cs.drawLine(2, i, width - 3, i); } else { else cs.setColor(new Color(comparison - 36, comparison - 36, comparison - 36)); cs.drawLine(1, i, width - 2, i);

Java仿千千静听音乐播放器源代码 自己收集的。

} public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } pressed = false; this.repaint(); exited = true; this.repaint(); exited = false; this.repaint(); pressed = true; this.repaint();

LButton.java

package eb.cstop.swing;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class LButton extends JButton implements MouseListener {

public LButton(String text) { super(text); public LButton() { } this.setButton(); private final Font font = new Font("宋体", 0, 12); private boolean mouseOn = false; private boolean mouseDown = false;

Java仿千千静听音乐播放器源代码 自己收集的。

} public LButton(ImageIcon icon) { } public LButton(String text, ImageIcon icon) { } private void setButton() { } public void paintBorder(Graphics g) { this.setContentAreaFilled(false); g.setColor(new Color(255, 255, 255)); g.fillRect(3, 3, this.getSize().width - 5, this.getSize().height - 5); if (!this.mouseDown) { if (!this.mouseOn) { } g.drawLine(3, 2, this.getSize().width - 3, 2);// TopLine g.drawLine(3, this.getSize().height - 3, this.getSize().width - 3, this.getSize().height - 3);// BottomLine g.drawLine(2, 3, 2, this.getSize().height - 4);// LeftLine g.drawLine(this.getSize().width - 2, 3, this.getSize().width - 2, this.getSize().height - 4);// RightLine int height = this.getSize().height - 5; int row = 3; while (row <= height) { int now = (row * 100) / height; if (now <= 35) { if (!mouseOn) { g.setColor(new Color(245 - now, 245 - now, 245 - now)); } else { g.setColor(new Color(160, 160, 160)); g.setColor(new Color(180, 180, 180)); } else { this.setFont(font); this.addMouseListener(this); this.setForeground(new Color(0, 70, 150)); super(text); this.setIcon(icon); this.setButton(); this.setIcon(icon); this.setButton();

Java仿千千静听音乐播放器源代码 自己收集的。

} } } } } g.drawLine(4, row, this.getSize().width - 4, row); if (!mouseOn) { } g.drawLine(4, row, this.getSize().width - 4, row); g.setColor(new Color(140 + now, 140 + now, 140 + now)); g.setColor(new Color(150 + now, 150 + now, 150 + now)); } else { } else { row++; } else { g.setColor(new Color(140, 140, 140)); g.drawLine(3, 2, this.getSize().width - 3, 2); g.drawLine(3, this.getSize().height - 3, this.getSize().width - 3, this.getSize().height - 3); g.drawLine(2, 3, 2, this.getSize().height - 4); g.drawLine(this.getSize().width - 2, 3, this.getSize().width - 2, this.getSize().height - 4); int height = this.getSize().height - 5; int row = 3; while (row <= height) { } int now = (row * 100) / height; if (now <= 35) { } row++; g.setColor(new Color(210 - now, 210 - now, 210 - now)); g.drawLine(4, row, this.getSize().width - 4, row); g.setColor(new Color(110 + now, 110 + now, 110 + now)); g.drawLine(4, row, this.getSize().width - 4, row); } else { super.paintComponent(g); public void paintComponent(Graphics g) { } public void mouseClicked(MouseEvent e) { } super.paintComponent(g);

Java仿千千静听音乐播放器源代码 自己收集的。

} public void mouseReleased(MouseEvent e) { } this.mouseDown = false; this.repaint(); public void mousePressed(MouseEvent e) { } this.mouseDown = true; this.repaint(); public void mouseExited(MouseEvent e) { } this.mouseOn = false; this.setForeground(new Color(0, 70, 150)); this.repaint(); public void mouseEntered(MouseEvent e) { } this.mouseOn = true; this.setForeground(new Color(50, 130, 210)); this.repaint();

LPasswordField.java

package eb.cstop.swing;

import javax.swing.JPasswordField;

import java.awt.event.FocusListener;

import java.awt.event.FocusEvent;

import java.awt.event.KeyListener;

import java.awt.event.KeyEvent;

import java.awt.Color;

import java.awt.event.MouseListener;

import javax.swing.JPopupMenu;

import javax.swing.JMenuItem;

import java.awt.Font;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.ActionEvent;

public class LPasswordField extends JPasswordField implements ActionListener,

FocusListener, KeyListener, MouseListener { private JPopupMenu popup = new JPopupMenu();

Java仿千千静听音乐播放器源代码 自己收集的。

private JMenuItem paste = new JMenuItem(" 粘贴 "); private JMenuItem selectAll = new JMenuItem(" 全选 "); private JMenuItem delete = new JMenuItem(" 删除 ");

private Font font = new Font("宋体", 0, 12);

/**

* 构造函数<br>

*/

public LPasswordField() {

this("");

}

/**

* 构造函数<br>

* column - 占用列长度<br>

*/

public LPasswordField(int column) {

this(column, "");

}

/**

* 构造函数<br>

* column - 占用列长度<br>

* text - 初始本文

*/

public LPasswordField(int column, String text) {

this(text);

this.setColumns(column);

}

/**

* 构造函数<br>

* text - 初始本文

*/

public LPasswordField(String text) {

this.setText(text);

this.addFocusListener(this);

this.addKeyListener(this);

this.addMouseListener(this);

paste.setFont(font);

selectAll.setFont(font);

delete.setFont(font);

paste.addActionListener(this);

selectAll.addActionListener(this);

Java仿千千静听音乐播放器源代码 自己收集的。

} popup.add(paste); popup.add(delete); popup.addSeparator(); popup.add(selectAll); this.setSelectionColor(new Color(0, 80, 140)); this.setSelectedTextColor(Color.white); public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public void actionPerformed(ActionEvent e) { } public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { this.requestFocus(); if (this.getPassword().length < 1) { selectAll.setEnabled(false); delete.setEnabled(false); Object source = e.getSource(); if (source == paste) this.paste(); this.selectAll(); this.replaceSelection(""); else if (source == selectAll) else if (source == delete) if (e.getKeyCode() == KeyEvent.VK_ENTER) { } this.transferFocus(); this.selectAll();

Java仿千千静听音乐播放器源代码 自己收集的。

} } } } popup.show(this, e.getX(), e.getY()); selectAll.setEnabled(true); if (this.getSelectedText() != null) delete.setEnabled(true); delete.setEnabled(false); else public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { }

LTextField.java

package eb.cstop.swing;

import javax.swing.JTextField;

import java.awt.event.FocusListener;

import java.awt.event.FocusEvent;

import java.awt.event.KeyListener;

import java.awt.event.KeyEvent;

import java.awt.Color;

import javax.swing.JMenuItem;

import javax.swing.JPopupMenu;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseEvent;

import java.awt.Font;

public class LTextField extends JTextField implements MouseListener,

FocusListener, KeyListener, ActionListener { private JPopupMenu popup = new JPopupMenu(); private JMenuItem copy = new JMenuItem(" 复制 ");

Java仿千千静听音乐播放器源代码 自己收集的。

private JMenuItem cut = new JMenuItem(" 剪切 "); private JMenuItem paste = new JMenuItem(" 粘贴 "); private JMenuItem selectAll = new JMenuItem(" 全选 "); private JMenuItem delete = new JMenuItem(" 删除 "); private Font font = new Font("宋体", 0, 12); public LTextField() { } public LTextField(int column) { } public LTextField(int column, String text) { } public LTextField(String text) { } public void focusGained(FocusEvent e) { this.setText(text); this.addFocusListener(this); this.addKeyListener(this); this.setSelectionColor(new Color(0, 80, 140)); this.setSelectedTextColor(Color.white); this.addMouseListener(this); copy.setFont(font); cut.setFont(font); paste.setFont(font); selectAll.setFont(font); delete.setFont(font); copy.addActionListener(this); cut.addActionListener(this); paste.addActionListener(this); selectAll.addActionListener(this); delete.addActionListener(this); popup.add(cut); popup.add(copy); popup.add(paste); popup.add(delete); popup.addSeparator(); popup.add(selectAll); this(text); this.setColumns(column); this(column, ""); this("");

Java仿千千静听音乐播放器源代码 自己收集的。

} public void focusLost(FocusEvent e) { } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public void actionPerformed(ActionEvent e) { } public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { this.requestFocus(); if (this.getText().length() < 1) { copy.setEnabled(false); cut.setEnabled(false); selectAll.setEnabled(false); delete.setEnabled(false); copy.setEnabled(true); cut.setEnabled(true); selectAll.setEnabled(true); Object source = e.getSource(); if (source == cut) this.cut(); this.copy(); this.paste(); this.selectAll(); this.replaceSelection(""); else if (source == copy) else if (source == paste) else if (source == selectAll) else if (source == delete) if (e.getKeyCode() == KeyEvent.VK_ENTER) { } this.transferFocus(); } else {

Java仿千千静听音乐播放器源代码 自己收集的。

} } } } delete.setEnabled(true); delete.setEnabled(false); else popup.show(this, e.getX(), e.getY()); public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { }

ProgressBar.java

package eb.cstop.swing;

import javax.swing.JLabel;

import java.awt.*;

import java.awt.event.MouseListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionListener;

import java.util.ArrayList;

import java.awt.event.MouseWheelListener;

import java.awt.event.MouseWheelEvent;

public class ProgressBar extends JLabel implements MouseListener,

MouseMotionListener, MouseWheelListener { private int value = 0; private int minLimit = 0; private int maxLimit = 100; private float alpha = 0.7f; private Color border = new Color(0, 0, 0); private Color color = new Color(250, 160, 0); private ArrayList changeListener = new ArrayList(); private ProgressBarEvent event = new ProgressBarEvent();

Java仿千千静听音乐播放器源代码 自己收集的。

public int getMaxLimit() { public void setMaxLimit(int value) { } if (value > 0) maxLimit = value; maxLimit = 100; else public int getMinLimt() { } return minLimit; public void setMinLimt(int value) { } if (value > 0) minLimit = value; minLimit = 0; else public boolean removeProgressBarListener(ProgressBarListener listener) { } return changeListener.remove(listener); public void addProgressBarListener(ProgressBarListener listener) { } changeListener.add(listener); public float getAlpha() { } return alpha; public void setAlpha(float alpha) { } this.alpha = alpha; this.repaint(); public ProgressBar() { } this.setPreferredSize(new Dimension(-1, 5)); this.addMouseListener(this); this.addMouseMotionListener(this); this.addMouseWheelListener(this);

Java仿千千静听音乐播放器源代码 自己收集的。

} public void setValueForChange(int value) { } public void setValue(int value) { } public int getValue() { } public void setBorderColor(Color border) { return value; if (value == this.value) return; return; return; this.value = value; value = 0; if (value < minLimit) else if (value > maxLimit) if (value >= minLimit) else this.repaint(); ProgressBarListener listener = null; event.setValue(value); event.setComparison((int) (((float) value / maxLimit) * 100.0f)); for (int i = 0; i < changeListener.size(); i++) { } listener = (ProgressBarListener) changeListener.get(i); event.setSource(listener); listener.valueChanged(event); if (value == this.value) return; return; return; this.value = value; value = 0; if (value < minLimit) else if (value > maxLimit) if (value >= minLimit) else this.repaint();

Java仿千千静听音乐播放器源代码 自己收集的。

} this.repaint(); public Color getBorderColor() { } public void setColor(Color color) { } public Color getColor() { } public void paintBorder(Graphics g) { } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { Graphics2D cs = (Graphics2D) g; int width = this.getSize().width; int valueWidth = (int) (((float) value / maxLimit) * (float) width); cs.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); cs.setColor(color); for (int i = 1; i < valueWidth - 1; i++) { } cs.setColor(border); cs.drawRect(0, 0, width - 1, 4); if (i % 2 == 0) { } cs.drawLine(i, 1, i, 1); cs.drawLine(i, 3, i, 3); return color; this.color = color; this.repaint(); return border;

Java仿千千静听音乐播放器源代码 自己收集的。

} } if (e.getButton() == MouseEvent.BUTTON1) { } int comparison = (int) (((float) e.getX() / (this.getSize().width - this .setValue((int) (((float) comparison / 100) * (float) 2)) * (float) 100); maxLimit)); public void mouseReleased(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { } public void mouseWheelMoved(MouseWheelEvent e) { } if (e.getUnitsToScroll() > 0) this.setValue(value - 2); this.setValue(value + 2); else int comparison = (int) (((float) e.getX() / (this.getSize().width - 2)) this.setValue((int) (((float) comparison / 100) * (float) maxLimit)); * (float) 100);

ProgressBarEvent.java

package eb.cstop.swing;

public class ProgressBarEvent {

public int getValue() { } return value; protected void setValue(int value) { } this.value = value; private Object source; private int comparison; private int value;

Java仿千千静听音乐播放器源代码 自己收集的。

}public Object getSource() { return source; } protected void setSource(Object source) { } this.source = source; public int getComparison() { } return comparison; protected void setComparison(int comparison) { } parison = comparison;

ProgressBarListener.java

package eb.cstop.swing;

public interface ProgressBarListener {

}public void valueChanged(ProgressBarEvent e);

RectangleDialog.java

package eb.cstop.swing;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import javax.swing.JDialog;

import java.awt.Frame;

public class RectangleDialog extends JDialog implements MouseListener,

public RectangleDialog() { } this(null); private int beForX = 0; private int beForY = 0; MouseMotionListener {

Java仿千千静听音乐播放器源代码 自己收集的。

} public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } this.setLocation(this.getLocation().x + e.getX() - beForX, this .getLocation().y + e.getY() - beForY); public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } beForX = e.getX(); beForY = e.getY(); public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public RectangleDialog(Frame frame) { } super(frame); this.setUndecorated(true); this.addMouseListener(this); this.addMouseMotionListener(this);

RectangleFrame.java

package eb.cstop.swing;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;

Java仿千千静听音乐播放器源代码 自己收集的。

public class RectangleFrame extends JFrame implements MouseListener,

} public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } this.setLocation(this.getLocation().x + e.getX() - beForX, this .getLocation().y + e.getY() - beForY); public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } beForX = e.getX(); beForY = e.getY(); public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public RectangleFrame() { } this.setUndecorated(true); this.addMouseListener(this); this.addMouseMotionListener(this); protected int beForX = 0; protected int beForY = 0; MouseMotionListener {

SoudPlayer.java

package eb.cstop.swing;

import java.io.*;

import javax.sound.sampled.AudioInputStream;

Java仿千千静听音乐播放器源代码 自己收集的。

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.AudioFormat;

import javax.sound.sampled.DataLine;

import javax.sound.sampled.SourceDataLine;

import javax.sound.sampled.LineUnavailableException;

public class SoudPlayer extends Thread {

public void run() { try { line = (SourceDataLine) AudioSystem.getLine(info); line.open(streamInput.getFormat()); line.start(); private void newObject() { } audioFormat = streamInput.getFormat(); info = new (SourceDataLine.class, audioFormat, 2048); start(); public SoudPlayer(File file) { } try { } streamInput = AudioSystem.getAudioInputStream(file); newObject(); e.printStackTrace(); return; public SoudPlayer(String path) { } File file = new File(path); try { } streamInput = AudioSystem.getAudioInputStreamnewObject(); e.printStackTrace(); return; AudioFormat audioFormat; AudioInputStream streamInput; SourceDataLine line; info; } catch (Exception e) { } catch (Exception e) {

本文来源:https://www.bwwdw.com/article/gu21.html

Top