📄 musiceditor.java
字号:
package musicmgrsys;
import javax.swing.JDialog;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.GridBagLayout;
import java.awt.*;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import javax.swing.JFileChooser;
public class MusicEditor extends JDialog {
MainView mv = null;
public int type = 0; //type==0插入; type==1编辑.
public MusicEditor(MainView mv) {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
this.mv = mv;
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(gridBagLayout1);
this.setModal(true);
this.setResizable(false);
this.setTitle("音乐编辑器");
jLabel1.setText("介质");
jLabel6.setText("发行年");
jLabel7.setText("评价");
jLabel8.setText("注释");
jLabel5.setText("原唱者");
jLabel4.setText("歌曲名");
jLabel3.setText("等级");
jLabel2.setText("种类");
jButton2.setText("取消");
jButton2.addActionListener(new MusicEditor_jButton2_actionAdapter(this));
jButton1.setText("确定");
jButton1.addActionListener(new MusicEditor_jButton1_actionAdapter(this));
jComboBox1.insertItemAt("VHS", 0);
jComboBox1.insertItemAt("DVD", 1);
jComboBox1.insertItemAt("VCD", 2);
jComboBox1.insertItemAt("SVCD", 3);
jComboBox1.insertItemAt("TYPE", 4);
jComboBox1.insertItemAt("MP3", 5);
jComboBox1.insertItemAt("MP4", 6);
jComboBox2.insertItemAt("1", 0);
jComboBox2.insertItemAt("2", 1);
jComboBox2.insertItemAt("3", 2);
jComboBox2.insertItemAt("4", 3);
jComboBox2.insertItemAt("5", 4);
jLabel9.setText("所属音乐集");
String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
String URL = "jdbc:borland:dslocal:";
String FILE = "musicmgrsys.jds";
try
{
Class.forName(DRIVER);
Connection con = DriverManager.getConnection(URL + FILE, "SYSDBA", "masterkey");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select NAME from MUSICSET");
int i = 0;
while(rs.next())
{
jComboBox3.insertItemAt(rs.getString("NAME"), i++);
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.toString());
}
jButton3.setText("...");
jButton3.addActionListener(new MusicEditor_jButton3_actionAdapter(this));
jLabel10.setText("路径");
this.getContentPane().add(jComboBox3,
new GridBagConstraints(4, 2, 5, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(19, 16, 0, 17), 97, -1));
this.getContentPane().add(jLabel3,
new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(17, 13, 0, 0), 7, 7));
this.getContentPane().add(jLabel9,
new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(19, 12, 0, 0), 3, 7));
this.getContentPane().add(jTextField4,
new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(20, 33, 0, 0), 65, 1));
this.getContentPane().add(jLabel6,
new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(19, 17, 0, 0), 2, 8));
this.getContentPane().add(jTextField3,
new GridBagConstraints(6, 1, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(34, 13, 0, 17), 84, 2));
this.getContentPane().add(jLabel5,
new GridBagConstraints(3, 1, 2, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(32, 21, 0, 0), 5, 9));
this.getContentPane().add(jTextField2,
new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(33, 33, 0, 0), 100, 3));
this.getContentPane().add(jLabel4,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(32, 17, 0, 0), 6, 10));
this.getContentPane().add(jTextField1,
new GridBagConstraints(3, 0, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(17, 12, 0, 0), 53, 0));
this.getContentPane().add(jLabel2,
new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(17, 11, 0, 0), 0, 7));
this.getContentPane().add(jLabel1,
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(17, 17, 0, 10), 4, 8));
this.getContentPane().add(jComboBox2,
new GridBagConstraints(7, 0, 2, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(17, 0, 0, 17), 33, -3));
this.getContentPane().add(jComboBox1,
new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(17, 0, 0, 22), 34, -3));
this.getContentPane().add(jButton1,
new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(27, 35, 17, 0), 17, 0));
this.getContentPane().add(jButton2,
new GridBagConstraints(5, 6, 3, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(28, 0, 17, 0), 24, -1));
this.getContentPane().add(jTextArea2,
new GridBagConstraints(1, 5, 8, 1, 1.0, 1.0
, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(21, 33, 0, 17), 295, 9));
this.getContentPane().add(jLabel8,
new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(30, 17, 0, 0), 14, 4));
this.getContentPane().add(jTextArea1,
new GridBagConstraints(1, 4, 8, 1, 1.0, 1.0
, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 33, 0, 17), 295, 61));
this.getContentPane().add(jLabel7,
new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(11, 17, 58, 0), 15, 6));
this.getContentPane().add(jTextField5,
new GridBagConstraints(1, 3, 7, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(13, 33, 0, 7), 237, 3));
this.getContentPane().add(jLabel10,
new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(12, 17, 0, 0), 14, 11));
this.getContentPane().add(jButton3,
new GridBagConstraints(8, 3, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(13, 0, 0, 17), -12, -1));
}
JLabel jLabel1 = new JLabel();
public JComboBox jComboBox1 = new JComboBox();
JLabel jLabel2 = new JLabel();
public JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
public JComboBox jComboBox2 = new JComboBox();
JLabel jLabel4 = new JLabel();
public JTextField jTextField2 = new JTextField();
JLabel jLabel5 = new JLabel();
public JTextField jTextField3 = new JTextField();
JLabel jLabel6 = new JLabel();
public JTextField jTextField4 = new JTextField();
JLabel jLabel7 = new JLabel();
public JTextArea jTextArea1 = new JTextArea();
JLabel jLabel8 = new JLabel();
public JTextArea jTextArea2 = new JTextArea();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel9 = new JLabel();
public JComboBox jComboBox3 = new JComboBox();
JLabel jLabel10 = new JLabel();
public JTextField jTextField5 = new JTextField();
JButton jButton3 = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JFileChooser jFileChooser1 = new JFileChooser();
public void jButton1_actionPerformed(ActionEvent e) {
String format = jComboBox1.getSelectedItem().toString();
String gerue = jTextField1.getText();
int rating = Integer.parseInt(jComboBox2.getSelectedItem().toString());
String evaluation = jTextArea1.getText();
String title = jTextField2.getText();
String director = jTextField3.getText();
int year = Integer.parseInt(jTextField4.getText());
String comments = jTextArea2.getText();
String name = jComboBox3.getSelectedItem().toString();
String location = jTextField5.getText();
String tabname = null;
String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
String URL = "jdbc:borland:dslocal:";
String FILE = "musicmgrsys.jds";
try
{
Class.forName(DRIVER);
Connection con = DriverManager.getConnection(URL + FILE, "SYSDBA", "masterkey");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select TABNAME from MUSICSET where NAME='" + name + "'");
while(rs.next())
{
tabname = rs.getString("TABNAME");
}
rs.close();
stmt.close();
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex.toString());
}
Music music = new Music();
music.setFormat(format);
music.setGerue(gerue);
music.setRating(rating);
music.setEvaluation(evaluation);
music.setTitle(title);
music.setDirector(director);
music.setYear(year);
music.setComments(comments);
music.setLocation(location);
for(MusicModel i : mv.getList())
{
if(i.getTabname().equalsIgnoreCase(tabname))
{
i.connectDB();
if(type == 0)
{
i.addMusic(music);
}
else if(type == 1)
{
i.editMusic(title, music);
mv.musicItemView1.getTextArea().setText("");
mv.musicItemView1.getTextArea().append("格式: " + music.getFormat() + "\n");
mv.musicItemView1.getTextArea().append("种类: " + music.getGerue() + "\n");
mv.musicItemView1.getTextArea().append("等级: " + music.getRating() + "\n");
mv.musicItemView1.getTextArea().append("评价: " + music.getEvaluation() + "\n");
mv.musicItemView1.getTextArea().append("标题: " + music.getTitle() + "\n");
mv.musicItemView1.getTextArea().append("原唱: " + music.getDirector() + "\n");
mv.musicItemView1.getTextArea().append("年份: " + music.getYear() + "\n");
mv.musicItemView1.getTextArea().append("注释: " + music.getComments() + "\n");
mv.musicItemView1.getTextArea().append("路径: " + music.getLocation() + "\n");
}
i.closeDB();
}
}
this.dispose();
}
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
public void jButton3_actionPerformed(ActionEvent e) {
if(JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this))
{
jTextField5.setText(jFileChooser1.getSelectedFile().getPath());
}
}
}
class MusicEditor_jButton3_actionAdapter implements ActionListener {
private MusicEditor adaptee;
MusicEditor_jButton3_actionAdapter(MusicEditor adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class MusicEditor_jButton2_actionAdapter implements ActionListener {
private MusicEditor adaptee;
MusicEditor_jButton2_actionAdapter(MusicEditor adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class MusicEditor_jButton1_actionAdapter implements ActionListener {
private MusicEditor adaptee;
MusicEditor_jButton1_actionAdapter(MusicEditor adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -