简单问题(庆祝春节)

geelpheels 2007-02-18 12:24:12
java.io.IOException: failed to load image contents
at javax.swing.ImageIcon.writeObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.access$100(Unknown Source)
at java.io.ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.awt.Container.writeObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.access$100(Unknown Source)
at java.io.ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.awt.Container.writeObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.access$100(Unknown Source)
at java.io.ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.awt.Container.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.beans.PropertyChangeSupport.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
......


PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
pg.grabPixels();
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
throw new IOException("failed to load image contents");


可能是什么问题呢?
...全文
644 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
geelpheels 2007-02-23
  • 打赏
  • 举报
回复
public void BackupListeners() {
if (branch) {
while (!listenerStack.isEmpty()) {
listenerStack.pop();
}
while (!loaderStack.isEmpty()){
loaderStack.pop();
}

while (!visualStack.isEmpty()){
visualStack.pop();
}

branch = false;

}
backup_listeners = (Vector) m_listeners.clone();
try{
SerializedObject so = new SerializedObject(m_Loader);
backup_loader = (weka.core.converters.Loader)so.getObject();

so = new SerializedObject(m_visual);
backup_visual =(BeanVisual)so.getObject(); /************An exception thrown************/
}
catch(Exception ex){
ex.printStackTrace();
System.err.print("serialize failed!");
}
if (deep < 20) {
listenerQuene.add(backup_listeners);
loaderQuene.add(backup_loader);

visualQueue.add(backup_visual);

deep++;
instanceEventArray[deep] = m_instanceEventTargets;
dataSetEventArray[deep] = m_dataSetEventTargets;

} else {
listenerQuene.remove(0);
listenerQuene.add(backup_listeners);

loaderQuene.remove(0);
loaderQuene.add(backup_loader);

visualQueue.remove(0);
visualQueue.add(backup_visual);

for (int index = 0; index < dataSetEventArray.length - 1; index++) {
instanceEventArray[index] = instanceEventArray[index + 1];
dataSetEventArray[index] = dataSetEventArray[index + 1];
}
instanceEventArray[deep] = m_instanceEventTargets;
dataSetEventArray[deep] = m_dataSetEventTargets;
}
layout_update = true;
cursor = deep;

}

public void RestoreListeners() {
branch = true;
backup_listeners = (Vector) listenerQuene.get(deep);
listenerStack.push((Vector) (m_listeners.clone()));

backup_loader = (weka.core.converters.Loader)loaderQuene.get(deep);
loaderStack.push(backup_loader);

backup_visual = (BeanVisual) visualQueue.get(deep);
visualStack.push(backup_visual);

if (deep > 0) {
listenerQuene.remove(deep);
loaderQuene.remove(deep);

visualQueue.remove(deep);

deep--;
}
try{
m_listeners = backup_listeners;
setLoaderIgnoreVisualName(backup_loader);
m_Loader.setSource(((FileSourcedConverter)m_Loader).retrieveFile());

setVisual(backup_visual);

}
catch(Exception ex){
System.err.print("setsource failed!");
}

if (layout_update) {
instanceEventArray[deep + 2] = m_instanceEventTargets;
dataSetEventArray[deep + 2] = m_dataSetEventTargets;
layout_update = false;
}
if (!downwards) {

cursor--;
m_instanceEventTargets = instanceEventArray[cursor];
m_dataSetEventTargets = dataSetEventArray[cursor];
cursor--;
} else {

if (cursor >= 0) {

m_instanceEventTargets = instanceEventArray[cursor];
m_dataSetEventTargets = dataSetEventArray[cursor];
cursor--;
}
}
downwards = true;
}

public void ForwardRecovery() {
if (branch) {
Stack tempStack = (Stack) listenerStack.clone();
tempStack.pop();
listenerQuene.add(m_listeners.clone());
try {
SerializedObject so = new SerializedObject(m_Loader);
loaderQuene.add(so.getObject());

so = new SerializedObject(m_visual);
visualQueue.add(so.getObject());

} catch (Exception ex) {
System.err.print("forward serialize failed!");
}
deep++;
try {
if (!tempStack.isEmpty()) {
m_listeners = (Vector) (listenerStack.pop());
setLoaderIgnoreVisualName((weka.core.converters.Loader) loaderStack.pop());
m_Loader.setSource(((FileSourcedConverter) m_Loader)
.retrieveFile());

setVisual((BeanVisual)visualStack.pop());

} else {
m_listeners = (Vector) (listenerStack.peek());
setLoaderIgnoreVisualName((weka.core.converters.Loader) loaderStack.peek());
m_Loader.setSource(((FileSourcedConverter) m_Loader)
.retrieveFile());


setVisual((BeanVisual)visualStack.peek());
}
} catch (Exception ex) {
System.err.print("setSource failed!");
}
if (downwards) {
cursor += 2;
m_instanceEventTargets = instanceEventArray[cursor];
m_dataSetEventTargets = dataSetEventArray[cursor];
cursor--;

} else {
if (cursor <= 20) {
cursor++;
m_instanceEventTargets = instanceEventArray[cursor];
m_dataSetEventTargets = dataSetEventArray[cursor];

}
}
}
}

