import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.Socket;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author ipopp
*/
public class imageClientPanel {
public static BufferedImage image;
public static JPanel panel;
public static void main (String[] args) {
JFrame frame = new JFrame("test");
frame.setSize(800,600);
frame.add(panel = new JPanel() {
@Override
public void paintComponent(Graphics graphics) {
super.paintComponents(graphics);
if(image != null) {
graphics.drawImage(image, 0, 0, this);
} else {
graphics.setColor(Color.black);
graphics.fillRect(0,0,800,600);
}
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
try {
Socket socket = new Socket("127.0.0.1",9090);
BufferedInputStream ins = new BufferedInputStream(socket.getInputStream());
int bytesRead =0;
byte[] buffer = new byte[128];
while(true) {
BufferedImage tmpImage = ImageIO.read(ins);
if (tmpImage != null)
{
image = tmpImage;
panel.repaint();
}
}
} catch (IOException el) {
}
}
}
Komentar
Posting Komentar