Reloading and redisplay images using JScrollPane

I am using
Java platform:jdk 1.4.1
Windows platform: Windows 98se
Problem:I am making one application in which i need to display images when i get
it from socket.I had used one JScrollPane over JPanel with scrollbars.But when i get the image i stored it into an Image object.
such as in my main program
screen = Toolkit.getDefaultToolkit().getImage ( "screen.jpg" );
//Draw picture first time it works fine...
paintPicture(screen);
paintPicture(Image image)
     {picpnl = new JPanel();
     picpnl.setLayout(new BorderLayout());
        image = Toolkit.getDefaultToolkit(  ).getImage(image);
//Is picpnl is unable to display image second time       
      picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
        c.add( picpnl, BorderLayout.CENTER );
        picpnl.setVisible(true);
from my refresh code:
       if(image!=null)
          image.flush();
       Runtime rt = Runtime.getRuntime();
       rt.runFinalization();
       rt.gc();
       image = null;
//is this 2nd time image not properly stored in variable image
       image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );
       paintPicture(image);
//go to paintPicture second time doesn't work
class ImageComponent extends JComponent {
  Image image;
  Dimension size;
  public ImageComponent(Image image) {
    this.image = image;
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
      mt.waitForAll(  );
catch (InterruptedException e) {
// error ...
size = new Dimension (image.getWidth(null),
image.getHeight(null));
setSize(size);}
public void paint(Graphics g) {
     g.drawImage(image, 0, 0, this);
public Dimension getPreferredSize( ) {
return size;
The above code works fine for (the first time).But when i try to display a different socket image (the second time) it doesn't work.
I didn't know what the problem is...
---whether the previous image didn't get erased from RAM or
---the OS is not aware of the current changed image in variable (image) or the
---JScrollPane is unable to redraw it second time.
How can i display one changed image from the socket onto the JScrollPane? (the second time).
Also i want to know if we are using one file with the name "screen.jpg" and at runtime if i changed that file with another file with the same name. How can i display that changed file?Is it possible in Java or not.(Is it the limitation of Java).
I totally get frustated by reading all forums but i didn't get the answer.Please reply me soon with the complete code?
The complete source code for the problem:
(SERVER):
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class Remote extends JFrame
private JPanel btnpnl,picpnl;
private JButton button[];
private UIManager.LookAndFeelInfo looks[];
private static int change = 1;
private JLabel label1;
private Icon icon[];
private String names[] = { "looks","connect","control", "refresh", "auto",    "commands" };
private String iconnames[] = { "gifs/look.gif","gifs/connect.gif","gifs/control.gif","gifs/refresh.gif","gifs/auto.gif","gifs/command.gif" };
private String looknames[] = { "Motif", "Windows", "Metal" };
private int port=5000;
private ScrollablePicture picture=null;
private ServerSocket server;
private Socket client;
private ObjectInputStream ins = null;
private ObjectOutputStream ous = null;
private File file;
private String fileName;
private boolean autocontrol=true;
private Image image=null;
private Container c;
     public remote()
          super( "Remote Desktop" );
c = getContentPane();
          c.setLayout( new BorderLayout() );
//String file = "screen.jpg";
looks = UIManager.getInstalledLookAndFeels();
          btnpnl = new JPanel();
          btnpnl.setLayout( new FlowLayout() );
          button = new JButton[names.length];
          icon = new ImageIcon[iconnames.length];
          Buttonhandler handler = new Buttonhandler();
          for( int i=0; i<names.length; ++i )
icon[i] = new ImageIcon( iconnames[i] );
               button[i] = new JButton( names, icon[i] );
               button[i].addActionListener(handler);
btnpnl.add(button[i]);
          c.add( btnpnl, BorderLayout.NORTH );
          //Adding Label1
          label1 = new JLabel("LABEL1");
          c.add( label1, BorderLayout.SOUTH );
picpnl = new JPanel();
     picpnl.setLayout(new BorderLayout());
          //image = Toolkit.getDefaultToolkit( ).getImage(file);
// paintPicture(image);
          c.add( picpnl, BorderLayout.CENTER );
          //setResizable(false);
          setSize( 808, 640 );
          show();
public void paintPicture(Image image)
picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
picpnl.setVisible(true);
public class Buttonhandler implements ActionListener
          public void actionPerformed( ActionEvent e )
try{
               if( e.getActionCommand() == "looks" )
try
               label1.setText( Integer.toString( change ) );
          UIManager.setLookAndFeel( looks[change++].getClassName() );
                    SwingUtilities.updateComponentTreeUI(remote.this);
               if(change==3)
                    change=0;
catch (Exception ex)
ex.printStackTrace();
               if( e.getActionCommand() == "connect" )
                    label1.setText( "connect" );
runServer();
               if( e.getActionCommand() == "refresh" )
                    label1.setText( "refresh" );
                    ous.writeObject("refresh");
                    ous.flush();
                    recieveFile();
               if( e.getActionCommand() == "auto" )
                    label1.setText( "auto" );
                    ous.writeObject("auto");
                    button[4].setText("stop");
                    ous.flush();
                    setButton(false,false,false,false,true,false);
               auto();
               if( e.getActionCommand() == "stop" )
                    ous.writeObject("stop");
                    ous.flush();
                    button[4].setText("auto");
                    setButton(true,true,true,true,true,true);
               autocontrol=false;
          catch(Exception ef)
               ef.getMessage();
     public void auto()
          while(autocontrol)
recieveFile();
     public void setButton( boolean b1, boolean b2, boolean b3, boolean b4, boolean b5, boolean b6)
          button[0].setEnabled(b1);
          button[1].setEnabled(b2);
          button[2].setEnabled(b3);
          button[3].setEnabled(b4);
          button[4].setEnabled(b5);
          button[5].setEnabled(b6);
     public void recieveFile()
     int flag = 0;
          try{
               while(flag<=2){
               Object recieved = ins.readObject();
               System.out.println("from client:" + recieved);
switch (flag) {
case 0:
if (recieved.equals("sot")) {
System.out.println("sot recieved");
                                   flag++;
break;
               case 1:
fileName = (String) recieved;
file = new File(fileName);
                              System.out.println("fileName received");
                              flag++;
break;
               case 2:
               if (file.exists())
                    file.delete();
               byte[] b = (byte[])recieved;
               FileOutputStream ff = new FileOutputStream(fileName);
ff.write(b);
flag = 3;
if(image!=null)
                         image.flush();
                                                            Runtime rt = Runtime.getRuntime();
               rt.runFinalization();
               rt.gc();
               image = null;
          Image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );          
                    paintPicture(image);
break;
          catch(Exception e)
               e.printStackTrace();
class ImageComponent extends JComponent {
Image image;
Dimension size;
public ImageComponent(Image image) {
this.image = image;
MediaTracker mt = new MediaTracker(this);
mt.addImage(image, 0);
try {
mt.waitForAll( );
catch (InterruptedException e) {
// error ...
size = new Dimension (image.getWidth(null),
image.getHeight(null));
setSize(size);}
public void paint(Graphics g) {
     g.drawImage(image, 0, 0, this);
public Dimension getPreferredSize( ) {
return size;
     public void runServer()
     try{
               server = new ServerSocket(port);
               client = server.accept();
JOptionPane.showMessageDialog(null,"Connected");
               System.out.println("connection received from" + client.getInetAddress().getHostName());
               ous = new ObjectOutputStream( client.getOutputStream() );
ous.flush();
               ins = new ObjectInputStream( client.getInputStream() );
               System.out.println("get i/o streams");
          catch(Exception e)
               e.printStackTrace();
     public static void main(String[] args)
     remote app = new remote();
     app.addWindowListener(
          new WindowAdapter(){
                    public void windowClosing( WindowEvent e )
                         System.exit( 0 );
CLIENT code:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
public class Client extends JFrame
private JLabel label1;
private JButton button1;
private Socket server;
private ObjectInputStream ins=null;
private ObjectOutputStream ous=null;
private File file;
private boolean autocontrol=true;     
public Client()
     super("Client");
     Container c = getContentPane();
     ButtonHandler handler = new ButtonHandler();
     c.setLayout( new FlowLayout() );
     label1 = new JLabel("");
     button1 = new JButton("connect");
     c.add(label1);
     c.add(button1);
     button1.addActionListener(handler);
     setSize(300,300);
     show();
class ButtonHandler implements ActionListener
     public void actionPerformed(ActionEvent e)
     if(e.getActionCommand()=="connect")
               runClient();
public void runClient()
     try{     
          server = new Socket(InetAddress.getByName("127.0.0.1"),5000);
System.out.println("connected to" + server.getInetAddress().getHostName());
          ous = new ObjectOutputStream(server.getOutputStream());
     ous.flush();
          ins = new ObjectInputStream(server.getInputStream());
          System.out.println("get i/o streams");
               file = new File("screen.jpg");
          listencommands();
     }catch(Exception e)
          e.getMessage();
public void listencommands()
     try
          while(true){
          Object message = ins.readObject();
     if(message.equals("refresh"))
               screenshot();
               sendFile(file);
     if(message.equals("auto"))
               autocontrol=true;
               while(autocontrol)
                    screenshot();
                    sendFile(file);
if(message.equals("stop"))
               autocontrol = false;
     catch(Exception e)
          e.printStackTrace();
public void sendFile( File file ) throws IOException
     try{     
          System.out.println("Ready to send file");
          ous.writeObject("sot");
ous.flush();
System.out.println("sot send");
          ous.writeObject("screen.jpg");
          ous.flush();
System.out.println("fileName send");
          FileInputStream f = new FileInputStream (file);
System.out.println("fileinputstream received");
          int size = f.available();
byte array[] = new byte[size];
f.read(array,0,size);
          System.out.println("Declared array");               
                    //ous.write(size);
                    //ous.flush();
          ous.writeObject(array);
ous.flush();
          System.out.println("image send");
          catch (Exception e)
               System.out.println(e.getMessage());
public void screenshot()
try
     //Get the screen size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
Robot robot = new Robot();     
     BufferedImage image = robot.createScreenCapture(rectangle);
     File file;
//Save the screenshot as a jpg
     file = new File("screen.jpg");
     ImageIO.write(image, "jpg", file);
catch (Exception e)
     System.out.println(e.getMessage());
public static void main( String args[] )
          Client app = new Client();
app.addWindowListener(
          new WindowAdapter(){
                    public void windowClosing( WindowEvent e )
                         System.exit( 0 );
Steps to run code:
if everything goes fine:
1.Run the server.
2.Run the client.
3.Press connect button on server.
4.Press connect on client.
5.You get a Message box "Connected".
6.Press refresh button on Server.
7.You get the first image.
8.Press refresh button on Server.
9.You are not going to get anything but the same image.....this is where the problem begins to display that second changed image screenshot.

/* (SERVER): */
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class Remote extends JFrame
private JPanel btnpnl,picpnl;
private JButton button[];
private UIManager.LookAndFeelInfo looks[];
private static int change = 1;
private JLabel label1;
private Icon icon[];
private String names[] = { "looks","connect","control", "refresh", "auto", "commands" };
private String iconnames[] = { "gifs/look.gif","gifs/connect.gif","gifs/control.gif","gifs/refresh.gif","gifs/auto.gif","gifs/command.gif" };
private String looknames[] = { "Motif", "Windows", "Metal" };
private int port=5000;
private ScrollablePicture picture=null;
private ServerSocket server;
private Socket client;
private ObjectInputStream ins = null;
private ObjectOutputStream ous = null;
private File file;
private String fileName;
private boolean autocontrol=true;
private Image image=null;
private Container c;
public remote()
super( "Remote Desktop" );
c = getContentPane();
c.setLayout( new BorderLayout() );
//String file = "screen.jpg";
looks = UIManager.getInstalledLookAndFeels();
btnpnl = new JPanel();
btnpnl.setLayout( new FlowLayout() );
button = new JButton[names.length];
icon = new ImageIcon[iconnames.length];
Buttonhandler handler = new Buttonhandler();
for( int i=0; i<names.length; ++i )
icon = new ImageIcon( iconnames );
button = new JButton( names, icon );
button.addActionListener(handler);
btnpnl.add(button);
c.add( btnpnl, BorderLayout.NORTH );
//Adding Label1
label1 = new JLabel("LABEL1");
c.add( label1, BorderLayout.SOUTH );
picpnl = new JPanel();
picpnl.setLayout(new BorderLayout());
//image = Toolkit.getDefaultToolkit( ).getImage(file);
// paintPicture(image);
c.add( picpnl, BorderLayout.CENTER );
//setResizable(false);
setSize( 808, 640 );
show();
public void paintPicture(Image image)
picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
picpnl.setVisible(true);
public class Buttonhandler implements ActionListener
public void actionPerformed( ActionEvent e )
try{
if( e.getActionCommand() == "looks" )
try
label1.setText( Integer.toString( change ) );
UIManager.setLookAndFeel( looks[change++].getClassName() );
SwingUtilities.updateComponentTreeUI(remote.this);
if(change==3)
change=0;
catch (Exception ex)
ex.printStackTrace();
if( e.getActionCommand() == "connect" )
label1.setText( "connect" );
runServer();
if( e.getActionCommand() == "refresh" )
label1.setText( "refresh" );
ous.writeObject("refresh");
ous.flush();
recieveFile();
if( e.getActionCommand() == "auto" )
label1.setText( "auto" );
ous.writeObject("auto");
button[4].setText("stop");
ous.flush();
setButton(false,false,false,false,true,false);
auto();
if( e.getActionCommand() == "stop" )
ous.writeObject("stop");
ous.flush();
button[4].setText("auto");
setButton(true,true,true,true,true,true);
autocontrol=false;
catch(Exception ef)
ef.getMessage();
public void auto()
while(autocontrol)
recieveFile();
public void setButton( boolean b1, boolean b2, boolean b3, boolean b4, boolean b5, boolean b6)
button[0].setEnabled(b1);
button[1].setEnabled(b2);
button[2].setEnabled(b3);
button[3].setEnabled(b4);
button[4].setEnabled(b5);
button[5].setEnabled(b6);
public void recieveFile()
int flag = 0;
try{
while(flag><=2){
Object recieved = ins.readObject();
System.out.println("from client:" + recieved);
switch (flag) {
case 0:
if (recieved.equals("sot")) {
System.out.println("sot recieved");
flag++;
break;
case 1:
fileName = (String) recieved;
file = new File(fileName);
System.out.println("fileName received");
flag++;
break;
case 2:
if (file.exists())
file.delete();
byte[] b = (byte[])recieved;
FileOutputStream ff = new FileOutputStream(fileName);
ff.write(b);
flag = 3;
if(image!=null)
image.flush();
Runtime rt = Runtime.getRuntime();
rt.runFinalization();
rt.gc();
image = null;
Image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );
paintPicture(image);
break;
catch(Exception e)
e.printStackTrace();
class ImageComponent extends JComponent {
Image image;
Dimension size;
public ImageComponent(Image image) {
this.image = image;
MediaTracker mt = new MediaTracker(this);
mt.addImage(image, 0);
try {
mt.waitForAll( );
catch (InterruptedException e) {
// error ...
size = new Dimension (image.getWidth(null),
image.getHeight(null));
setSize(size);}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
public Dimension getPreferredSize( ) {
return size;
public void runServer()
try{
server = new ServerSocket(port);
client = server.accept();
JOptionPane.showMessageDialog(null,"Connected");
System.out.println("connection received from" + client.getInetAddress().getHostName());
ous = new ObjectOutputStream( client.getOutputStream() );
ous.flush();
ins = new ObjectInputStream( client.getInputStream() );
System.out.println("get i/o streams");
catch(Exception e)
e.printStackTrace();
public static void main(String[] args)
remote app = new remote();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing( WindowEvent e )
System.exit( 0 );
/* End Server */
/*CLIENT code: */
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
public class Client extends JFrame
private JLabel label1;
private JButton button1;
private Socket server;
private ObjectInputStream ins=null;
private ObjectOutputStream ous=null;
private File file;
private boolean autocontrol=true;
public Client()
super("Client");
Container c = getContentPane();
ButtonHandler handler = new ButtonHandler();
c.setLayout( new FlowLayout() );
label1 = new JLabel("");
button1 = new JButton("connect");
c.add(label1);
c.add(button1);
button1.addActionListener(handler);
setSize(300,300);
show();
class ButtonHandler implements ActionListener
public void actionPerformed(ActionEvent e)
if(e.getActionCommand()=="connect")
runClient();
public void runClient()
try{
server = new Socket(InetAddress.getByName("127.0.0.1"),5000);
System.out.println("connected to" + server.getInetAddress().getHostName());
ous = new ObjectOutputStream(server.getOutputStream());
ous.flush();
ins = new ObjectInputStream(server.getInputStream());
System.out.println("get i/o streams");
file = new File("screen.jpg");
listencommands();
}catch(Exception e)
e.getMessage();
public void listencommands()
try
while(true){
Object message = ins.readObject();
if(message.equals("refresh"))
screenshot();
sendFile(file);
if(message.equals("auto"))
autocontrol=true;
while(autocontrol)
screenshot();
sendFile(file);
if(message.equals("stop"))
autocontrol = false;
catch(Exception e)
e.printStackTrace();
public void sendFile( File file ) throws IOException
try{
System.out.println("Ready to send file");
ous.writeObject("sot");
ous.flush();
System.out.println("sot send");
ous.writeObject("screen.jpg");
ous.flush();
System.out.println("fileName send");
FileInputStream f = new FileInputStream (file);
System.out.println("fileinputstream received");
int size = f.available();
byte array[] = new byte[size];
f.read(array,0,size);
System.out.println("Declared array");
//ous.write(size);
//ous.flush();
ous.writeObject(array);
ous.flush();
System.out.println("image send");
catch (Exception e)
System.out.println(e.getMessage());
public void screenshot()
try
//Get the screen size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
File file;
//Save the screenshot as a jpg
file = new File("screen.jpg");
ImageIO.write(image, "jpg", file);
catch (Exception e)
System.out.println(e.getMessage());
public static void main( String args[] )
Client app = new Client();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing( WindowEvent e )
System.exit( 0 );
}

Similar Messages

  • Reloading and redisplay images on JScrollPane

    I am using
    Java platform:jdk 1.4.1
    Windows platform: Windows 98se
    Problem:I am making one application in which i need to display images when i get
    it from socket.I had used one JScrollPane over JPanel with scrollbars.But when i get the image i stored it into an Image object.
    such as in my main program
    screen = Toolkit.getDefaultToolkit().getImage ( "screen.jpg" );
    //Draw picture first time it works fine...
    paintPicture(screen);
    paintPicture(Image image)
         {picpnl = new JPanel();
         picpnl.setLayout(new BorderLayout());
            image = Toolkit.getDefaultToolkit(  ).getImage(image);
    //Is picpnl is unable to display image second time       
          picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
            c.add( picpnl, BorderLayout.CENTER );
            picpnl.setVisible(true);
    from my refresh code:
           if(image!=null)
              image.flush();
           Runtime rt = Runtime.getRuntime();
           rt.runFinalization();
           rt.gc();
           image = null;
    //is this 2nd time image not properly stored in variable image
           image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );
           paintPicture(image);
    //go to paintPicture second time doesn't work
    class ImageComponent extends JComponent {
      Image image;
      Dimension size;
      public ImageComponent(Image image) {
        this.image = image;
        MediaTracker mt = new MediaTracker(this);
        mt.addImage(image, 0);
        try {
          mt.waitForAll(  );
    catch (InterruptedException e) {
    // error ...
    size = new Dimension (image.getWidth(null),
    image.getHeight(null));
    setSize(size);}
    public void paint(Graphics g) {
         g.drawImage(image, 0, 0, this);
    public Dimension getPreferredSize( ) {
    return size;
    The above code works fine for (the first time).But when i try to display a different socket image (the second time) it doesn't work.
    I didn't know what the problem is...
    ---whether the previous image didn't get erased from RAM or
    ---the OS is not aware of the current changed image in variable (image) or the
    ---JScrollPane is unable to redraw it second time.
    How can i display one changed image from the socket onto the JScrollPane? (the second time).
    Also i want to know if we are using one file with the name "screen.jpg" and at runtime if i changed that file with another file with the same name. How can i display that changed file?Is it possible in Java or not.(Is it the limitation of Java).
    I totally get frustated by reading all forums but i didn't get the answer.Please reply me soon with the complete code?
    The complete source code for the problem:
    (SERVER):
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.text.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Remote extends JFrame
    private JPanel btnpnl,picpnl;
    private JButton button[];
    private UIManager.LookAndFeelInfo looks[];
    private static int change = 1;
    private JLabel label1;
    private Icon icon[];
    private String names[] = { "looks","connect","control", "refresh", "auto",    "commands" };
    private String iconnames[] = { "gifs/look.gif","gifs/connect.gif","gifs/control.gif","gifs/refresh.gif","gifs/auto.gif","gifs/command.gif" };
    private String looknames[] = { "Motif", "Windows", "Metal" };
    private int port=5000;
    private ScrollablePicture picture=null;
    private ServerSocket server;
    private Socket client;
    private ObjectInputStream ins = null;
    private ObjectOutputStream ous = null;
    private File file;
    private String fileName;
    private boolean autocontrol=true;
    private Image image=null;
    private Container c;
         public remote()
              super( "Remote Desktop" );
    c = getContentPane();
              c.setLayout( new BorderLayout() );
    //String file = "screen.jpg";
    looks = UIManager.getInstalledLookAndFeels();
              btnpnl = new JPanel();
              btnpnl.setLayout( new FlowLayout() );
              button = new JButton[names.length];
              icon = new ImageIcon[iconnames.length];
              Buttonhandler handler = new Buttonhandler();
              for( int i=0; i<names.length; ++i )
    icon[i] = new ImageIcon( iconnames[i] );
                   button[i] = new JButton( names, icon[i] );
                   button[i].addActionListener(handler);
    btnpnl.add(button[i]);
              c.add( btnpnl, BorderLayout.NORTH );
              //Adding Label1
              label1 = new JLabel("LABEL1");
              c.add( label1, BorderLayout.SOUTH );
    picpnl = new JPanel();
         picpnl.setLayout(new BorderLayout());
              //image = Toolkit.getDefaultToolkit( ).getImage(file);
    // paintPicture(image);
              c.add( picpnl, BorderLayout.CENTER );
              //setResizable(false);
              setSize( 808, 640 );
              show();
    public void paintPicture(Image image)
    picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
    picpnl.setVisible(true);
    public class Buttonhandler implements ActionListener
              public void actionPerformed( ActionEvent e )
    try{
                   if( e.getActionCommand() == "looks" )
    try
                   label1.setText( Integer.toString( change ) );
              UIManager.setLookAndFeel( looks[change++].getClassName() );
                        SwingUtilities.updateComponentTreeUI(remote.this);
                   if(change==3)
                        change=0;
    catch (Exception ex)
    ex.printStackTrace();
                   if( e.getActionCommand() == "connect" )
                        label1.setText( "connect" );
    runServer();
                   if( e.getActionCommand() == "refresh" )
                        label1.setText( "refresh" );
                        ous.writeObject("refresh");
                        ous.flush();
                        recieveFile();
                   if( e.getActionCommand() == "auto" )
                        label1.setText( "auto" );
                        ous.writeObject("auto");
                        button[4].setText("stop");
                        ous.flush();
                        setButton(false,false,false,false,true,false);
                   auto();
                   if( e.getActionCommand() == "stop" )
                        ous.writeObject("stop");
                        ous.flush();
                        button[4].setText("auto");
                        setButton(true,true,true,true,true,true);
                   autocontrol=false;
              catch(Exception ef)
                   ef.getMessage();
         public void auto()
              while(autocontrol)
    recieveFile();
         public void setButton( boolean b1, boolean b2, boolean b3, boolean b4, boolean b5, boolean b6)
              button[0].setEnabled(b1);
              button[1].setEnabled(b2);
              button[2].setEnabled(b3);
              button[3].setEnabled(b4);
              button[4].setEnabled(b5);
              button[5].setEnabled(b6);
         public void recieveFile()
         int flag = 0;
              try{
                   while(flag<=2){
                   Object recieved = ins.readObject();
                   System.out.println("from client:" + recieved);
    switch (flag) {
    case 0:
    if (recieved.equals("sot")) {
    System.out.println("sot recieved");
                                       flag++;
    break;
                   case 1:
    fileName = (String) recieved;
    file = new File(fileName);
                                  System.out.println("fileName received");
                                  flag++;
    break;
                   case 2:
                   if (file.exists())
                        file.delete();
                   byte[] b = (byte[])recieved;
                   FileOutputStream ff = new FileOutputStream(fileName);
    ff.write(b);
    flag = 3;
    if(image!=null)
                             image.flush();
                                                                Runtime rt = Runtime.getRuntime();
                   rt.runFinalization();
                   rt.gc();
                   image = null;
              Image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );          
                        paintPicture(image);
    break;
              catch(Exception e)
                   e.printStackTrace();
    class ImageComponent extends JComponent {
    Image image;
    Dimension size;
    public ImageComponent(Image image) {
    this.image = image;
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
    mt.waitForAll( );
    catch (InterruptedException e) {
    // error ...
    size = new Dimension (image.getWidth(null),
    image.getHeight(null));
    setSize(size);}
    public void paint(Graphics g) {
         g.drawImage(image, 0, 0, this);
    public Dimension getPreferredSize( ) {
    return size;
         public void runServer()
         try{
                   server = new ServerSocket(port);
                   client = server.accept();
    JOptionPane.showMessageDialog(null,"Connected");
                   System.out.println("connection received from" + client.getInetAddress().getHostName());
                   ous = new ObjectOutputStream( client.getOutputStream() );
    ous.flush();
                   ins = new ObjectInputStream( client.getInputStream() );
                   System.out.println("get i/o streams");
              catch(Exception e)
                   e.printStackTrace();
         public static void main(String[] args)
         remote app = new remote();
         app.addWindowListener(
              new WindowAdapter(){
                        public void windowClosing( WindowEvent e )
                             System.exit( 0 );
    CLIENT code:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class Client extends JFrame
    private JLabel label1;
    private JButton button1;
    private Socket server;
    private ObjectInputStream ins=null;
    private ObjectOutputStream ous=null;
    private File file;
    private boolean autocontrol=true;     
    public Client()
         super("Client");
         Container c = getContentPane();
         ButtonHandler handler = new ButtonHandler();
         c.setLayout( new FlowLayout() );
         label1 = new JLabel("");
         button1 = new JButton("connect");
         c.add(label1);
         c.add(button1);
         button1.addActionListener(handler);
         setSize(300,300);
         show();
    class ButtonHandler implements ActionListener
         public void actionPerformed(ActionEvent e)
         if(e.getActionCommand()=="connect")
                   runClient();
    public void runClient()
         try{     
              server = new Socket(InetAddress.getByName("127.0.0.1"),5000);
    System.out.println("connected to" + server.getInetAddress().getHostName());
              ous = new ObjectOutputStream(server.getOutputStream());
         ous.flush();
              ins = new ObjectInputStream(server.getInputStream());
              System.out.println("get i/o streams");
                   file = new File("screen.jpg");
              listencommands();
         }catch(Exception e)
              e.getMessage();
    public void listencommands()
         try
              while(true){
              Object message = ins.readObject();
         if(message.equals("refresh"))
                   screenshot();
                   sendFile(file);
         if(message.equals("auto"))
                   autocontrol=true;
                   while(autocontrol)
                        screenshot();
                        sendFile(file);
    if(message.equals("stop"))
                   autocontrol = false;
         catch(Exception e)
              e.printStackTrace();
    public void sendFile( File file ) throws IOException
         try{     
              System.out.println("Ready to send file");
              ous.writeObject("sot");
    ous.flush();
    System.out.println("sot send");
              ous.writeObject("screen.jpg");
              ous.flush();
    System.out.println("fileName send");
              FileInputStream f = new FileInputStream (file);
    System.out.println("fileinputstream received");
              int size = f.available();
    byte array[] = new byte[size];
    f.read(array,0,size);
              System.out.println("Declared array");               
                        //ous.write(size);
                        //ous.flush();
              ous.writeObject(array);
    ous.flush();
              System.out.println("image send");
              catch (Exception e)
                   System.out.println(e.getMessage());
    public void screenshot()
    try
         //Get the screen size
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
    Robot robot = new Robot();     
         BufferedImage image = robot.createScreenCapture(rectangle);
         File file;
    //Save the screenshot as a jpg
         file = new File("screen.jpg");
         ImageIO.write(image, "jpg", file);
    catch (Exception e)
         System.out.println(e.getMessage());
    public static void main( String args[] )
              Client app = new Client();
    app.addWindowListener(
              new WindowAdapter(){
                        public void windowClosing( WindowEvent e )
                             System.exit( 0 );
    Steps to run code:
    if everything goes fine:
    1.Run the server.
    2.Run the client.
    3.Press connect button on server.
    4.Press connect on client.
    5.You get a Message box "Connected".
    6.Press refresh button on Server.
    7.You get the first image.
    8.Press refresh button on Server.
    9.You are not going to get anything but the same image.....this is where the problem begins to display that second changed image screenshot.

    This is a Swing related question and you've already posted this question in the Swing forum.
    Don't clutter the forum by posting the same question in 3 different forums.

  • Reloading and Redisplaying images on JScrollPane

    I am using
    Java platform:jdk 1.4.1
    Windows platform: Windows 98se
    Problem:I am making one application in which i need to display images when i get
    it from socket.I had used one JScrollPane over JPanel with scrollbars.But when i get the image i stored it into an Image object.
    such as in my main program
    screen = Toolkit.getDefaultToolkit().getImage ( "screen.jpg" );
    //Draw picture first time it works fine...
    paintPicture(screen);
    paintPicture(Image image)
         {picpnl = new JPanel();
         picpnl.setLayout(new BorderLayout());
            image = Toolkit.getDefaultToolkit(  ).getImage(image);
    //Is picpnl is unable to display image second time       
          picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
            c.add( picpnl, BorderLayout.CENTER );
            picpnl.setVisible(true);
    from my refresh code:
           if(image!=null)
              image.flush();
           Runtime rt = Runtime.getRuntime();
           rt.runFinalization();
           rt.gc();
           image = null;
    //is this 2nd time image not properly stored in variable image
           image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );
           paintPicture(image);
    //go to paintPicture second time doesn't work
    class ImageComponent extends JComponent {
      Image image;
      Dimension size;
      public ImageComponent(Image image) {
        this.image = image;
        MediaTracker mt = new MediaTracker(this);
        mt.addImage(image, 0);
        try {
          mt.waitForAll(  );
    catch (InterruptedException e) {
    // error ...
    size = new Dimension (image.getWidth(null),
    image.getHeight(null));
    setSize(size);}
    public void paint(Graphics g) {
         g.drawImage(image, 0, 0, this);
    public Dimension getPreferredSize( ) {
    return size;
    The above code works fine for (the first time).But when i try to display a different socket image (the second time) it doesn't work.
    I didn't know what the problem is...
    ---whether the previous image didn't get erased from RAM or
    ---the OS is not aware of the current changed image in variable (image) or the
    ---JScrollPane is unable to redraw it second time.
    How can i display one changed image from the socket onto the JScrollPane? (the second time).
    Also i want to know if we are using one file with the name "screen.jpg" and at runtime if i changed that file with another file with the same name. How can i display that changed file?Is it possible in Java or not.(Is it the limitation of Java).
    I totally get frustated by reading all forums but i didn't get the answer.Please reply me soon with the complete code?
    The complete source code for the problem:
    (SERVER):
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.text.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Remote extends JFrame
    private JPanel btnpnl,picpnl;
    private JButton button[];
    private UIManager.LookAndFeelInfo looks[];
    private static int change = 1;
    private JLabel label1;
    private Icon icon[];
    private String names[] = { "looks","connect","control", "refresh", "auto",    "commands" };
    private String iconnames[] = { "gifs/look.gif","gifs/connect.gif","gifs/control.gif","gifs/refresh.gif","gifs/auto.gif","gifs/command.gif" };
    private String looknames[] = { "Motif", "Windows", "Metal" };
    private int port=5000;
    private ScrollablePicture picture=null;
    private ServerSocket server;
    private Socket client;
    private ObjectInputStream ins = null;
    private ObjectOutputStream ous = null;
    private File file;
    private String fileName;
    private boolean autocontrol=true;
    private Image image=null;
    private Container c;
         public remote()
              super( "Remote Desktop" );
    c = getContentPane();
              c.setLayout( new BorderLayout() );
    //String file = "screen.jpg";
    looks = UIManager.getInstalledLookAndFeels();
              btnpnl = new JPanel();
              btnpnl.setLayout( new FlowLayout() );
              button = new JButton[names.length];
              icon = new ImageIcon[iconnames.length];
              Buttonhandler handler = new Buttonhandler();
              for( int i=0; i<names.length; ++i )
    icon[i] = new ImageIcon( iconnames[i] );
                   button[i] = new JButton( names, icon[i] );
                   button[i].addActionListener(handler);
    btnpnl.add(button[i]);
              c.add( btnpnl, BorderLayout.NORTH );
              //Adding Label1
              label1 = new JLabel("LABEL1");
              c.add( label1, BorderLayout.SOUTH );
    picpnl = new JPanel();
         picpnl.setLayout(new BorderLayout());
              //image = Toolkit.getDefaultToolkit( ).getImage(file);
    // paintPicture(image);
              c.add( picpnl, BorderLayout.CENTER );
              //setResizable(false);
              setSize( 808, 640 );
              show();
    public void paintPicture(Image image)
    picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
    picpnl.setVisible(true);
    public class Buttonhandler implements ActionListener
              public void actionPerformed( ActionEvent e )
    try{
                   if( e.getActionCommand() == "looks" )
    try
                   label1.setText( Integer.toString( change ) );
              UIManager.setLookAndFeel( looks[change++].getClassName() );
                        SwingUtilities.updateComponentTreeUI(remote.this);
                   if(change==3)
                        change=0;
    catch (Exception ex)
    ex.printStackTrace();
                   if( e.getActionCommand() == "connect" )
                        label1.setText( "connect" );
    runServer();
                   if( e.getActionCommand() == "refresh" )
                        label1.setText( "refresh" );
                        ous.writeObject("refresh");
                        ous.flush();
                        recieveFile();
                   if( e.getActionCommand() == "auto" )
                        label1.setText( "auto" );
                        ous.writeObject("auto");
                        button[4].setText("stop");
                        ous.flush();
                        setButton(false,false,false,false,true,false);
                   auto();
                   if( e.getActionCommand() == "stop" )
                        ous.writeObject("stop");
                        ous.flush();
                        button[4].setText("auto");
                        setButton(true,true,true,true,true,true);
                   autocontrol=false;
              catch(Exception ef)
                   ef.getMessage();
         public void auto()
              while(autocontrol)
    recieveFile();
         public void setButton( boolean b1, boolean b2, boolean b3, boolean b4, boolean b5, boolean b6)
              button[0].setEnabled(b1);
              button[1].setEnabled(b2);
              button[2].setEnabled(b3);
              button[3].setEnabled(b4);
              button[4].setEnabled(b5);
              button[5].setEnabled(b6);
         public void recieveFile()
         int flag = 0;
              try{
                   while(flag<=2){
                   Object recieved = ins.readObject();
                   System.out.println("from client:" + recieved);
    switch (flag) {
    case 0:
    if (recieved.equals("sot")) {
    System.out.println("sot recieved");
                                       flag++;
    break;
                   case 1:
    fileName = (String) recieved;
    file = new File(fileName);
                                  System.out.println("fileName received");
                                  flag++;
    break;
                   case 2:
                   if (file.exists())
                        file.delete();
                   byte[] b = (byte[])recieved;
                   FileOutputStream ff = new FileOutputStream(fileName);
    ff.write(b);
    flag = 3;
    if(image!=null)
                             image.flush();
                                                                Runtime rt = Runtime.getRuntime();
                   rt.runFinalization();
                   rt.gc();
                   image = null;
              Image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );          
                        paintPicture(image);
    break;
              catch(Exception e)
                   e.printStackTrace();
    class ImageComponent extends JComponent {
    Image image;
    Dimension size;
    public ImageComponent(Image image) {
    this.image = image;
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
    mt.waitForAll( );
    catch (InterruptedException e) {
    // error ...
    size = new Dimension (image.getWidth(null),
    image.getHeight(null));
    setSize(size);}
    public void paint(Graphics g) {
         g.drawImage(image, 0, 0, this);
    public Dimension getPreferredSize( ) {
    return size;
         public void runServer()
         try{
                   server = new ServerSocket(port);
                   client = server.accept();
    JOptionPane.showMessageDialog(null,"Connected");
                   System.out.println("connection received from" + client.getInetAddress().getHostName());
                   ous = new ObjectOutputStream( client.getOutputStream() );
    ous.flush();
                   ins = new ObjectInputStream( client.getInputStream() );
                   System.out.println("get i/o streams");
              catch(Exception e)
                   e.printStackTrace();
         public static void main(String[] args)
         remote app = new remote();
         app.addWindowListener(
              new WindowAdapter(){
                        public void windowClosing( WindowEvent e )
                             System.exit( 0 );
    CLIENT code:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class Client extends JFrame
    private JLabel label1;
    private JButton button1;
    private Socket server;
    private ObjectInputStream ins=null;
    private ObjectOutputStream ous=null;
    private File file;
    private boolean autocontrol=true;     
    public Client()
         super("Client");
         Container c = getContentPane();
         ButtonHandler handler = new ButtonHandler();
         c.setLayout( new FlowLayout() );
         label1 = new JLabel("");
         button1 = new JButton("connect");
         c.add(label1);
         c.add(button1);
         button1.addActionListener(handler);
         setSize(300,300);
         show();
    class ButtonHandler implements ActionListener
         public void actionPerformed(ActionEvent e)
         if(e.getActionCommand()=="connect")
                   runClient();
    public void runClient()
         try{     
              server = new Socket(InetAddress.getByName("127.0.0.1"),5000);
    System.out.println("connected to" + server.getInetAddress().getHostName());
              ous = new ObjectOutputStream(server.getOutputStream());
         ous.flush();
              ins = new ObjectInputStream(server.getInputStream());
              System.out.println("get i/o streams");
                   file = new File("screen.jpg");
              listencommands();
         }catch(Exception e)
              e.getMessage();
    public void listencommands()
         try
              while(true){
              Object message = ins.readObject();
         if(message.equals("refresh"))
                   screenshot();
                   sendFile(file);
         if(message.equals("auto"))
                   autocontrol=true;
                   while(autocontrol)
                        screenshot();
                        sendFile(file);
    if(message.equals("stop"))
                   autocontrol = false;
         catch(Exception e)
              e.printStackTrace();
    public void sendFile( File file ) throws IOException
         try{     
              System.out.println("Ready to send file");
              ous.writeObject("sot");
    ous.flush();
    System.out.println("sot send");
              ous.writeObject("screen.jpg");
              ous.flush();
    System.out.println("fileName send");
              FileInputStream f = new FileInputStream (file);
    System.out.println("fileinputstream received");
              int size = f.available();
    byte array[] = new byte[size];
    f.read(array,0,size);
              System.out.println("Declared array");               
                        //ous.write(size);
                        //ous.flush();
              ous.writeObject(array);
    ous.flush();
              System.out.println("image send");
              catch (Exception e)
                   System.out.println(e.getMessage());
    public void screenshot()
    try
         //Get the screen size
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
    Robot robot = new Robot();     
         BufferedImage image = robot.createScreenCapture(rectangle);
         File file;
    //Save the screenshot as a jpg
         file = new File("screen.jpg");
         ImageIO.write(image, "jpg", file);
    catch (Exception e)
         System.out.println(e.getMessage());
    public static void main( String args[] )
              Client app = new Client();
    app.addWindowListener(
              new WindowAdapter(){
                        public void windowClosing( WindowEvent e )
                             System.exit( 0 );
    Steps to run code:
    if everything goes fine:
    1.Run the server.
    2.Run the client.
    3.Press connect button on server.
    4.Press connect on client.
    5.You get a Message box "Connected".
    6.Press refresh button on Server.
    7.You get the first image.
    8.Press refresh button on Server.
    9.You are not going to get anything but the same image.....this is where the problem begins to display that second changed image screenshot.

    Use the "code" formatting tags when posting code so the code retains its formatting.
    Also, instead of posting a complicated client/server application, why don't you start with something simple. Like create a GUI with two buttons, "Load Image 1", "Load Image 2". Once you learn how to solve this simple program you shouldn't have a problem with a little more complicated scenario.
    I would try just adding a JLabel to the scroll pane. Then when you want to change the image just use the setIcon(...) method of JLabel.

  • Reloading and redrawing Icon using swing

    Hi,
    I am building an application in which I need to display several pictures in GIF format. At some point I allow the user to replace a picture from a pool of other pictures. I then rename the chosen picture to the name of the original picture and then replace the original picture. This is done using replaceIcon. My problem is that although the picture is being replaced, I cannot get it to reload and redisplay the picture. I get a Null pointer exception.
    It is essential for me to replace and rename the file since and since the pool of pictures might be large, it would be impractical to redirect the path to a new chosen picture. Anyone has encountered a similar problem? any help would be very much appreciated.
    thanks
    Nessen

    Hi,
    I am building an application in which I need to display several pictures in GIF format. At some point I allow the user to replace a picture from a pool of other pictures. I then rename the chosen picture to the name of the original picture and then replace the original picture. This is done using replaceIcon. My problem is that although the picture is being replaced, I cannot get it to reload and redisplay the picture. I get a Null pointer exception.
    It is essential for me to replace and rename the file since and since the pool of pictures might be large, it would be impractical to redirect the path to a new chosen picture. Anyone has encountered a similar problem? any help would be very much appreciated.
    thanks
    Nessen

  • Drag and drop images using tilelist in flex

    i just want the working code for drag and drop images using
    tilelist in flex

    Try JDK 1.4 and call setDragEnabled(true)
    I will also post updated version of MediaChest soon using custom TransferHandler for DnD different types of Objects.

  • Upload and Download images using API

    Hi
    I have an image catalog database where the actual images are stored on the database server filesystem and reduced size images are uploaded into the database. The user can browse and search the image catalog and see the reduced size images.
    I have created a collection to store the filenames of selected images (the user selects the images he likes, much like a shopping cart) and I would like to be able to get the corresponding full size images from the server to the client (which are not stored in the database but have the same filename in a folder in the OS).
    I am using XE so don't have room to store the full size images in the catalog.
    I need this to work at the click of a button on the apex form - say the user does a kind of checkout procedure and the files he needs are delivered to his desktop or memory stick or wherever.
    For this button process is it best to
    1) upload the big images into the database (temporarily) and then download them to the client before deleting them from the database - I can do the multi upload from pl/sql but not sure how to do the download.
    or
    2) write some kind of OS batch file to copy the files from the server to the client
    Any help gratefully received.
    I'm using Apex 3.1 on 10g XE on Windows XP
    Thanks
    Kathryn

    Hi
    I don't think bfiles will solve my problem. I need to get a file from a directory on the server to a user specified directory on the client. The database can't write bfiles to the client PC (security). I don't even need the files to be in the database.
    I'd like my applcation to either
    1) write a batch file and then run it. The contents of the batch file will be the copy commands to copy files form server to client
    or
    2) upload the files from the server directory into the database and then the use can download them to wherever he likes - but I need to do multiple files with just one click of a button by the user and the process needs to do the following steps : upload from server, download to client, delete from database
    I think I can do option 2) using Denes' code but it seems a bit OTT and a lot of database work just to copy some OS files.
    Just wondered if anyone else has done something similar
    Kathryn

  • How to  upload and display image using bsp application

    hi
    I  just wants to know that
    1- how to  upload image from BSP page with attachment into sap server .?
    2-how to display image in to BSP page(webpage).
    thanks

    Hello Gupta Prashant,
    Just to upload and display an image, import image in MIME repository. Not only still images but also flash files can also be uploaded in the MIME repository. Once you import the image in it, use normal html code for image call;
    <img src = "file.jpg/gif" width=  height=>
    Besides it, if your requirement is to store the image in the database and fetch it based on specified field-name, then you have to go for BLOBs i.e Binary Large Object, using this you can also store images, videos, pdfs, applications in the database.
    MBLOB - Medium BLOBs store videos and pdfs,
    LBLOB  - Large BLOBs store movie files and applications.
    You have got 2 ways to use it; some databases store BLOB objects into themselves and some store the path of the BLOB object maintained on the FTP server.
    You can also implement it in ABAP;
    read the following link and practice the tutorial;
    [ Use of MIME Types|http://help.sap.com/saphelp_45b/helpdata/en/f1/b4a6c4df3911d18e080000e8a48612/content.htm]
    also check this
    [TYPES - LOB HANDLE|http://help.sap.com/abapdocu/en/ABAPTYPES_LOB_HANDLE.htm]
    And looking at your question, in order to upload an image, you can make use of FILEUPLOAD tag provided by HTMLB.
    Step 1: FILEUPLOAD provides a browse button to choose desired image file.
    Step 2: Store that image in database using BLOBs.
    Step 3: Retrieve the image using normal select query and display it on the screen.
    Hope it helps you,
    Zahack

  • Can i store and retrieve image using sql command?

    hi
    the following is what i enter to store image in table using sql*plus
    however i encounter some errors as shown below.
    i wondered if i actually can use sql to store image and retreive image
    or i need other developer beside sql to do.
    create table img_storage
    (id     number primary key,
    image     ORDSYS.ORDImage);
    CREATE or REPLACE procedure ADD_image (tmp_id number, file_name varchar2)
    as
         obj ORDSYS.ORDImage;
         ctx raw(4000) := null;
    begin
         INSERT INTO img_classifier (id, image) VALUES (tmp_id,
         ORDSYS.ORDImage (ORDSYS.ORDSOURCE(EMPTY_BLOB(),
         NULL,NULL,NULL,SYSDATE,NULL),
         NULL,NULL,NULL,NULL,NULL,NULL,NULL));
         COMMIT;
         SELECT image into obj FROM img_storage
         where id = tmp_id FOR UPDATE;
         obj.importFrom(ctx,'FILE','IMGDIR',file_name);
         obj.setproperties();
         UPDATE img_storage
         SET image = obj where id = tmp_id;
         COMMIT;
    end;
    show errors;
    create or replace directory imgdir as 'c:\image\';
    exec add_image(1,'argvseng.jpg');
    BEGIN add_image(1,'argvseng.jpg'); END;
    ERROR at line 1:
    ORA-00001: unique constraint (SYS.SYS_C002717) violated
    ORA-06512: at "SYS.ADD_IMAGE", line 7
    ORA-06512: at line 1
    how to reslove the error as shown above.
    or sql does not support ordsys.ordimage such command.
    hmm very confused ....
    what is the difference bet using blob for image and ordsys.ordimage?

    This has nothing to do with intereMedia.
    This is a basic SQL issue.
    A primary key cannot have duplicate entries in a table as the error message suggests.
    Before you call your peocedure you can delete the row with 1 as the primary key, or call the insert peocedure using a primary key that is not being used.

  • Cropping and resizing Images using Adobe Photoshop Elements 12

    I am trying to edit pictures for my web site and previously used adobe photo shop 4 which I liked very well. When I try to crop and resize in photoshop 12 have been unable to adjust the images using pixels. As every photo on my website needs to be in pixels then this is a big problem for me! Is there anyway to change the preferences in the settings?  Thanks Tess

    You should head over to the Elements forums, this forum is for Photoshop. Go here : http://forums.adobe.com/community/photoshop_elements

  • Open camera and capture image using J2me.

    please I want J2me code to open the mobile camera and capture image....
    please reply me as quick as possible....(very urgent)...

    eng_amy wrote:
    please I want J2me code to open the mobile camera and capture image....Well..
    eng_amy wrote:
    please reply me as quick as possible....(very urgent).....(checks watch) ..it's obviously too late. Never mind.

  • Cut and move image using mouse ?

    Hello,
    I am developing one paint program. I am making it similar to microsoft paint. In This paint, I want to use lasso, magic wand tool and select tool. But I am not too familiar with java. And want to do with your help. Please help on this topic. If lasso and magic wand tools behave same. Then please tell me about only select tool that will use for the purpose of select a particular area from canvas (canvas is drawing sheets that holds the drawing). Please help me.
    If there is any snippet of this above declaration please send. Can we use system clipboard to cut, move and paste for this drawing by the help of mouse. Please help me. I will really thankful to you.
    Thanks in advance.
    Manveer

    For the Magic Wand (at least for what I suppose it is) I would consider the image as a graph, where two pixels are connected if the difference between their color values is below some tolerance value. Then you can easily perform the iterative breadth-first algorithm to collect the pixels of the selection. I recently did something similar (although not on an image itself, but on some higher abstraction of it).
    For the Lasso i would collect all the pixels, the user selects, then calculate the bounding box over the selected pixel area and finally determine for each pixel inside the bounding box, that is no member of the lasso/selection pixels, whether it lies inside or outside the selection area. This could be accomplished by performing another bfs from one pixel, that includes all pixels besides the ones lying outside the bounding box or are pixels of the selection lasso.

  • Bringing up a button and an image using video cue points

    Hi,
    I have a 4:40 long video and I'd like to show a button and a background image (or a movie clip) at 4:30 and I want them stay on the screen after the video is complete. If someone could give me a step by step instructions for this I'd really appreciate it. By the way I use Flash CS5.
    Have a great day!
    Veli

    Sorry if I confused you. Here's a little sample video I'd like to show you (only 10 seconds), so I can explain it more clearly. This is exactly the same thing except it is 10 seconds instead of 5 minutes.
    http://www.relationsmith.com/hhosp/slideshow/jan12/slideshow.html
    In this project I have 6 layers (from top to bottom); action, replay, button, bg, frame, video. The video plays and the button (btn1) comes up at 7, then the video ends and replay button comes up. So far so good.
    When I hit replay button to watch the video again, the video starts to play but this time the video is on the top of everything. I cant see the blue frame, at the 7th second the button activates but is hidden behind the video, and so is the replay button. I think the answer lies in this code:
    function replay(e:MouseEvent):void {
        addChild(flv_pb); 
        flv_pb.play();
    You said this code "addChild(flv_pb);" would put the video on the top of everything. So I was wondering if there is a way to play the video without having it at the top most depth. I'm pasting the entire code for your reference.
    Thanks!
    import fl.video.MetadataEvent;
    replay_btn.visible=false;
    btn1.visible=false;
    flv_pb.addASCuePoint(7,"show");
    flv_pb.addEventListener(MetadataEvent.CUE_POINT,cuepointF);
    flv_pb.addEventListener(Event.COMPLETE,completeF);
    btn1.addEventListener(MouseEvent.CLICK, clickButton);
    replay_btn.addEventListener(MouseEvent.CLICK, replay);
    function completeF(e:Event):void{
    replay_btn.visible=true;
    function replay(e:MouseEvent):void {
        addChild(flv_pb);  // moves flv_pb to the top most depth
        flv_pb.play();
    function cuepointF(e:MetadataEvent):void{
    if(e.info.name=="show"){
    bg.play()
    btn1.visible=true;
    var myURL:URLRequest=new URLRequest("http://www.ctwolfpackyouth.org/");
    function clickButton(myevent:MouseEvent):void {
              navigateToURL(myURL);

  • Load and display image using CDC

    Hi everyone,
    Please help. I'm new to java. I need a simple routine to load and display an image from the file system into a CDC app on windows mobile 5. I'm usin creme 4.1.
    Thanx in advance

    Use the following as a guide:
    1. Get the image (path below must be absolute):
    public static Image getImage(String filename) throws ScanException {
    Image img = null;
    // Read paths from properties file
    StringBuffer buf = new StringBuffer("\\");
    buf.append(ScanUtility.getPathImages());
    buf.append("\\");
    buf.append(filename);
    buf.append(".jpg");
    File dataFile = new File(buf.toString());
    if(!dataFile.exists())
    throw new ScanException("Cannot locate the file:\n" + dataFile.getAbsolutePath());
    img = Toolkit.getDefaultToolkit().createImage(buf.toString());
    return img;
    2. Create a class to display the image (pass in the image, above):
    ImagePanel class source:
    import java.awt.*;
    import java.awt.image.*;
    public class ImagePanel extends Panel {
    private Image image = null;
    private Image scaledImage = null;
    private boolean imageComplete = false;
    public ImagePanel(Image img) {
    image = img;
    scaledImage = image.getScaledInstance(200, -1, Image.SCALE_DEFAULT);
    prepareImage(scaledImage, this);
    // Override the paint method, to render the image
    public void paint(Graphics g) {
    if(imageComplete) {
    g.drawImage(scaledImage, 0, 0, this);
    // Override imageUpdate method, to prevent repaint() from trying
    // to do anything until the image is scaled
    public boolean imageUpdate(Image img, int infoFlags, int x, int y, int w, int h) {
    if(infoFlags == ImageObserver.ALLBITS) {
    imageComplete = true;
    repaint();
    return super.imageUpdate(img, infoFlags, x, y, w, h);
    public void flush() {
    image.flush();
    scaledImage.flush();
    image = null;
    scaledImage = null;
    }

  • Load, crop and saving jpg and gif images with JFileChooser

    Hello!
    I wonder is there someone out there who can help me with a applic that load, (crop) and saving images using JFileChooser with a simple GUI as possible. I'm new to programming and i hope someone can show me.
    Tor

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.filechooser.FileFilter;
    public class ChopShop extends JPanel {
        JFileChooser fileChooser;
        BufferedImage image;
        Rectangle clip = new Rectangle(50,50,150,150);
        boolean showClip = true;
        public ChopShop() {
            fileChooser = new JFileChooser(".");
            fileChooser.setFileFilter(new ImageFilter());
        public void setClip(int x, int y) {
            clip.setLocation(x, y);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(image != null) {
                int x = (getWidth() - image.getWidth())/2;
                int y = (getHeight() - image.getHeight())/2;
                g2.drawImage(image, x, y, this);
            if(showClip) {
                g2.setPaint(Color.red);
                g2.draw(clip);
        public Dimension getPreferredSize() {
            int width = 400;
            int height = 400;
            int margin = 20;
            if(image != null) {
                width = image.getWidth() + 2*margin;
                height = image.getHeight() + 2*margin;
            return new Dimension(width, height);
        private void showOpenDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    image = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("Read error for " + file.getPath() +
                                       ": " + e.getMessage());
                    image = null;
                revalidate();
                repaint();
        private void showSaveDialog() {
            if(image == null || !showClip)
                return;
            if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                String ext = ((ImageFilter)fileChooser.getFileFilter()).getExtension(file);
                // Make sure we have an ImageWriter for this extension.
                if(!canWriteTo(ext)) {
                    System.out.println("Cannot write image to " + ext + " file.");
                    String[] formatNames = ImageIO.getWriterFormatNames();
                    System.out.println("Supported extensions are:");
                    for(int j = 0; j < formatNames.length; j++)
                        System.out.println(formatNames[j]);
                    return;
                // If file exists, warn user, confirm overwrite.
                if(file.exists()) {
                    String message = "<html>" + file.getPath() + " already exists" +
                                     "<br>Do you want to replace it?";
                    int n = JOptionPane.showConfirmDialog(this, message, "Confirm",
                                                          JOptionPane.YES_NO_OPTION);
                    if(n != JOptionPane.YES_OPTION)
                        return;
                // Get the clipped image, if available. This is a subImage
                // of image -> they share the same data. Handle with care.
                BufferedImage clipped = getClippedImage();
                if(clipped == null)
                    return;
                // Copy the clipped image for safety.
                BufferedImage cropped = copy(clipped);
                boolean success = false;
                // Write cropped to the user-selected file.
                try {
                    success = ImageIO.write(cropped, ext, file);
                } catch(IOException e) {
                    System.out.println("Write error for " + file.getPath() +
                                       ": " + e.getMessage());
                System.out.println("writing image to " + file.getPath() +
                                   " was" + (success ? "" : " not") + " successful");
        private boolean canWriteTo(String ext) {
            // Support for writing gif format is new in j2se 1.6
            String[] formatNames = ImageIO.getWriterFormatNames();
            //System.out.printf("writer formats = %s%n",
            //                   java.util.Arrays.toString(formatNames));
            for(int j = 0; j < formatNames.length; j++) {
                if(formatNames[j].equalsIgnoreCase(ext))
                    return true;
            return false;
        private BufferedImage getClippedImage() {
            int w = getWidth();
            int h = getHeight();
            int iw = image.getWidth();
            int ih = image.getHeight();
            // Find origin of centered image.
            int ix = (w - iw)/2;
            int iy = (h - ih)/2;
            // Find clip location relative to image origin.
            int x = clip.x - ix;
            int y = clip.y - iy;
            // clip must be within image bounds to continue.
            if(x < 0 || x + clip.width  > iw || y < 0 || y + clip.height > ih) {
                System.out.println("clip is outside image boundries");
                return null;
            BufferedImage subImage = null;
            try {
                subImage = image.getSubimage(x, y, clip.width, clip.height);
            } catch(RasterFormatException e) {
                System.out.println("RFE: " + e.getMessage());
            // Caution: subImage is not independent from image. Changes
            // to one will affect the other. Copying is recommended.
            return subImage;
        private BufferedImage copy(BufferedImage src) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dest = new BufferedImage(w, h, src.getType());
            Graphics2D g2 = dest.createGraphics();
            g2.drawImage(src, 0, 0, this);
            g2.dispose();
            return dest;
        private JPanel getControls() {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(getCropPanel(), gbc);
            panel.add(getImagePanel(), gbc);
            return panel;
        private JPanel getCropPanel() {
            JToggleButton toggle = new JToggleButton("clip", showClip);
            toggle.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    showClip = ((AbstractButton)e.getSource()).isSelected();
                    repaint();
            SpinnerNumberModel widthModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner widthSpinner = new JSpinner(widthModel);
            SpinnerNumberModel heightModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner heightSpinner = new JSpinner(heightModel);
            ChangeListener cl = new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    JSpinner spinner = (JSpinner)e.getSource();
                    int value = ((Number)spinner.getValue()).intValue();
                    if(spinner == widthSpinner)
                        clip.width = value;
                    if(spinner == heightSpinner)
                        clip.height = value;
                    repaint();
            widthSpinner.addChangeListener(cl);
            heightSpinner.addChangeListener(cl);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            panel.add(toggle, gbc);
            addComponents(new JLabel("width"),  widthSpinner,  panel, gbc);
            addComponents(new JLabel("height"), heightSpinner, panel, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc) {
            gbc.anchor = GridBagConstraints.EAST;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(c2, gbc);
        private JPanel getImagePanel() {
            final JButton open = new JButton("open");
            final JButton save = new JButton("save");
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JButton button = (JButton)e.getSource();
                    if(button == open)
                        showOpenDialog();
                    if(button == save)
                        showSaveDialog();
            open.addActionListener(al);
            save.addActionListener(al);
            JPanel panel = new JPanel();
            panel.add(open);
            panel.add(save);
            return panel;
        public static void main(String[] args) {
            ChopShop chopShop = new ChopShop();
            ClipMover mover = new ClipMover(chopShop);
            chopShop.addMouseListener(mover);
            chopShop.addMouseMotionListener(mover);
            JFrame f = new JFrame("click inside rectangle to drag");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(chopShop));
            f.getContentPane().add(chopShop.getControls(), "Last");
            f.pack();
            f.setLocation(200,100);
            f.setVisible(true);
    class ImageFilter extends FileFilter {
        static String GIF = "gif";
        static String JPG = "jpg";
        static String PNG = "png";
        // bmp okay in j2se 1.5+
        public boolean accept(File file) {
            if(file.isDirectory())
                return true;
            String ext = getExtension(file).toLowerCase();
            if(ext.equals(GIF) || ext.equals(JPG) || ext.equals(PNG))
                return true;
            return false;
        public String getDescription() {
            return "gif, jpg, png images";
        public String getExtension(File file) {
            String s = file.getPath();
            int dot = s.lastIndexOf(".");
            return (dot != -1) ? s.substring(dot+1) : "";
    class ClipMover extends MouseInputAdapter {
        ChopShop component;
        Point offset = new Point();
        boolean dragging = false;
        public ClipMover(ChopShop cs) {
            component = cs;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            if(component.clip.contains(p)) {
                offset.x = p.x - component.clip.x;
                offset.y = p.y - component.clip.y;
                dragging = true;
        public void mouseReleased(MouseEvent e) {
            dragging = false;
        public void mouseDragged(MouseEvent e) {
            if(dragging) {
                int x = e.getX() - offset.x;
                int y = e.getY() - offset.y;
                component.setClip(x, y);
    }

  • Truly dumb question. How do I get PS to actually complete a command, eg straighten an horizon, and finalise the change. Even doing a "save as" with a new file name and reloading brings the image back, straightened, but with the skewed back ground frame st

    Truly dumb question. How do I get PS to actually complete a command, eg straighten an horizon, and finalise the change. Even doing a "save as" with a new file name and reloading brings the image back, straightened, but with the skewed back ground frame still there. Is there a "apply change" or similiar command that I simply cannot see.

    brings the image back, straightened, but with the skewed back ground frame
    PSE did what you told it to do. Choose the Straighten and crop edges or fill edges options when you use the straighten tool if you want it to do more than just straighten the contents of the image. Many people prefer the plain straighten because they'd rather crop themselves than let PSE do it.

Maybe you are looking for