public void setFilePath(String file){
f = file;
}

public String getFilePath(){
return f;
}

public static void main(String[] args) {
try {
final javax.swing.JFrame jf = new javax.swing.JFrame();
jf.getContentPane().setLayout(new java.awt.BorderLayout());

final Loader tv = new Loader();

jf.getContentPane().add(tv, java.awt.BorderLayout.CENTER);
jf.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
jf.dispose();
System.exit(0);
}
});
jf.setSize(800, 600);
jf.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void setLoaderIgnoreVisualName(weka.core.converters.Loader loader) {
boolean loadImages = true;
if (loader.getClass().getName()
.compareTo(m_Loader.getClass().getName()) == 0) {
loadImages = false;
}
m_Loader = loader;
String loaderName = loader.getClass().toString();
loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1,
loaderName.length());
if (loadImages) {
if (m_Loader instanceof Visible) {
m_visual = ((Visible) m_Loader).getVisual();
} else {

if (!m_visual.loadIcons(BeanVisual.ICON_PATH + loaderName
+ ".gif", BeanVisual.ICON_PATH + loaderName
+ "_animated.gif")) {
useDefaultVisual();
}
}
}

if (!(loader instanceof DatabaseLoader)) {
try {
m_dataFormat = m_Loader.getStructure();
System.err
.println("Notifying listeners of instance structure avail. (Loader).");
notifyStructureAvailable(m_dataFormat);
} catch (Exception ex) {
}
}

m_globalInfo = KnowledgeFlowApp.getGlobalInfo(m_Loader);
}

}
geelpheels 2007-02-23
  • 打赏
  • 举报
回复
public void setLoader(weka.core.converters.Loader loader) {
boolean loadImages = true;
if (loader.getClass().getName()
.compareTo(m_Loader.getClass().getName()) == 0) {
loadImages = false;
}
m_Loader = loader;
String loaderName = loader.getClass().toString();
loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1,
loaderName.length());
if (loadImages) {
if (m_Loader instanceof Visible) {
m_visual = ((Visible) m_Loader).getVisual();
} else {

if (!m_visual.loadIcons(BeanVisual.ICON_PATH + loaderName
+ ".gif", BeanVisual.ICON_PATH + loaderName
+ "_animated.gif")) {
useDefaultVisual();
}
}
}
m_visual.setText(loaderName);

if (!(loader instanceof DatabaseLoader)) {
try {
m_dataFormat = m_Loader.getStructure();
System.err
.println("Notifying listeners of instance structure avail. (Loader).");
notifyStructureAvailable(m_dataFormat);
} catch (Exception ex) {
}
}

m_globalInfo = KnowledgeFlowApp.getGlobalInfo(m_Loader);
}

public weka.core.converters.Loader getLoader() {
return m_Loader;
}

public void setWrappedAlgorithm(Object algorithm) {

if (!(algorithm instanceof weka.core.converters.Loader)) {
throw new IllegalArgumentException(algorithm.getClass()
+ " : incorrect " + "type of algorithm (Loader)");
}
setLoader((weka.core.converters.Loader) algorithm);
}

public Object getWrappedAlgorithm() {
return getLoader();
}

protected void notifyStructureAvailable(Instances structure) {
if (m_dataSetEventTargets > 0 && structure != null) {
DataSetEvent dse = new DataSetEvent(this, structure);
notifyDataSetLoaded(dse);
} else if (m_instanceEventTargets > 0 && structure != null) {
m_ie.setStructure(structure);
notifyInstanceLoaded(m_ie);
}
}

protected void notifyDataSetLoaded(DataSetEvent e) {
Vector l;
synchronized (this) {
l = (Vector) m_listeners.clone();
}

if (l.size() > 0) {
for (int i = 0; i < l.size(); i++) {
((DataSourceListener) l.elementAt(i)).acceptDataSet(e);
}
m_dataSet = null;
}
}

