Results 1 to 4 of 4
  1. #1
    prowael is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Unhappy read images path from database and display it in label?

    Dear all,
    I have writing one code to display image as slideshow the path of images located in oracle database the problem that it does not displaying the images while looping after loop finish it display only the last image below is the sample code Please Help:



    /* slideShow.java ** Created on 03 , 2011, 08:51 ص */

    /** * @author ml223344 */
    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.sql.*;

    public class slideShow extends JFrame {

    String Pic_Path = "//rmo-db-04/road1/ARRB/ARRB_MOC/NEw_BATCH/2008-2011/CYCLE_0.2/H65/H65-M-L1-1105-1371/FORWARD/00000/000000.Jpeg"; //wamar

    int Pause = 1;
    int x;
    int v_seq = 1;

    /** Creates new form slideShow */
    public slideShow() {
    initComponents();
    viewPhotoes();
    }

    public void viewPhotoes() {
    String file = Pic_Path;
    File f = new File(file);
    if (!f.exists()) {
    JOptionPane.showConfirmDialog((Component) null,
    "Photo " + f.getName() + " not available.Re-viewing files again.",
    "File not found.",
    JOptionPane.PLAIN_MESSAGE);
    x = 0;
    }
    ImageIcon i = new ImageIcon(file);
    jLabel1.setIcon(i);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });

    jButton2.setText("jButton1");

    jLabel1.setText("jLabel1");

    jTextField1.setText("jTextField1");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(49, 49, 49)
    .addComponent(jButton1)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addComponent(jButton2))
    .addGroup(layout.createSequentialGroup()
    .addGap(35, 35, 35)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGap(23, 23, 23)
    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap(49, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 35, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton1)
    .addComponent(jButton2))
    .addContainerGap())
    );

    pack();
    }// </editor-fold>

    public void do_connection() throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//rmo-db-04:1521/roadsdb", "myusername", "mypassword");
    // @//machineName:port/SID, userid, password
    try {
    Statement stmt = conn.createStatement();
    try {
    ResultSet rset = stmt.executeQuery("select GET_PATH(F_SNAP) F_SNAP, seq from pd_video_s25 SS, SLIDESHOW_PATH_DT inf where SS.last_survey = INF.LAST_SURVEY AND SS.last_survey = 6 and road_no = 65 and direction = 'M' AND LANE_NO = 1 AND SEGM_ID = 76426 ORDER BY SS.SEQ ");

    try {
    while (rset.next() && Pause == 1) {
    Pic_Path = rset.getString(1);
    v_seq = rset.getInt(2);
    jTextField1.setText(String.format("%s", v_seq));
    viewPhotoes();

    }//end of while

    } finally {
    try {
    rset.close();
    } catch (Exception ignore) {
    }
    }
    } finally {
    try {
    stmt.close();
    } catch (Exception ignore) {
    }
    }
    } finally {
    try {
    conn.close();
    } catch (Exception ignore) {
    }
    }
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    // this.viewPhotoes();

    try {
    this.do_connection();
    } catch (Exception e) {
    e.printStackTrace();
    }//end of catch

    }

    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new slideShow().setVisible(true);

    }
    });

    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
    }

  2. #2
    Join Date
    Oct 2011
    Location
    Chennai, India
    Posts
    2
    Rep Power
    0

    Default Re: read images path from database and display it in label?

    I have not worked much on swing apps.. But I have done almost similar thing in a JSP page.
    I suggest what you should do is You first get all the images in n different variable on the page and then put it inside the loop for slide show.
    Hope it may work. .You should try...
    All the best..:)

  3. #3
    prowael is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: read images path from database and display it in label?

    Thanks for your reply, the problem that I have thousands of images. cann't load it into variables.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: read images path from database and display it in label?

    Please use code tags when posting code...

    SInce I'm having trouble following the flow up there I will take a guess that you are doing everything (or at least the looing through the images part) in the EDT (ie Swing) thread, so Swing never gets a chance to redraw anything until the end of the loop...hence it seemingly only drawing the last image.

Similar Threads

  1. Display image via label
    By mike_ledis in forum Java Applets
    Replies: 1
    Last Post: 06-02-2011, 06:28 PM
  2. Read and display large images quickly
    By neptune692 in forum Advanced Java
    Replies: 15
    Last Post: 01-13-2011, 10:00 PM
  3. Display string as label
    By cool in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2010, 12:45 PM
  4. Read the content of file from a specified path
    By shiva in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 07:31 AM
  5. Replies: 3
    Last Post: 01-29-2009, 10:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •