File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes running gifs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "running gifs" Watch "running gifs" New topic
Author

running gifs

Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I am trying to add a gif to my application but am having a little trouble. I am already adding 2 JLabels and 2 JTextfields to a verticalEastBox and they are working fine. When I add the iconPanel to the verticalEastBox all I get is a gray area but no gif. I have tried using just the gif name as well as the full directory name, but still no picture.
Here is the code I am using for the gif.

Thanks,
Craig
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Make sure you're spelling the filename of the GIF correctly, and be sure it's in the current directory (though if you tried this with an absolute path, this shouldn't be a problem). Is this an animated GIF, and is the first frame completely blank? I've seen a problems with some animated GIFs that will not display correctly and only show their first frame.
[ February 05, 2004: Message edited by: Nathan Pruett ]

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
jack lista
Greenhorn

Joined: Feb 05, 2004
Posts: 2
Hey there,
I have a bit of code that does what you're looking for, so you can use it to analyze why your code isn't working. You will have to remove the references to the Scheduler code unless you want to set up the quartz scheduler, which isn't necessary to resolve your image problem. YOu'll also want to remove all references to the CronTrigger, which is also a quartz thing. Most of this stuff is in the event listeners. Just remove or comment out all references to this stuff:
in createComponents():
final Scheduler sched = sf.getScheduler();
in the constructor:
public QuartzJobManager( SchedulerFactory sf ) {...}
in listeners:
CronTrigger ct = new CronTrigger( triggerName, groupName, jobName,
groupName, new Date(), null, cronExpression );
JobDetail job = new JobDetail(...);
etc.
You may also want to remove the references to the Logger if you're not using log4j. You could do a stringreplace and set all the logger.info()
or logger.error to System.out.println, etc.
After you've done that, just dump the file in a directory and compile it to the current directory [like javac -d . QuartzJobManager.java] and run it. Put the images in the same directory as the java file and run it from that same directory also and you should see a simple swing GUI with a few image buttons. As I'm new to this forum [1st post] I'll just include the src in this text box, as I don't see any other way to include it, pardon me if this is a faux pas...
Here's the src:
package org.foo;

//import com.sun.java.swing.*; // JDK 1.1 package name
import javax.swing.*; //This is the final package name.
//Used by JDK 1.2 Beta 4 and all
import java.awt.*; //Swing releases before Swing 1.1 Beta 3.
import java.awt.event.*;
import javax.swing.JComboBox;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListDataEvent;
import java.util.Date;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.HashMap;
import java.lang.UnsupportedOperationException;
import javax.naming.*;
// quartz stuff
import org.quartz.Trigger;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SchedulerException;
import org.apache.log4j.Logger;

public class QuartzJobManager {
private static String labelPrefix = "Quartz: ";
static String url = "t3://localhost:7001";
static String user = null;
static String password = null;
private SchedulerFactory sf = null;
//private Log logger = LogFactory.getLog(QuartzJobManager.class);
private static final Logger logger = Logger.getLogger(QuartzJobManager.class.getName());
private boolean serverPaused = false;
private int numClicks = 0;
private final JLabel label = new JLabel( " ",
SwingConstants.LEFT );
private final JLabel triggerLabel = new JLabel( " ",
SwingConstants.LEFT );
public void setMainLabelText( String text ) {
label.setText( "<html><h2>"+text+"</h2></html>" );
}
public void setTriggerLabelText( String text ) {
triggerLabel.setText( "<html><h2>"+text+"</h2></html>" );
}
public QuartzJobManager( SchedulerFactory sf ) {
// -=j=-: set the scheduler factory
this.sf = sf;
}
public Component createComponents() {
JPanel pane = null;
String serverName = null;
String serverInstanceID = null;
String[] jobNames = null;
String[] groupNames = null;
String[] staticJobErrorStringArray = { "there", "was", "a", "problem...!" };
try {
//JButton button = new JButton("I'm a Swing button!");
// -=j=-: this one [housefly.jpg] shows up whole, the others get clipped,
// you see only top left
ImageIcon houseflyImgIcon = loadImageIcon("housefly.jpg","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("ms-dom1.gif","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("card1.jpg","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("Harley.jpg","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("bunny.jpg","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("sun-webserver1.gif","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("DMVMap.gif","I'm a Swing button!");
ImageIcon buttonImgIcon = loadImageIcon("starfield.gif","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("olaflara_1_12.jpg","I'm a Swing button!");
//ImageIcon buttonImgIcon = loadImageIcon("marketplace.gif","I'm a Swing button!");
//JButton button = new JButton( houseflyImgIcon );
JButton button = new JButton( buttonImgIcon );
//String groupName = "default";
final Scheduler sched = sf.getScheduler();
serverName = sched.getSchedulerName();
serverInstanceID = sched.getSchedulerInstanceId();
HashMap groupsAndJobsHashMap = new HashMap();
final HashMap jobsAndTriggersHashMap = new HashMap();
groupNames = sched.getJobGroupNames();
if( groupNames != null && groupNames.length > 0 ) {
//groupNames = sched.getTriggerNames( groupName );
for( int i = 0; i < groupNames.length; i++ ) {
jobNames = sched.getJobNames( groupNames[i] );
if( jobNames != null && jobNames.length > 0 ) {
// here we want to squrrel away the jobs somehow...
java.util.List jobNamesList = Arrays.asList( jobNames );
groupsAndJobsHashMap.put( groupNames[i], jobNamesList );
logger.info( "jobNamesList.size(): "+jobNamesList.size()+" for group: "+groupNames[i] );
for( int j = 0; j < jobNames.length; j++ ) {
String thisJobGroupKey = jobNames[j]+groupNames[i];
Object it = jobsAndTriggersHashMap.get( thisJobGroupKey );
if( it == null ) {
logger.info( "\n\n>>>>it == null, getting trigger for job: "+thisJobGroupKey );
Trigger[] triggerArray = sched.getTriggersOfJob( jobNames[j], groupNames[i] );
//java.util.List jobTriggersList = Arrays.asList( triggerArray );
//jobsAndTriggersHashMap.put( thisJobGroupKey, jobTriggersList );
jobsAndTriggersHashMap.put( thisJobGroupKey, triggerArray );
logger.info( ">>>>it == null, stored "+triggerArray.length+
" trigger[s] for job: "+thisJobGroupKey );
} else {
logger.info( "\n\n\n\n>>>>it != null for job: "+thisJobGroupKey+
", shouldn't see this, should be unique!<<<<\n\n\n\n" );
}
}
} else {
logger.info( "jobNames == null && / || jobNames.length =< 0" );
}
}
logger.info( "groupNames != null && groupNames.length > 0" );
} else {
//groupNames = staticJobErrorStringArray;
logger.info( "groupNames == null && / || groupNames.length =< 0, groupNames: "+groupNames+", len: "+groupNames.length );
if( groupNames != null ) {
for( int h = 0; h < groupNames.length; h++ ) {
logger.info( "groupNames["+h+"]: "+groupNames[h] );
}
}
}
labelPrefix = labelPrefix+serverName+", instance: "+serverInstanceID;
//final JLabel label = new JLabel( labelPrefix, SwingConstants.LEFT );
// 60 width label... there's got to be a better way...
//final JLabel label = new JLabel( " ",
// SwingConstants.LEFT );
label.setFont(new Font("SansSerif", Font.PLAIN, 14));
triggerLabel.setFont(new Font("SansSerif", Font.PLAIN, 14));
label.setForeground(Color.black);
triggerLabel.setForeground(Color.black);
setMainLabelText( labelPrefix );
setTriggerLabelText( "Add Jobs:" );
//final JLabel triggerLabel = new JLabel( " ",
// SwingConstants.LEFT );
final JComboBox groupsCombo = new JComboBox( groupNames );
groupsCombo.setFont(new Font("Dialog", Font.BOLD, 14));
if( groupNames != null && groupNames.length > 0 ) {
groupsCombo.setSelectedIndex( 0 );
groupsCombo.contentsChanged( new ListDataEvent((Object)this, ListDataEvent.CONTENTS_CHANGED, 0, 0 ) );
}
// add the listener later after jobsList, which it refers to, has been created
// list
String firstSelectedGroup = (String)groupsCombo.getSelectedItem();
logger.info( "\n\n>>>>firstSelectedGroup: "+firstSelectedGroup+"<<<<" );
jobNames = sched.getJobNames( firstSelectedGroup );
final JList jobsList = new JList( jobNames );
jobsList.setFont(new Font("Dialog", Font.BOLD, 14));
logger.info( ">>>>jobsList created with firstSelectedGroup, jobNames: "+jobNames+"<<<<\n\n" );
JScrollPane scrollPane = new JScrollPane( jobsList );
if( jobNames != null && jobNames.length > 0 ) {
jobsList.setSelectedIndex( 0 );
}
groupsCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
logger.info( "e.getActionCommand(): "+e.getActionCommand()+
", e.paramString(): "+e.paramString() );
String groupString = (String)groupsCombo.getSelectedItem();
logger.info( "groupString: "+groupString+", calling sched.getJobNames( "+groupString+" )" );
String[] localJobNames = sched.getJobNames( groupString );
if( localJobNames != null && localJobNames.length > 0 ) {
for( int j = 0; j < localJobNames.length; j++ ) {
logger.info( "localJobNames[j]: "+localJobNames[j] );
}
jobsList.setListData( (Object[])localJobNames );
jobsList.setSelectedIndex( 0 );
}
} catch( Exception ex ) {
logger.info(":::::::::::::: Error :::::::::::::::::");
ex.printStackTrace();
}
}
});
// trigers for each job
final JList jobsTriggersList = new JList();
jobsTriggersList.setFont(new Font("Dialog", Font.BOLD, 10));
JScrollPane triggersScrollPane = new JScrollPane( jobsTriggersList );
jobsTriggersList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
logger.info( "\n\n>>>>jobsTriggersList.valueChanged() called, class: "+this.getClass().getName()+"<<<<\n\n" );
if (e.getValueIsAdjusting() == false) {
logger.info( "about to call jobsTriggersList.getSelectedIndex()" );
if (jobsTriggersList.getSelectedIndex() == -1) {
//No selection, disable fire button.
//fireButton.setEnabled(false);
logger.info( "no selection...." );
logger.info( "no selection, jobsList.getSelectedIndex(): "+jobsTriggersList.getSelectedIndex() );
//logger.info( "no selection, jobsList.getSelectedValue(): "+jobsTriggersList.getSelectedValue() );
} else {
//Selection, enable the fire button.
//fireButton.setEnabled(true);
//String job = (String)jobsList.getSelectedValue();
//String group = (String)groupsCombo.getSelectedItem();
//logger.info( "this job is: "+job );
//logger.info( "this group is: "+group );
logger.info( "has selection...." );
logger.info( "has selection, jobsList.getSelectedIndex(): "+jobsTriggersList.getSelectedIndex() );
if( jobsTriggersList.getModel().getSize() > 0 ) {
logger.info( ">>>jobsTriggersList.getModel().getSize() > 0: "+jobsTriggersList.getModel().getSize()+"<<<" );
logger.info( "has selection, jobsList.getSelectedValue(): "+jobsTriggersList.getSelectedValue() );
logger.info( "this trigger is: "+jobsTriggersList.getSelectedValue() );
Trigger trigger = (Trigger)jobsTriggersList.getSelectedValue();
logger.info( "trigger: "+trigger );
if( trigger != null ) {
logger.info( ">>>trigger != null<<<" );
setTriggerLabelText( trigger.getFullName()+"::"+
( (trigger instanceof CronTrigger)?((CronTrigger)trigger).getCronExpression():"SimpleTrigger" )+
trigger.getNextFireTime()
);
} else {
logger.info( ">>>trigger == null<<<" );
}
} else {
logger.info( ">>>jobsTriggersList.getModel().getSize() <= 0: "+jobsTriggersList.getModel().getSize()+" <<<" );
}
}
}
logger.info( "leaving jobsTriggersList.valueChanged()..." );
}
});
jobsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
logger.info( "\n\n>>>>####jobsList.valueChanged() called, class: "+this.getClass().getName()+"<<<<\n\n" );
if (e.getValueIsAdjusting() == false) {
if (jobsList.getSelectedIndex() == -1) {
//No selection, disable fire button.
//fireButton.setEnabled(false);
logger.info( "no selection...." );
logger.info( "no selection, jobsList.getSelectedIndex(): "+jobsList.getSelectedIndex() );
//logger.info( "no selection, jobsList.getSelectedValue(): "+jobsList.getSelectedValue() );
} else {
//Selection, enable the fire button.
//fireButton.setEnabled(true);
if( jobsList.getModel().getSize() > 0 ) {
logger.info( ">>>jobsList.getModel().getSize() > 0: "+jobsList.getModel().getSize()+"<<<" );
logger.info( "this job is: "+jobsList.getSelectedValue() );
try {
Trigger[] thisJobsTriggers
= sched.getTriggersOfJob( (String)jobsList.getSelectedValue(),
(String)groupsCombo.getSelectedItem() );
jobsTriggersList.setListData( (Object[])thisJobsTriggers );
jobsTriggersList.setSelectedIndex( 0 );
logger.info( "this trigger is: "+jobsTriggersList.getSelectedValue() );
Trigger trigger = (Trigger)jobsTriggersList.getSelectedValue();
if( trigger != null ) {
setTriggerLabelText( trigger.getFullName()+"::"+
( (trigger instanceof CronTrigger)?((CronTrigger)trigger).getCronExpression():"SimpleTrigger" )+
"::"+
trigger.getNextFireTime()
);
}
} catch( SchedulerException se ) {
setMainLabelText( se.toString() );
logger.error( "caught a SchedulerException: "+se+", msg: "+se.getMessage() );
se.printStackTrace();
}
} else {
logger.info( ">>>jobsList.getModel().getSize() <= 0: "+jobsList.getModel().getSize()+" <<<" );
}
} //if( jobsList.getSelectedIndex() == -1) ELSE
}
}
});
// now set the first trigger of the first selected job and make it show on the label
// this'll be my next problem with an empty server
logger.info( "\n\n\n\n>>>>here we go...<<<<\n\n\n\n" );
if( jobsList.getModel().getSize() > 0 ) {
logger.info( "\n\n\n\n>>>>jobsList.getModel().getSize() > 0<<<<\n\n\n\n" );
try {
Trigger[] thisJobsTriggers
= sched.getTriggersOfJob( (String)jobsList.getSelectedValue(),
(String)groupsCombo.getSelectedItem() );
jobsTriggersList.setListData( (Object[])thisJobsTriggers );
jobsTriggersList.setSelectedIndex( 0 );
logger.info( "\n\n\n\n>>>>FIRST trigger is: "+jobsTriggersList.getSelectedValue()+"<<<<\n\n\n\n" );
Trigger trigger = (Trigger)jobsTriggersList.getSelectedValue();
if( trigger != null ) {
setTriggerLabelText( trigger.getFullName()+"::"+
( (trigger instanceof CronTrigger)?((CronTrigger)trigger).getCronExpression():"SimpleTrigger" )+
"::"+
trigger.getNextFireTime()
);
}
} catch( SchedulerException se ) {
setMainLabelText( se.toString() );
logger.error( "caught a SchedulerException: "+se+", msg: "+se.getMessage() );
se.printStackTrace();
}
} else {
logger.info( "\n\n\n\n>>>>jobsList.getModel().getSize() <= 0<<<<\n\n\n\n" );
}
//final JLabel childSaysHelloLabel = new JLabel( "", houseflyImgIcon, SwingConstants.RIGHT );
final JButton deleteJobButton = new JButton( "delete", houseflyImgIcon );
deleteJobButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
try {
String jobName = (String)jobsList.getSelectedValue();
String groupName = (String)groupsCombo.getSelectedItem();
setMainLabelText( labelPrefix+"deleting job: "+jobName+", group: "+groupName );
logger.info( "deleting job: "+jobName+", group: "+groupName );
sched.deleteJob( jobName, groupName );
String[] localJobNames = sched.getJobNames( groupName );
if( localJobNames != null && localJobNames.length > 0 ) {
for( int j = 0; j < localJobNames.length; j++ ) {
logger.info( "localJobNames[j]: "+localJobNames[j] );
}
jobsList.setListData( (Object[])localJobNames );
} else {
String[] none = { "" };
jobsList.setListData( (Object[])none );
groupsCombo.removeItem( (Object)groupName );
groupsCombo.setSelectedIndex( 0 );
}
} catch( Exception ex ) {
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
});
//final JLabel parentSaysHelloLabel = new JLabel( "", houseflyImgIcon, SwingConstants.RIGHT );
final JButton pauseJobButton = new JButton( "delete all", houseflyImgIcon );
pauseJobButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText(labelPrefix + numClicks);
try {
groupsCombo.removeAllItems();
setMainLabelText( labelPrefix+"deleting all jobs... " );
logger.info( "deleting all jobs... " );
String[] groups = sched.getTriggerGroupNames();
for(int i=0; i < groups.length; i++) {
String[] names = sched.getTriggerNames(groups[i]);
for(int j=0; j < names.length; j++) {
sched.unscheduleJob(names[j], groups[i]);
System.err.println( "Trigger Name: "+names[j]+", Group: "+groups[i] );
}
}
groups = sched.getJobGroupNames();
for(int i=0; i < groups.length; i++) {
String[] names = sched.getJobNames(groups[i]);
for(int j=0; j < names.length; j++) {
sched.deleteJob(names[j], groups[i]);
System.err.println( "Job Name: "+names[j]+", Group: "+groups[i] );
}
}
String[] localJobNames = sched.getJobNames( (String)groupsCombo.getSelectedItem() );
if( localJobNames != null && localJobNames.length > 0 ) {
for( int j = 0; j < localJobNames.length; j++ ) {
logger.info( "localJobNames[j]: "+localJobNames[j] );
}
jobsList.setListData( (Object[])localJobNames );
} else {
String[] none = { "" };
jobsList.setListData( (Object[])none );
}
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( uoe.toString() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( ex.toString() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex+"\nmsg: "+ex.getMessage());
ex.printStackTrace();
}
}
});
//final JLabel parentMethodOnlyLabel = new JLabel( "", houseflyImgIcon, SwingConstants.RIGHT );
final JButton resumeJobButton = new JButton( "last fired", houseflyImgIcon );
resumeJobButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText(labelPrefix + numClicks);
if( jobsTriggersList.getModel().getSize() > 0 ) {
try {
String jobName = (String)jobsList.getSelectedValue();
String groupName = (String)groupsCombo.getSelectedItem();
Trigger trigger = (Trigger)jobsTriggersList.getSelectedValue();
Date date = trigger.getPreviousFireTime();
logger.info( "job: "+jobName+", group: "+groupName+" last fired: "+date );
setMainLabelText( "job: "+jobName+", group: "+groupName+" last fired: "+date );
//sched.resumeJob( jobName, groupName );
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( uoe.toString() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( ex.toString() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
}
});
//final JLabel callParentBeanLabel = new JLabel( "", houseflyImgIcon, SwingConstants.RIGHT );
final JButton triggerJobButton = new JButton( "trigger", houseflyImgIcon );
triggerJobButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText(labelPrefix + numClicks);
try {
String jobName = (String)jobsList.getSelectedValue();
String groupName = (String)groupsCombo.getSelectedItem();
logger.info( "triggering job: "+jobName+", group: "+groupName );
sched.triggerJob( jobName, groupName );
setMainLabelText("triggered: job: "+jobName+", group: "+groupName);
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( "UnsupportedOperationException: "+uoe.getMessage() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( "Exception: "+ex.getMessage() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
});

final JButton anotherButton = new JButton( "next fire", houseflyImgIcon );
anotherButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText("ha ha, it's a trigger!");
try {
String jobName = (String)jobsList.getSelectedValue();
String groupName = (String)groupsCombo.getSelectedItem();
Trigger trigger = (Trigger)jobsTriggersList.getSelectedValue();
Date date = trigger.getNextFireTime();
logger.info( "job: "+jobName+", group: "+groupName+" last fired: "+date );
setMainLabelText( "job: "+jobName+", group: "+groupName+" will fire next at: "+date );
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( "UnsupportedOperationException: "+uoe.getMessage() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( "Exception: "+ex.getMessage() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
});
final JButton moButton = new JButton( "kill quartz", houseflyImgIcon );
moButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText("ha ha, it's a trigger!");
try {
String jobName = (String)jobsList.getSelectedValue();
String groupName = (String)groupsCombo.getSelectedItem();
setMainLabelText( "atttempting to shutdown quartz..." );
sched.shutdown( true );
if( sched.isShutdown() ) {
setMainLabelText( "quartz has been successfully shutdown" );
} else {
setMainLabelText( "quartz was NOT successfully shutdown" );
}
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( "UnsupportedOperationException: "+uoe.getMessage() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( "Exception: "+ex.getMessage() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
});
final JTextField jobNameTextField = new JTextField("jobName");
jobNameTextField.setFont(new Font("Dialog", Font.BOLD, 14));
final JTextField groupNameTextField = new JTextField("groupName");
groupNameTextField.setFont(new Font("Dialog", Font.BOLD, 14));
final JTextField cronExpressionTextField = new JTextField("0 45 1 ? * *");
cronExpressionTextField.setFont(new Font("Dialog", Font.BOLD, 14));
JButton doneButton = new JButton( "done" );
JButton addButton = new JButton( "add" );
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String origGroupName = null;
if( groupsCombo.getModel().getSize() > 0 ) {
origGroupName = (String)groupsCombo.getSelectedItem();
logger.info( ">>>===+- model size > 0, origGroupName: "+origGroupName );
} else {
logger.info( ">>>===+- model size <= 0, origGroupName: "+origGroupName );
}
String jobName = jobNameTextField.getText();
String groupName = groupNameTextField.getText();
String triggerName = jobName+"."+groupName+"Trigger";
String cronExpression = cronExpressionTextField.getText();
logger.info( "creating job: "+jobName+", group: "+groupName );
//JobDetail job 15= new JobDetail("10afterJob4", "10-after-group", ProcessNotificationsInDBJob.class);
JobDetail job = new JobDetail(jobName, groupName, ProcessNotificationsInDBJob.class);
JobDataMap map = new JobDataMap();
map.put("msg", "send notifications job is executing!");
job.setJobDataMap(map);
//CronTrigger ct = new CronTrigger("10afterTrigger4", "10-after-group", "10afterJob4",
// "10-after-group", new Date(), null, "0 55 * ? * *");
CronTrigger ct = new CronTrigger( triggerName, groupName, jobName,
groupName, new Date(), null, cronExpression );
//String[] innergroups = sched.getJobGroupNames();
//java.util.List groupNamesList = Arrays.asList( innergroups );
// add to the combo box if the group doesn't already exist
boolean foundit = false;
boolean foundOrigGroup = false;
Date ft = sched.scheduleJob(job, ct);
setMainLabelText( ft.toString() );
logger.info( "\n\n\n\n>>>>: "+job.getFullName()+" will run at: "
+ft+" & repeat based on expression: "+ct.getCronExpression()+"\n\n\n\n");
logger.info(">>>> job scheduled.<<<<");
groupsCombo.removeAllItems();
String[] innergroups = sched.getJobGroupNames();
for( int l = 0; l < innergroups.length; l++ ) {
groupsCombo.addItem( (Object)innergroups[l] );
if( innergroups[l].equalsIgnoreCase( groupName ) ) {
foundit = true;
}
// -=j=-: this used to say groupName, but I think that's wrong, as we're talking
// orig group[ here... I could be wrong though!
if( innergroups[l].equalsIgnoreCase( origGroupName ) ) {
foundOrigGroup = true;
}
}
if( foundit ) {
logger.info( ">>>===+- foundit: "+foundit+", calling setSelectedItem( "+groupName+" )" );
groupsCombo.setSelectedItem( groupName );
} else if( foundOrigGroup ) {
logger.info( ">>>===+- foundit: "+foundit+", found foundOrigGroup: "+foundOrigGroup+
", calling setSelectedItem( "+origGroupName+" )" );
groupsCombo.setSelectedItem( origGroupName );
} else {
logger.info( ">>>===+- foundit: "+foundit+", found foundOrigGroup: "+foundOrigGroup+
", calling setSelectedIndex( "+0+" )" );
groupsCombo.setSelectedIndex( 0 );
}
if( groupsCombo.getModel().getSize() > 0 ) {
String[] localJobNames = sched.getJobNames( (String)groupsCombo.getSelectedItem() );
if( localJobNames != null && localJobNames.length > 0 ) {
for( int j = 0; j < localJobNames.length; j++ ) {
logger.info( "localJobNames[j]: "+localJobNames[j] );
}
jobsList.setListData( (Object[])localJobNames );
}
}
} catch( UnsupportedOperationException uoe ) {
setMainLabelText( "UnsupportedOperationException: "+uoe.getMessage() );
logger.info( ":::::::::::::: UnsupportedOperationException :::::::::::::::::"+uoe );
uoe.printStackTrace();
} catch( Exception ex ) {
setMainLabelText( "Exception: "+ex.getMessage() );
logger.info( ":::::::::::::: Exception :::::::::::::::::"+ex );
ex.printStackTrace();
}
}
});
button.setMnemonic('i');
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
numClicks++;
setMainLabelText(labelPrefix + numClicks);
try {
if( !serverPaused ) {
logger.info( "pausing all jobs..." );
setMainLabelText( "pausing all jobs..." );
sched.pauseAll();
serverPaused = true;
logger.info( "all jobs paused" );
setMainLabelText( "all jobs paused" );
} else {
logger.info( "resuming all jobs..." );
setMainLabelText( "resuming all jobs..." );
sched.resumeAll();
serverPaused = false;
logger.info( "all jobs resumed" );
setMainLabelText( "all jobs resumed" );
}
} catch( Exception ex ) {
logger.error( ":::::::::::::: Exception :::::::::::::::::"+ex );
logger.error( "msg: "+ex.getMessage() );
setMainLabelText( ex.toString() );
ex.printStackTrace();
}
}
});
label.setLabelFor(button);
doneButton.setMnemonic('q');
doneButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
/*
* An easy way to put space between a top-level container
* and its contents is to put the contents in a JPanel
* that has an "empty" border.
*/
pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
10, //top
10, //left
5, //bottom
10) //right
);
// for GrigLayout
//pane.setLayout(new GridLayout(0, 1));
//pane.add(button);
//pane.add(label);
pane.setLayout(new BorderLayout());
pane.add( button, "Center" );
// -=j=-: here create a box for the 3-4 labels
JPanel labelBoxPane = new JPanel();
labelBoxPane.setLayout(new BoxLayout( labelBoxPane, BoxLayout.Y_AXIS ));
//labelBoxPane.add( label );

