Application and image display

A

Arint?

I have this code here that just supposed to rotate pictures to
display. Kinda like a picture album. But for some reason it doesn't
always switch all 5 pictures. Sometimes it does all five other times
it just does 2 of them. Can someone point me in the right direction.

/*
* MainDisplay.java
*
* Created on May 2, 2004, 3:49 PM
*/
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainDisplay extends JFrame
{
/** Creates new form MainDisplay */
public MainDisplay() {
initComponents();
cities.add("test");
cities.add("suite1");
rotate = new Thread( new TimeTask() );
rotate.start();
}

/** This method is called from within the constructor to
* initialize the form.
*/
private void initComponents()
{
setSize( new Dimension(300,300) );
centerPanel = new ImPanel();
northPanel = new ImPanel();
southPanel = new ImPanel();
eastPanel = new ImPanel();
westPanel = new ImPanel();

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
}
});

getContentPane().add(northPanel, BorderLayout.NORTH);
getContentPane().add(southPanel, BorderLayout.SOUTH);
getContentPane().add(eastPanel, BorderLayout.EAST);
getContentPane().add(westPanel, BorderLayout.WEST);
getContentPane().add(centerPanel, BorderLayout.CENTER);

Dimension dims = new Dimension(200,300);
northPanel.setPreferredSize( dims );
eastPanel.setPreferredSize( dims );
westPanel.setPreferredSize( dims );
southPanel.setPreferredSize( dims );
dims.setSize(300,300);
centerPanel.setPreferredSize( dims );

pack();
setResizable( false );
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt)
{
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try{
new MainDisplay().show();
}
catch(Exception e)
{
e.printStackTrace();
}
}

public void rotateDisplays(String centerName) {
System.out.println(centerName);
int end = centerName.length() + 2;
StringBuffer sb = new StringBuffer( end + 10 );
StringBuffer file = new StringBuffer( end + 10 );
sb.append( ".\\" );
file.append( ".\\" );
sb.append( centerName );
file.append( centerName );

sb.append( ".gif" );
file.append( ".txt" );
showPanel( sb, file, centerPanel );
sb.delete( end, sb.length() );
file.delete( end, file.length() );

sb.append("_north.gif");
file.append("_north.txt");
showPanel( sb, file, northPanel );
sb.delete( end, sb.length() );
file.delete( end, file.length() );
}

public void showPanel( StringBuffer jpg, StringBuffer file,
ImPanel panel )
{
try{
FileInputStream read = new FileInputStream(new
File(file.toString() ) );
byte data[] = new byte[ read.available() ];
read.read( data );
panel.setText( new String(data) );
}catch(Exception a){a.printStackTrace();}
panel.setImage( jpg.toString() );
}

public void updateInfoWindow( String x )
{
if ( null == infoWindow )
{
infoWindow = new JDialog( this );
infoWindow.setSize(300,200);
textArea = new JTextArea();
infoWindow.getContentPane().add( textArea );
infoWindow.show();
infoWindow.setTitle( "Information Window" );
}
if ( infoWindow.isVisible() )
{
textArea.setText( x );
}
else
infoWindow.show();
}

private ImPanel centerPanel;
private ImPanel eastPanel;
private ImPanel northPanel;
private ImPanel southPanel;
private ImPanel westPanel;
private ArrayList cities = new ArrayList(5);
private Thread rotate;
static JDialog infoWindow;
static JTextArea textArea;

public class ImPanel extends javax.swing.JPanel
{

/** Creates new form ImPanel */
public ImPanel() {
initComponents();
addMouseListener( new PanelMouse() );
}

//public void preLoad()
public void setImage( String i ){ jpg = i; }
public void setText( String x ){ infoText = x; }
public void reset()
{
img = null;
this.repaint();
}

/** This method is called from within the constructor to
* initialize the form.
*/
private void initComponents()
{
setBackground( Color.BLACK );
}

public void paintComponent(java.awt.Graphics g) {
super.paintComponent(g);
if ( jpg == null )
return;
int width = getWidth();
int height = getHeight();
if ( null == img )
{
ImageIcon ico = new ImageIcon( jpg );
img = ico.getImage();
}
if (width > img.getWidth(this) )
width = img.getWidth(this);
if (height > img.getHeight(this) )
height = img.getHeight(this);

g.drawImage( img, 0, 0, this );
//g.drawImage( img, 0, 0, width, height, this );
}

public boolean imageUpdate(Image img, int infoFlags, int x,
int y, int w, int h)
{
return true;
}


public class PanelMouse extends MouseAdapter
{
public void mouseEntered(MouseEvent arg0)
{
MainDisplay.this.updateInfoWindow( infoText );
super.mouseEntered(arg0);
}
}

String infoText = " ";
String jpg;
Image img = null;
Image inext = null;
}

public class TimeTask implements Runnable
{
public void run()
{
int len = cities.size();
int idx = 0;
while ( true )
{
if ( idx == len )
idx = 0;
String s = (String)cities.get( idx );
rotateDisplays( s );
idx++;
try{
Thread.currentThread().sleep( 19100 );
}catch(Exception e){}
centerPanel.reset();
northPanel.reset();
eastPanel.reset();
westPanel.reset();
southPanel.reset();
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top