protected void notifyInstanceLoaded(InstanceEvent e) {
Vector l;
synchronized (this) {
l = (Vector) m_listeners.clone();
}

if (l.size() > 0) {
for (int i = 0; i < l.size(); i++) {
((InstanceListener) l.elementAt(i)).acceptInstance(e);
}
m_dataSet = null;
}
}

public void startLoading() {
if (m_ioThread == null) {
// m_visual.setText(m_dataSetFile.getName());
m_ioThread = new LoadThread(Loader.this);
m_ioThread.setPriority(Thread.MIN_PRIORITY);
m_ioThread.start();
} else {
m_ioThread = null;
}
}

public Enumeration enumerateRequests() {
Vector newVector = new Vector(0);
boolean ok = true;
if (m_ioThread == null) {
if (m_Loader instanceof FileSourcedConverter) {
if (!((FileSourcedConverter) m_Loader).retrieveFile().isFile()) {
ok = false;
}
}
String entry = "Start loading";
if (!ok) {
entry = "$" + entry;
}
newVector.addElement(entry);
}
return newVector.elements();
}

public void performRequest(String request) {
if (request.compareTo("Start loading") == 0) {
startLoading();
} else {
throw new IllegalArgumentException(request
+ " not supported (Loader)");
}
}

public boolean eventGeneratable(String eventName) {
if (eventName.compareTo("instance") == 0) {
if (!(m_Loader instanceof weka.core.converters.IncrementalConverter)) {
return false;
}
if (m_dataSetEventTargets > 0) {
return false;
}
}

if (eventName.compareTo("dataSet") == 0) {
if (!(m_Loader instanceof weka.core.converters.BatchConverter)) {
return false;
}
if (m_instanceEventTargets > 0) {
return false;
}
}
return true;
}

public synchronized void addDataSourceListener(DataSourceListener dsl) {
super.addDataSourceListener(dsl);
m_dataSetEventTargets++;
// pass on any current instance format
try {
if (m_dbSet) {
m_dataFormat = m_Loader.getStructure();
m_dbSet = false;
}
} catch (Exception ex) {
}
notifyStructureAvailable(m_dataFormat);
}

public synchronized void removeDataSourceListener(DataSourceListener dsl) {
super.removeDataSourceListener(dsl);
m_dataSetEventTargets--;
}

public synchronized void addInstanceListener(InstanceListener dsl) {
super.addInstanceListener(dsl);
m_instanceEventTargets++;
try {
if (m_dbSet) {
m_dataFormat = m_Loader.getStructure();
m_dbSet = false;
}
} catch (Exception ex) {
}
// pass on any current instance format
notifyStructureAvailable(m_dataFormat);
}

public synchronized void removeInstanceListener(InstanceListener dsl) {
super.removeInstanceListener(dsl);
m_instanceEventTargets--;
}
geelpheels 2007-02-23
  • 打赏
  • 举报
回复
异常是这里抛出的:/************An exception thrown************/


package weka.gui.beans;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.InputEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.io.Serializable;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Enumeration;
import java.io.IOException;
import java.beans.beancontext.*;
import javax.swing.JButton;

import weka.core.Instance;
import weka.core.Instances;
import weka.core.SerializedObject;
import weka.core.converters.*;

