java - Changing an Icon in a JLabel dynamically -


i having bit of problem changing , icon in jlabel dynamically. first of all, trying simulating screen sharing operation. on client side, taking screenshots every second, sending them server. on server side, trying open these pictures in simple gui.

i able send pictures without problem , able them without problem well. however, gui code have written cannot open pictures. more specifically, if there picture, able open it, not open picture has come.

what doing in server side is, picture gets server, saving predetermined name. , able open picture windows' own picture photo viewer. in fact, new picture comes, photo viewer updates , shows new screenshot.

however, having trouble opening screenshots in jframe. have written program take screenshots in jpg format, send them server , open them in gui. having problems opening in gui part. have understood, not open files coming client.

below codes, appreciated.

server side,

 package screencap;  /*  * change template, choose tools | templates  * , open template in editor.  */ import fileserver.*; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstream; import java.net.serversocket; import java.net.socket; import java.util.logging.level; import java.util.logging.logger; import test.tsgicons;   /**  *  * @author busra  */ public class screencapserver extends thread{     string filepath;     int portnumber;     fileserver screencapserver;     serversocket getfileserver;      socket getfile;      inputstream in;     fileoutputstream fileoutputstream;     tsgicons screenshoticons;      public screencapserver(string path, int port) {         this.filepath = path;         this.portnumber = port;         this.screenshoticons = new tsgicons();     }       public static void waittime(long millisecond){           long max = millisecond;           for(long = 0;  < max; i++){               for(long j = 0;  j < max; j++){                }           }       }            public void run() {         while(true) {             try {                 for(int = 0; < 10; i++) {                     getfileserver = new serversocket(portnumber);                     getfile = getfileserver.accept();                     in = getfile.getinputstream();                     fileoutputstream = new fileoutputstream(filepath + "\\" + + ".jpg");                     byte [] buffer = new byte[64*1024];                      int bytesread = 0;                     while ( (bytesread = in.read(buffer)) != -1) {                         fileoutputstream.write(buffer, 0, bytesread);                     }                                      in.close();                     fileoutputstream.close();                     getfileserver.close();                     screenshoticons.update();                 }             } catch (ioexception ex) {                 ex.printstacktrace();              }         }         }   } 

gui,

    package test;  import java.awt.borderlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.timer;  public class tsgicons extends jframe implements actionlistener {     protected timer timer;     protected jlabel viewicon;     private string[] smiley = {"orig_screen"};     private string button = "button";     private int timecount;     private int iconnumber;     private string image;      public tsgicons() {         this(1, 100);     }      public tsgicons(int initialtime, int delay) {         super("tsg smileys");         this.timecount = initialtime;         this.iconnumber = this.timecount % this.smiley.length;         this.image = "transferredscreenshots\\" + this.smiley[this.iconnumber] + ".jpg";         this.viewicon = new jlabel();         this.viewicon.seticon(new javax.swing.imageicon(this.image));         this.timer = new timer(delay, this);         this.init();     }      protected void init() {         jbutton button = new jbutton("start / stop");         button.setactioncommand(button);         button.addactionlistener(this);         this.viewicon.sethorizontalalignment(jlabel.center);         this.getcontentpane().add(button, borderlayout.south);         this.getcontentpane().add(this.viewicon, borderlayout.center);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.setlocation(250, 250);         this.pack();          this.setvisible(true);     }      @override     public void actionperformed(actionevent e) {         if ( button.equals(e.getactioncommand()) )  { // test if button clicked             if ( this.timer.isrunning() ) {                 this.timer.stop();             } else {                 this.timer.start();             }         } else         {   this.timecount++;                 this.iconnumber = this.timecount % this.smiley.length;                 this.image = "transferredscreenshots\\" + this.smiley[this.iconnumber] + ".jpg";                 this.viewicon.seticon(new javax.swing.imageicon(this.image));         }     }      public void update() {         this.timecount++;         this.iconnumber = this.timecount % this.smiley.length;         this.image = "transferredscreenshots\\" + this.smiley[this.iconnumber] + ".jpg";         this.viewicon.seticon(new javax.swing.imageicon(this.image));      }      public static void main(string argv []) {         new tsgicons();     } } 


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -