gpt4 book ai didi

java - 如何引用 JTABLE 的第一列并为该列中单击的每一行添加操作?

转载 作者:行者123 更新时间:2023-12-02 13:18:20 25 4
gpt4 key购买 nike

我对编程很陌生,如果这是一个非常愚蠢的问题,我深表歉意。我有一个包含列的表 - 音频(Blob)、标题和艺术家姓名。我希望用户在按下音频单元格然后按下播放按钮时能够播放歌曲。我很难尝试引用保存音频的特定列行。这是我一直试图学习的链接,但我一无所获。 How can I determine which cell in a JTable was selected? 。如何引用这些项目,以便在单击第 1 行时从该文件中提取音频以便可以播放?我会写一个for循环吗?我知道如何播放这首歌,只是无法让它引用索引本身。英语不是我的母语,如果没有很好地解释,我很抱歉。

编辑:

`JTable table;
File sound;
AudioInputStream ais;
Clip clip;
table.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
try{
int row = table.getSelectedRow();
String selectedItem=(String) table.getValueAt(row,0);
sound= new File(selectedItem);
ais= AudioSystem.getAudioInputStream(sound);
clip= AudioSystem.getClip();
clip.open(ais);
clip.start();
}

catch(Exception exp ){
JOptionPane.showMessageDialog(null, exp);
}
}});

当我点击该行时,我想让它播放歌曲,但我得到一个 fileNotFoundException。提取文件的方法不正确吗?

最佳答案

I just can't get it to refer to the index itself.

我不明白这个问题。

您从其他帖子中看到您可以使用:

int row = table.getSelectedRow();

您将数据加载到表中,您知道哪列包含您要播放的歌曲的文件名,因此您只需执行以下操作:

String filename = table.getValueAt(row, ???);

I know how to play the song

然后你就可以播放这首歌了。

关于java - 如何引用 JTABLE 的第一列并为该列中单击的每一行添加操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43682908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com