public class Loader extends AbstractDataSource implements UserRequestAcceptor,
WekaWrapper, EventConstraints, Recoverable {

private transient Instances m_dataSet;

private transient Instances m_dataFormat;

protected String m_globalInfo;

private LoadThread m_ioThread;

private weka.core.converters.Loader m_Loader = new ArffLoader();

private InstanceEvent m_ie = new InstanceEvent(this);

private int m_instanceEventTargets = 0;

private int backup_instanceEventTargets = 0;

private int m_dataSetEventTargets = 0;

private int backup_dataSetEventTargets = 0;

private ArrayList listenerQuene = new ArrayList();
private ArrayList loaderQuene = new ArrayList();

private Stack listenerStack = new Stack();
private Stack loaderStack = new Stack();

private ArrayList visualQueue = new ArrayList();
private Stack visualStack = new Stack();
private BeanVisual backup_visual;

private weka.core.converters.Loader backup_loader;



int[] instanceEventArray = new int[30];

int[] dataSetEventArray = new int[30];

int cursor = 19;

int deep = -1;

boolean layout_update = false;

boolean downwards = true;

boolean branch = false;

private String f;

private boolean m_dbSet = false;

private class LoadThread extends Thread {
private DataSource m_DP;

public LoadThread(DataSource dp) {
m_DP = dp;
}

public void run() {
try {
m_visual.setAnimated();
boolean instanceGeneration = true;
if (m_dataSetEventTargets > 0) {
instanceGeneration = false;
}

if (instanceGeneration) {
Instance nextInstance = null;
Instances structure = null;
try {
m_Loader.reset();
System.err.println("NOTIFYING STRUCTURE AVAIL");
structure = m_Loader.getStructure();
notifyStructureAvailable(structure);
} catch (IOException e) {
e.printStackTrace();
}
try {
nextInstance = m_Loader.getNextInstance();
} catch (IOException e) {
e.printStackTrace();
}
int z = 0;
while (nextInstance != null) {
nextInstance.setDataset(structure);
m_ie.setStatus(InstanceEvent.INSTANCE_AVAILABLE);
m_ie.setInstance(nextInstance);
nextInstance = m_Loader.getNextInstance();
if (nextInstance == null) {
m_ie.setStatus(InstanceEvent.BATCH_FINISHED);
}
notifyInstanceLoaded(m_ie);
z++;
}
m_visual.setStatic();
} else {
m_dataSet = m_Loader.getDataSet();
m_visual.setStatic();
m_visual.setText(m_dataSet.relationName());
notifyDataSetLoaded(new DataSetEvent(m_DP, m_dataSet));
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
m_ioThread = null;
m_visual.setStatic();
}
}
}

public String globalInfo() {
return m_globalInfo;
}

public Loader() {
super();
setLoader(m_Loader);
appearanceFinal();
}

public void setDB(boolean flag) {

m_dbSet = flag;
}

protected void appearanceFinal() {
removeAll();
setLayout(new BorderLayout());
JButton goButton = new JButton("Start...");
add(goButton, BorderLayout.CENTER);
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startLoading();
}
});
}

protected void appearanceDesign() {
removeAll();
setLayout(new BorderLayout());
add(m_visual, BorderLayout.CENTER);
}

public void setBeanContext(BeanContext bc) {
super.setBeanContext(bc);
if (m_design) {
appearanceDesign();
} else {
appearanceFinal();
}
}
cyong1000 2007-02-23
  • 打赏
  • 举报
回复
你的I/O异常没有处理吧
lc328 2007-02-23
  • 打赏
  • 举报
回复
接分!~~~
geelpheels 2007-02-23
  • 打赏
  • 举报
回复
这是那个SerailizedObject类:

package weka.core;

import java.io.*;
import java.util.zip.*;

public class SerializedObject implements Serializable {

private byte[] m_storedObjectArray;

private boolean m_isCompressed;

public SerializedObject(Object toStore) throws Exception {

this(toStore, false);
}

public SerializedObject(Object toStore, boolean compress) throws Exception {

ByteArrayOutputStream ostream = new ByteArrayOutputStream();
OutputStream os = ostream;
ObjectOutputStream p;
if (!compress)
p = new ObjectOutputStream(new BufferedOutputStream(os));
else
p = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(os)));
p.writeObject(toStore);
p.flush();
p.close(); // used to be ostream.close() !
m_storedObjectArray = ostream.toByteArray();

m_isCompressed = compress;
}

public final boolean equals(Object compareTo) {

if (compareTo == null) return false;
if (!compareTo.getClass().equals(this.getClass())) return false;
byte[] compareArray = ((SerializedObject)compareTo).m_storedObjectArray;
if (compareArray.length != m_storedObjectArray.length) return false;
for (int i=0; i<compareArray.length; i++) {
if (compareArray[i] != m_storedObjectArray[i]) return false;
}
return true;
}

public int hashCode() {

return m_storedObjectArray.length;
}

public Object getObject() {

try {
ByteArrayInputStream istream = new ByteArrayInputStream(m_storedObjectArray);
ObjectInputStream p;
if (!m_isCompressed)
p = new ObjectInputStream(new BufferedInputStream(istream));
else
p = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(istream)));
Object toReturn = p.readObject();
istream.close();
return toReturn;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
shan1119 2007-02-21
  • 打赏
  • 举报
回复
估计就是toStore的问题了,这个类型你是怎么定义的,发上来看下。
hpxs2 2007-02-21
  • 打赏
  • 举报
