SuperVCD管理系统 java版完整代码 带各种注释....
更新时间:2023-06-01 18:26:01 阅读量: 实用文档 文档下载
- supervc多少钱推荐度:
- 相关推荐
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
表2-2 数据服务类列表
表2-3 工具类列表
表2-4 其他
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
MainFrame
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* StoneForest应用的主框架
*/
public class MainFrame extends JFrame {
/**
* tabbed pane组件
*/
protected JTabbedPane tabbedPane;
/**
* 音乐CD panel
*/
protected MusicPanel musicPanel;
/**
* 默认构造方法
*/
public MainFrame() {
setTitle("欢迎使用StoneForest应用! ");
Container container = this.getContentPane();
container.setLayout(new BorderLayout());
tabbedPane = new JTabbedPane();
musicPanel = new MusicPanel(this);
tabbedPane.addTab("音乐", musicPanel);
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
container.add(BorderLayout.CENTER, tabbedPane); JMenuBar myMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu("文件"); JMenu openMenu = new JMenu("打开"); JMenuItem localMenuItem = new JMenuItem("本地硬盘..."); openMenu.add(localMenuItem); JMenuItem networkMenuItem = new JMenuItem("网络..."); openMenu.add(networkMenuItem); JMenuItem webMenuItem = new JMenuItem("互联网..."); openMenu.add(webMenuItem); fileMenu.add(openMenu); JMenuItem saveMenuItem = new JMenuItem("保存"); fileMenu.add(saveMenuItem); JMenuItem exitMenuItem = new JMenuItem("退出"); fileMenu.add(exitMenuItem); myMenuBar.add(fileMenu); exitMenuItem.addActionListener(new ExitActionListener()); setupLookAndFeelMenu(myMenuBar); JMenu helpMenu = new JMenu("帮助"); JMenuItem aboutMenuItem = new JMenuItem("关于"); helpMenu.add(aboutMenuItem); myMenuBar.add(helpMenu); aboutMenuItem.addActionListener(new AboutActionListener()); this.setJMenuBar(myMenuBar); setSize(500, 400); setLocation(100, 100);
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
this.addWindowListener(new WindowCloser());
fileMenu.setMnemonic('f');
exitMenuItem.setMnemonic('x');
helpMenu.setMnemonic('h');
aboutMenuItem.setMnemonic('a');
//设定快捷键
exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
ActionEvent.CTRL_MASK));
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
ActionEvent.CTRL_MASK));
aboutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
ActionEvent.CTRL_MASK));
}
/**
* 设定和选择外观
*
*/
protected void setupLookAndFeelMenu(JMenuBar theMenuBar) {
UIManager.LookAndFeelInfo[] lookAndFeelInfo
UIManager.getInstalledLookAndFeels();
JMenu lookAndFeelMenu = new JMenu("选项");
JMenuItem anItem = null;
LookAndFeelListener myListener = new LookAndFeelListener();
try {
for (int i=0; i < lookAndFeelInfo.length; i++) {
anItem = new JMenuItem(lookAndFeelInfo[i].getName() + " 外观"); anItem.setActionCommand(lookAndFeelInfo[i].getClassName());
anItem.addActionListener(myListener);
lookAndFeelMenu.add(anItem);
}
}
catch (Exception e) {
e.printStackTrace();
}
theMenuBar.add(lookAndFeelMenu); =
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
} /** * 退出方法. */ public void exit() { } setVisible(false); dispose(); System.exit(0); /** * "退出"事件处理内部类. */ class ExitActionListener implements ActionListener { public void actionPerformed(ActionEvent event) { exit(); } } /** * "关闭窗口"事件处理内部类. */ class WindowCloser extends WindowAdapter { } /** * let's call our exit() method defined above */ public void windowClosing(WindowEvent e) { } exit(); /** * "外观"选择监听类 * */ class LookAndFeelListener implements ActionListener {
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
public void actionPerformed(ActionEvent event) {
String className = event.getActionCommand();
try {
UIManager.setLookAndFeel(className);
SwingUtilities.updateComponentTreeUI(MainFrame.this);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* "关于"菜单监听类
*/
class AboutActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
String msg = "StoneForest 超值享受!";
JOptionPane.showMessageDialog(MainFrame.this, msg);
}
}
}
MusicPanel
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
/**
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
* 这个类构建CD面板
*/
public class MusicPanel extends JPanel {
protected JLabel selectionLabel;
protected JComboBox categoryComboBox;
protected JPanel topPanel;
protected JList musicListBox;
protected JScrollPane musicScrollPane;
protected JButton detailsButton;
protected JButton clearButton;
protected JButton exitButton;
protected JPanel bottomPanel;
protected MainFrame parentFrame;
protected ArrayList musicArrayList;
protected MusicDataClient myDataClient;
public MusicPanel(MainFrame theParentFrame) {
try {
parentFrame = theParentFrame;
myDataClient = new MusicDataClient();
selectionLabel = new JLabel("选择音乐目录");
categoryComboBox = new JComboBox();
categoryComboBox.addItem("-------");
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
ArrayList categoryArrayList = myDataClient.getCategories(); Iterator iterator = categoryArrayList.iterator(); String aCategory; while (iterator.hasNext()) { } aCategory = (String) iterator.next(); categoryComboBox.addItem(aCategory); topPanel = new JPanel(); musicListBox = new JList(); musicListBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); musicScrollPane = new JScrollPane(musicListBox); detailsButton = new JButton("详细..."); clearButton = new JButton("清空"); exitButton = new JButton("退出"); bottomPanel = new JPanel(); this.setLayout(new BorderLayout()); topPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); topPanel.add(selectionLabel); topPanel.add(categoryComboBox); this.add(BorderLayout.NORTH, topPanel); this.add(BorderLayout.CENTER, musicScrollPane); bottomPanel.setLayout(new FlowLayout()); bottomPanel.add(detailsButton); bottomPanel.add(clearButton); bottomPanel.add(exitButton); this.add(BorderLayout.SOUTH, bottomPanel); detailsButton.addActionListener(new DetailsActionListener()); clearButton.addActionListener(new ClearActionListener());
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
exitButton.addActionListener(new ExitActionListener());
categoryComboBox.addItemListener(new GoItemListener());
musicListBox.addListSelectionListener(new MusicListSelectionListener());
detailsButton.setEnabled(false);
clearButton.setEnabled(false);
}
catch (IOException exc) {
JOptionPane.showMessageDialog(this, "网络问题 " + exc, "网络问题", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
protected void populateListBox() {
try {
String category = (String) categoryComboBox.getSelectedItem();
if (! category.startsWith("---")) {
musicArrayList = myDataClient.getRecordings(category);
}
else {
musicArrayList = new ArrayList();
}
Object[] theData = musicArrayList.toArray();
musicListBox.setListData(theData);
if (musicArrayList.size() > 0) {
clearButton.setEnabled(true);
}
else {
clearButton.setEnabled(false);
}
}
catch (IOException exc) {
JOptionPane.showMessageDialog(this, "网络问题: " + exc, "网络问题", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
class GoActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
populateListBox();
}
}
class DetailsActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
int index = musicListBox.getSelectedIndex();
MusicRecording myMusicRecording = (MusicRecording) musicArrayList.get(index);
MusicDetailsDialog myDetailsDialog = new MusicDetailsDialog(parentFrame, myMusicRecording);
myDetailsDialog.setVisible(true);
}
}
class ExitActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
parentFrame.exit();
}
}
class ClearActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
Object[] noData = new Object[1];
musicListBox.setListData(noData);
categoryComboBox.setSelectedIndex(0);
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
}
}
class GoItemListener implements ItemListener {
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
populateListBox();
}
}
}
class MusicListSelectionListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
if (musicListBox.isSelectionEmpty()) {
detailsButton.setEnabled(false);
}
else {
detailsButton.setEnabled(true);
}
}
}
}
MusicDetailsDialog
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
/**
* 这个类显示CD详细信息对话框
*/
public class MusicDetailsDialog extends JDialog {
protected MusicRecording myRecording;
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
protected Frame parentFrame;
public MusicDetailsDialog(Frame theParentFrame, MusicRecording theMusicRecording) {
this(theParentFrame, "光盘详细信息 " + theMusicRecording.toString(), theMusicRecording);
}
public MusicDetailsDialog(Frame theParentFrame, String theTitle, MusicRecording theMusicRecording) {
super(theParentFrame, theTitle, true);
myRecording = theMusicRecording;
parentFrame = theParentFrame;
buildGui();
}
private void buildGui() {
Container container = this.getContentPane();
container.setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
JPanel infoPanel = new JPanel();
infoPanel.setBorder(new EmptyBorder(10, 10, 0, 10));
infoPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 3;
c.weightx = 0.0;
c.weighty = 0.0;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.WEST;
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
c.insets = new Insets(10, 0, 2, 10); JLabel artistLabel = new JLabel("歌手: " + myRecording.getArtist()); artistLabel.setForeground(Color.black); infoPanel.add(artistLabel, c); c.gridy = GridBagConstraints.RELATIVE; c.insets = new Insets(2, 0, 10, 10); JLabel titleLabel = new JLabel("歌名: " + myRecording.getTitle()); titleLabel.setForeground(Color.black); infoPanel.add(titleLabel, c); JLabel categoryLabel = new JLabel("类别: " + myRecording.getCategory()); c.insets = new Insets(2, 0, 2, 0); categoryLabel.setForeground(Color.black); infoPanel.add(categoryLabel, c); Duration theDuration = myRecording.getDuration(); int runningTime = theDuration.getTotalSeconds() / 60; JLabel durationLabel = new JLabel("长度: " + runningTime + " 分."); durationLabel.setForeground(Color.black); infoPanel.add(durationLabel, c); JLabel priceLabel = new JLabel("价格: " + myRecording.getPrice() ); c.insets = new Insets(10, 0, 2, 0); priceLabel.setForeground(Color.black); infoPanel.add(priceLabel, c); c.gridx = 3; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 5; c.fill = GridBagConstraints.NONE; c.weightx = 1.0; c.weighty = 1.0; c.insets = new Insets(5, 5, 20, 0); String imageName = myRecording.getImageName(); ImageIcon recordingIcon = null; JLabel recordingLabel = null; // 读取图片 try { if (imageName.trim().length() == 0) { recordingLabel = new JLabel(" 图片不存在 ");
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
}
else {
recordingIcon = new ImageIcon(getClass().getResource("images/music/" + imageName));
recordingLabel = new JLabel(recordingIcon);
}
}
catch (Exception exc)
{
recordingLabel = new JLabel(" 图片不存在 ");
}
recordingLabel.setBorder(BorderFactory.createRaisedBevelBorder());
recordingLabel.setToolTipText(myRecording.getArtist());
infoPanel.add(recordingLabel, c);
container.add(BorderLayout.NORTH, infoPanel);
Track[] tracksArray = myRecording.getTrackList();
JList tracksListBox= new JList(tracksArray);
JScrollPane tracksScrollPane = new JScrollPane(tracksListBox);
TitledBorder listBorder = BorderFactory.createTitledBorder("List of Tracks"); listBorder.setTitleColor(Color.black);
tracksScrollPane.setBorder(listBorder);
container.add(BorderLayout.CENTER, tracksScrollPane);
JPanel bottomPanel = new JPanel();
JButton okButton = new JButton("OK");
bottomPanel.add(okButton);
container.add(BorderLayout.SOUTH, bottomPanel);
okButton.addActionListener(new OkButtonActionListener());
this.pack();
Point parentLocation = parentFrame.getLocation();
this.setLocation(parentLocation.x + 50, parentLocation.y + 50);
}
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
/**
* 处理按钮的内部类
*/
class OkButtonActionListener implements ActionListener {
public void actionPerformed(ActionEvent event)
{
setVisible(false);
}
}
}
DataAccessor
import java.util.*;
/**
* 这个抽象类定义了如何读取一个数据文件。
具体的CD信息
*
*/
public abstract class DataAccessor {
/**
* 存放CD信息的HashMap/hashtable .
*
*/
protected HashMap dataTable;
/**
* 最近增加的CD集合
*
*/
protected ArrayList recentRecordingList;
/**
* 默认构造方法
*/
public DataAccessor() {
dataTable = new HashMap();
recentRecordingList = new ArrayList();
}
它提供的方法可以用来获得CD的分类和
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
/** * 获得CD分类集合 */ public ArrayList getCategories() { Set categorySet = dataTable.keySet(); log("获得分类..."); } ArrayList categories = new ArrayList(categorySet); // 排序 Collections.sort(categories); log("完成获得分类!\n"); return categories; /** * 获得某类CD的集合 * * @param 类别 */ public ArrayList getRecordings(String category) { ArrayList recordingList = null; log("获得CD集合信息, 它们属于: " + category); recordingList = (ArrayList) dataTable.get(category); } /** // 排序 Collections.sort(recordingList); log("完成获得CD集合信息!\n"); return recordingList;
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
* 在内存中增加新的CD
*
* @param 被增加的CD
*
*/
public void addRecording(Recording theRecording) {
String category = theRecording.getCategory();
log("添加新的CD: " + theRecording);
ArrayList recordingList = (ArrayList) dataTable.get(category);
recordingList.add(theRecording);
recentRecordingList.add(theRecording);
log("完成添加新的CD!\n");
}
/**
* 从文件中读取数据
*/
public abstract void load();
/**
* 向文件中保存数据
*/
public abstract void save();
/**
* 日志方法.
*/
protected void log(Object msg) {
System.out.println("数据存取类 Data Accessor: " + msg);
}
}
Handler
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
import java.io.*;
import .*;
import java.util.*;
/**
* 这个类是socket连接的处理器
* 例如:
* <pre>
* Handler aHandler = new Handler(clientSocket, myMusicDataAccessor);
* aHandler.start();
* </pre>
*
*
*/
public class Handler extends Thread implements StoneForestProtocol {
protected Socket clientSocket;
protected ObjectOutputStream outputToClient;
protected ObjectInputStream inputFromClient;
protected MusicDataAccessor myMusicDataAccessor;
protected boolean done;
public Handler(Socket theClientSocket, MusicDataAccessor theMusicDataAccessor) throws IOException {
clientSocket = theClientSocket;
outputToClient = new ObjectOutputStream(clientSocket.getOutputStream()); inputFromClient = new ObjectInputStream(clientSocket.getInputStream());
myMusicDataAccessor = theMusicDataAccessor;
done = false;
}
public void run() {
try {
while (!done) {
log("等待命令...");
int opCode = inputFromClient.readInt();
log("opCode = " + opCode);
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
} switch(opCode) { case StoneForestProtocol.OP_GET_MUSIC_CATEGORIES: opGetMusicCategories(); break; case StoneForestProtocol.OP_GET_MUSIC_RECORDINGS: opGetMusicRecordings(); break; default: System.out.println("错误代码"); } } } catch (IOException exc) { log(exc); } protected void opGetMusicCategories() { try { ArrayList categoryList = myMusicDataAccessor.getCategories(); outputToClient.writeObject(categoryList); outputToClient.flush(); log("发出 " + categoryList.size() + " 类别信息到客户端到客户端."); } catch (IOException exc) { log("发生异常: " + exc); } } protected void opGetMusicRecordings() { try { log("读取份类信息"); String category = (String) inputFromClient.readObject(); log("类别是 " + category); ArrayList recordingList = myMusicDataAccessor.getRecordings(category); outputToClient.writeObject(recordingList); outputToClient.flush(); log("发出 " + recordingList.size() + " CD信息到客户端.");
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
}
catch (IOException exc) {
log("发生异常: " + exc);
exc.printStackTrace();
}
catch (ClassNotFoundException exc) {
log("发生异常: " + exc);
exc.printStackTrace();
}
}
public void setDone(boolean flag) {
done = flag;
}
protected void log(Object msg) {
System.out.println("处理器: " + msg);
}
}
MusicDataAccessor
import java.util.*;
import java.io.*;
/**
* 音乐CD数据读取的实现类
*
*/
public class MusicDataAccessor extends DataAccessor {
//////////////////////////////////////////////////////
//
// 文件格式如下
// 歌手姓名, 唱片名, 类别, 图片名, 歌曲数目
// 歌曲 #1, 总秒数
// 歌曲 #2, 总秒数
// ----------------------------
//
SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
/////////////////////////////////////////////////////// /** * 数据文件名 */ protected static final String FILE_NAME = "music.db"; /** * 纪录的分割符 */ protected static final String RECORD_SEPARATOR = "----------"; /** * 默认构造方法 * */ public MusicDataAccessor() { load(); } /** * 读取数据的方法 */ public void load() { dataTable = new HashMap(); ArrayList musicArrayList = null; StringTokenizer st = null; MusicRecording myRecording; String line = ""; String artist, title; String category, imageName; int numberOfTracks; int basePrice; double price; Track[] trackList; try { log("读取文件: " + FILE_NAME + "...");
正在阅读:
SuperVCD管理系统 java版完整代码 带各种注释....06-01
2018年金融理财师AFP证书结业作业试题及参考答案11-20
教科版2018年科学作业本参考答案04-10
PS制作网页效果图—漂亮的绿色首页模板03-03
平面设计师岗位说明书03-16
百度大班上学期安全总结12-29
第一章:微机基础知识05-21
江苏省高考语文大一轮复习第1部分语言文字运用第1章语言基础知识05-15
江苏考研网:2016江苏考研成绩查询02-08
各工种安全技术交底记录07-02
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 注释
- SuperVCD
- 管理系统
- 完整
- 各种
- 代码
- java