我正在创建一个简单的视频播放器,但我有问题显示要在JPanel中流式传输的视频文件.我创建并设计了一个JFrame,并在表单中放置了一个方形大小的JPanel.
到目前为止,这是我的代码:
package SoundsTrip;
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
*
* @author jmoreno
*/
public class VideoFrame extends javax.swing.JFrame {
/** Creates new form VideoFrame */
public VideoFrame() {
initComponents();
//this.setExtendedState(VideoFrame.MAXIMIZED_BOTH);
this.setSize(650, 500);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of …Run Code Online (Sandbox Code Playgroud) 当我在其中按下带有for循环事件的jbutton时,其他组件被禁用.
这是我的jbutton代码:
try{
InetAddress localhost = InetAddress.getLocalHost();
byte[] ip = localhost.getAddress();
for(int i=1;i<254;i++){
ip[3]=(byte)i;
final InetAddress address = InetAddress.getByAddress(ip);
if(address.isReachable(1000)){
listModel1.addElement(address);
System.out.println(address + "-Machine is turned on and can be ping.");
Rectangle progressRec = jProgressBar1.getBounds();
progressRec.x = 0;
progressRec.y = 0;
jProgressBar1.setValue(i);
jProgressBar1.paintImmediately(progressRec);
}
}
jList1.setModel(listModel1);
}catch(Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
循环结束后,其他组件是否已启用?我怎么去处理它?提前致谢...
编辑代码:建议不擅长编码
try{
InetAddress localhost = InetAddress.getLocalHost();
final byte[] ip = localhost.getAddress();
SwingWorker<ListModel, InetAddress> worker = new SwingWorker<ListModel, InetAddress>(){
public ListModel doInBackground() throws UnknownHostException, IOException{
for(int i=1;i<254;i++){
ip[3]=(byte)i;
final InetAddress …Run Code Online (Sandbox Code Playgroud)