回复
learnning
Hmilyl 2007-02-21
  • 打赏
  • 举报
回复
I/O Exception
逍遥小飞狼 2007-02-21
  • 打赏
  • 举报
回复
接分~
geelpheels 2007-02-21
  • 打赏
  • 举报
回复


package weka.gui.beans;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.io.Serializable;
import java.awt.*;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;

public class BeanVisual extends JPanel implements Serializable {

public static final String ICON_PATH="weka/gui/beans/icons/";

public static final int NORTH_CONNECTOR = 0;
public static final int SOUTH_CONNECTOR = 1;
public static final int EAST_CONNECTOR = 2;
public static final int WEST_CONNECTOR = 3;


protected String m_iconPath;

protected String m_animatedIconPath;

protected transient ImageIcon m_icon;
protected transient ImageIcon m_animatedIcon;

protected String m_visualName;

protected JLabel m_visualLabel;

private boolean m_stationary = true;

private PropertyChangeSupport m_pcs = new PropertyChangeSupport(this);

private boolean m_displayConnectors = false;
private Color m_connectorColor = Color.blue;

private String m_beanName;

public BeanVisual(String visualName, String iconPath,
String animatedIconPath) {

loadIcons(iconPath, animatedIconPath);
m_visualName = visualName;
m_visualLabel = new JLabel(m_icon);

setLayout(new BorderLayout());

add(m_visualLabel, BorderLayout.CENTER);
Dimension d = m_visualLabel.getPreferredSize();
Dimension d2 = new Dimension((int)d.getWidth() + 10,
(int)d.getHeight() + 10);
setMinimumSize(d2);
setPreferredSize(d2);
setMaximumSize(d2);

m_beanName=m_visualName;
}

public void scale(int factor) {
if (m_icon != null) {
removeAll();
Image pic = m_icon.getImage();
int width = m_icon.getIconWidth();
int height = m_icon.getIconHeight();
int reduction = width / factor;
width -= reduction;
height -= reduction;
pic = pic.getScaledInstance(width, height, Image.SCALE_SMOOTH);
m_icon = new ImageIcon(pic);
m_visualLabel = new JLabel(m_icon);
add(m_visualLabel, BorderLayout.CENTER);
Dimension d = m_visualLabel.getPreferredSize();
Dimension d2 = new Dimension((int)d.getWidth() + 10,
(int)d.getHeight() + 10);
setMinimumSize(d2);
setPreferredSize(d2);
setMaximumSize(d2);
}
}

public boolean loadIcons(String iconPath, String animatedIconPath) {
boolean success = true;
java.net.URL imageURL = ClassLoader.getSystemResource(iconPath);
if (imageURL == null) {
} else {
Image pic = Toolkit.getDefaultToolkit().
getImage(imageURL);

m_icon = new ImageIcon(pic);
if (m_visualLabel != null) {
m_visualLabel.setIcon(m_icon);
}
}

imageURL = ClassLoader.getSystemResource(animatedIconPath);
if (imageURL == null) {
success = false;
} else {
Image pic2 = Toolkit.getDefaultToolkit().
getImage(imageURL);
m_animatedIcon = new ImageIcon(pic2);
}
m_iconPath = iconPath;
m_animatedIconPath = animatedIconPath;
return success;
}

public void setText(String text) {
m_visualName = text;
// m_textLabel.setText(m_visualName);
m_pcs.firePropertyChange("label",null,null);
}

public String getText() {
return m_visualName;
}

public void setStatic() {
m_visualLabel.setIcon(m_icon);
}

public void setAnimated() {
m_visualLabel.setIcon(m_animatedIcon);
}

public Point getClosestConnectorPoint(Point pt) {
int sourceX = getParent().getX();
int sourceY = getParent().getY();
int sourceWidth = getWidth();
int sourceHeight = getHeight();
int sourceMidX = sourceX + (sourceWidth / 2);
int sourceMidY = sourceY + (sourceHeight / 2);
int x = (int)pt.getX();
int y = (int)pt.getY();

Point closest = new Point();
int cx = (Math.abs(x - sourceMidX) < Math.abs(y - sourceMidY)) ?
sourceMidX :
((x < sourceMidX) ? sourceX : sourceX + sourceWidth);
int cy = (Math.abs(y - sourceMidY) < Math.abs(x - sourceMidX)) ?
sourceMidY :
((y < sourceMidY) ? sourceY : sourceY + sourceHeight) ;
closest.setLocation(cx, cy);
return closest;
}

public Point getConnectorPoint(int compassPoint) {
int sourceX = getParent().getX();
int sourceY = getParent().getY();
int sourceWidth = getWidth();
int sourceHeight = getHeight();
int sourceMidX = sourceX + (sourceWidth / 2);
int sourceMidY = sourceY + (sourceHeight / 2);

switch (compassPoint) {
case NORTH_CONNECTOR : return new Point(sourceMidX, sourceY);
case SOUTH_CONNECTOR : return new Point(sourceMidX, sourceY+sourceHeight);
case WEST_CONNECTOR : return new Point(sourceX, sourceMidY);
case EAST_CONNECTOR : return new Point(sourceX+sourceWidth, sourceMidY);
default : System.err.println("Unrecognised connectorPoint (BeanVisual)");
}
return new Point(sourceX, sourceY);
}

public ImageIcon getStaticIcon() {
return m_icon;
}

public ImageIcon getAnimatedIcon() {
return m_animatedIcon;
}

public String getIconPath() {
return m_iconPath;
}

public String getAnimatedIconPath() {
return m_animatedIconPath;
}

public void setDisplayConnectors(boolean dc) {
// m_visualHolder.setDisplayConnectors(dc);
m_displayConnectors = dc;
m_connectorColor = Color.blue;
repaint();
}

public void setDisplayConnectors(boolean dc,
Color c) {
setDisplayConnectors(dc);
m_connectorColor = c;
}

public void addPropertyChangeListener(PropertyChangeListener pcl) {
m_pcs.addPropertyChangeListener(pcl);
}

public void removePropertyChangeListener(PropertyChangeListener pcl) {
m_pcs.removePropertyChangeListener(pcl);
}

public void paintComponent(Graphics gx) {
super.paintComponent(gx);
if (m_displayConnectors) {
gx.setColor(m_connectorColor);

int midx = (int)(this.getWidth() / 2.0);
int midy = (int)(this.getHeight() / 2.0);
gx.fillOval(midx-2, 0, 5, 5);
gx.fillOval(midx-2, this.getHeight()-5, 5, 5);
gx.fillOval(0, midy-2, 5, 5);
gx.fillOval(this.getWidth()-5, midy-2, 5, 5);
}
}

private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
try {
ois.defaultReadObject();
remove(m_visualLabel);
m_visualLabel = new JLabel(m_icon);
loadIcons(m_iconPath, m_animatedIconPath);
add(m_visualLabel, BorderLayout.CENTER);
Dimension d = m_visualLabel.getPreferredSize();
Dimension d2 = new Dimension((int)d.getWidth() + 10,
(int)d.getHeight() + 10);
setMinimumSize(d2);
setPreferredSize(d2);
setMaximumSize(d2);
} catch (Exception ex) {
ex.printStackTrace();
}
}

}
java_road 2007-02-21
  • 打赏
  • 举报