// right here add a horizontal box with top main label
JPanel horizMainLabelBoxPane = new JPanel();
horizMainLabelBoxPane.setLayout(new BoxLayout( horizMainLabelBoxPane, BoxLayout.X_AXIS ));
// horizontal box with top main label
horizMainLabelBoxPane.add( label );
labelBoxPane.add( horizMainLabelBoxPane );

// right here add a horizontal box with buttons
JPanel horizButtonBoxPane = new JPanel();
horizButtonBoxPane.setLayout(new BoxLayout( horizButtonBoxPane, BoxLayout.X_AXIS ));
// horizontal box of buttons
horizButtonBoxPane.add( deleteJobButton );
horizButtonBoxPane.add( pauseJobButton );
horizButtonBoxPane.add( resumeJobButton );
horizButtonBoxPane.add( triggerJobButton );
horizButtonBoxPane.add( anotherButton );
horizButtonBoxPane.add( moButton );
labelBoxPane.add( horizButtonBoxPane );
// get horiz button box dimensions
Dimension dim = horizButtonBoxPane.getPreferredSize();
Double widthDouble = new Double( dim.getWidth() );
Double heightDouble = new Double( dim.getHeight() );
logger.info( "}}}}*horizButtonBoxPane w:"+dim.getWidth()+", h: "+dim.getHeight()+"*{{{{" );
Dimension dimForWindow = new Dimension( widthDouble.intValue(), heightDouble.intValue() );
labelBoxPane.add( groupsCombo );
labelBoxPane.add( scrollPane );
labelBoxPane.add( triggersScrollPane );
// right here add a horizontal box with a label for displaying triggers
JPanel horizLabelBoxPane = new JPanel();
horizLabelBoxPane.setLayout(new BoxLayout( horizLabelBoxPane, BoxLayout.X_AXIS ));
horizLabelBoxPane.add( triggerLabel );
labelBoxPane.add( horizLabelBoxPane );
// right here add a horizontal box with textfields
JPanel horizTextFieldBoxPane = new JPanel();
horizTextFieldBoxPane.setLayout(new BoxLayout( horizTextFieldBoxPane, BoxLayout.X_AXIS ));
horizTextFieldBoxPane.add( jobNameTextField );
horizTextFieldBoxPane.add( groupNameTextField );
horizTextFieldBoxPane.add( cronExpressionTextField );
labelBoxPane.add( horizTextFieldBoxPane );
JPanel addBttnGridPane = new JPanel();
addBttnGridPane.setLayout( new GridLayout( 1, 1 ) );
addBttnGridPane.add( addButton );
JPanel quitBttnGridPane = new JPanel();
quitBttnGridPane.setLayout( new GridLayout( 1, 1 ) );
quitBttnGridPane.add( addButton );
quitBttnGridPane.add( doneButton );
labelBoxPane.add( quitBttnGridPane );
pane.add( labelBoxPane, "South" );
pane.setPreferredSize( dimForWindow );
pane.setMinimumSize( dimForWindow );
pane.setMaximumSize( dimForWindow );
} catch( Exception e ) {
groupNames = staticJobErrorStringArray;
logger.info( "caught Exception, so using static [meaningless] job list!: "
+e+", class: "+e.getClass().getName()+", trace:\n" );
e.printStackTrace();
}
return pane;
}
public ImageIcon loadImageIcon(String filename, String description)
{
/*
URL url;
try {
url = new URL(this.getDocumentBase(),filename);
} catch (MalformedURLException cant) {
Debug.spew(5,"Error trying to load image " + filename);
return null;
}
return new ImageIcon(url, description);
*/
return new ImageIcon(filename, description);
}
public Context getInitialContext() throws Exception {
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
if (user != null) {
logger.info("user: " + user);
h.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
h.put(Context.SECURITY_CREDENTIALS, password);
}
return new InitialContext(h);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch( Exception e ) {
System.err.println( "Caught an Exception calling UIManager.setLookAndFeel(..[metal]..): "+e );
System.err.println( "Caught an Exception, msg: "+e.getMessage() );
e.printStackTrace();
}
//Create the top-level container and add contents to it.
JFrame frame = new JFrame("QuartzJobManager");
QuartzJobManager app = new QuartzJobManager( new org.quartz.impl.StdSchedulerFactory() );
Component contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
Dimension dim = contents.getPreferredSize();
Double widthDouble = new Double( dim.getWidth() );
Double heightDouble = new Double( dim.getHeight() );
//System.out.println( "$$$$}}}}*contents (pane) w:"+dim.getWidth()+", h: "+dim.getHeight()+"*{{{{" );
Dimension dimForWindow = new Dimension( widthDouble.intValue(), heightDouble.intValue() );
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setBounds( 20, 40, 28+widthDouble.intValue(), ((widthDouble.intValue()/2) +(widthDouble.intValue()/4) ) );
//frame.pack();
frame.setVisible(true);
}
}
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I tried both animated gif's as well as non-animated gifs. I created a simple program just to test my image code but still no gif is showing. Can anybody see the problem? The image should fall between the two labels.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
This works fine for me (it's your code but trimmed down to show just the label):

The animated gif only cycles through one time though. I swear I tried animated gifs a year or so ago and it kept cycling.
brian
[ February 05, 2004: Message edited by: Brian Pipa ]

My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Thanks but still nothing. I copied your code and added the full directory name to my gif but nada. Could there be a setting in my editor that is stoping that? I'm using Sun One Studio Community Edition with Java 1.4.1.
I don't understand it.
Thanks,
Craig
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
I just changed my code to have a full path and it worked fine:
ImageIcon icon = new ImageIcon("c:\\downloads\\goliath.gif");
So did this:
ImageIcon icon = new ImageIcon("c:/downloads/goliath.gif");
Maybe detail the steps you took ot compile and run my sample code and we can figure out what's wrong?
Brian
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I'm not sure where Sun One puts class files, or how it runs your programs. It could be a problem if your program is running in a different directory than you think it is... ( though if you use an absolute path to the image it should work... )

Your program is working fine for me... try putting the image and the class file in the same directory and running your program from the command line.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
This works too. Try this (obviously chaneg the URL to point to a file on your HD. If it still doesn't work, uncomment the javaranch URL in the code (and comment out the URL to your local file) and try it with that and see if that works (it should)
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Thanks for all your help. It's working now. I still can't get the image to load without pointing to the full directory address. But that's OK. It turned out the reason why the full direcory wasn't working before was because I had the wrong slashes in there. I must have looked at that a hundred times.
Thanks again for your help.
Craig
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: running gifs
 
Similar Threads
panel and image problem
How delete the specify item on the JComboBox immediately.
Icon and JManuBar
Mouse shift event coding - to trigger a predetermined sequence of images to a GUI
Card layout...