回复
图片地址或是图片包装的格式不对.
geelpheels 2007-02-20
  • 打赏
  • 举报
回复
public SerializedObject(Object toStore, boolean compress) throws Exception {


////////////传入的toStore的类型为自定义的类型,这个类型继承自JPanel,实现了Serializable

ByteArrayOutputStream ostream = new ByteArrayOutputStream();
OutputStream os = ostream;
ObjectOutputStream p;
if (!compress)
p = new ObjectOutputStream(new BufferedOutputStream(os));
else
p = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(os)));
p.writeObject(toStore); ////////////这抛出异常了!
p.flush();
p.close(); // used to be ostream.close() !
m_storedObjectArray = ostream.toByteArray();

m_isCompressed = compress;
}
dajay520 2007-02-19
  • 打赏
  • 举报
回复
IO异常
加载图像出错!
interpb 2007-02-18
  • 打赏
  • 举报
回复
看看你的代码 吧

szm880828 2007-02-18
  • 打赏
  • 举报
回复
接分哦
zouxinfox 2007-02-18
  • 打赏
  • 举报
回复
这显然是if ((pg.getStatus() & ImageObserver.ABORT) != 0)抛出异常
新年快乐,接分了
jinanjiang 2007-02-18
  • 打赏
  • 举报
回复
接分
jiao38 2007-02-18
  • 打赏
  • 举报
回复


pg.getStatus() & ImageObserver.ABORT

在生产完成之前,跟踪的图像被异步中断


Buffered 2007-02-18
  • 打赏
  • 举报
回复
图片格式不对?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