public class BakedBean extends JComponent implements Externalizable { // Property names (only needed for bound or constrained properties) public static final String BEAN_VALUE = "Value"; public static final String BEAN_COLOR = "Color";
// Properties private Font m_beanFont; // simple private Dimension m_beanDimension; // simple private int m_beanValue; // bound private Color m_beanColor; // constrained private String m_beanString; // change
// Manages all PropertyChangeListeners protected SwingPropertyChangeSupport m_supporter = new SwingPropertyChangeSupport(this);
// Manages all VetoableChangeListeners protected VetoableChangeSupport m_vetoer = new VetoableChangeSupport(this);
// Only one ChangeEvent is needed since the event's only // state is the source property. The source of events generated // is always "this". -- you’ll see this in lots of Swing code. protected transient ChangeEvent m_changeEvent = null;
// This can manage all types of listeners, as long as we set // up the fireXX methods to correctly look through this list. // This makes you appreciate the XXSupport classes. protected EventListenerList m_listenerList = new EventListenerList();
public BakedBean() { m_beanFont = new Font("SanSerif", Font.BOLD | Font.ITALIC, 12); m_beanDimension = new Dimension(150,100); m_beanValue = 0; m_beanColor = Color.black; m_beanString = "BakedBean #"; }
public void setBeanFont(Font font) { m_beanFont = font; }
public Font getBeanFont() { return m_beanFont; }
public void setBeanValue(int newValue) { int oldValue = m_beanValue; m_beanValue = newValue;
// Notify all PropertyChangeListeners m_supporter.firePropertyChange(BEAN_VALUE, new Integer(oldValue), new Integer(newValue)); }
public int getBeanValue() { return m_beanValue; }
public void setBeanColor(Color newColor) throws PropertyVetoException { Color oldColor = m_beanColor;
// Notify all VetoableChangeListeners before making change // ...exception will be thrown here if there is a veto // ...if not we continue on and make the change m_vetoer.fireVetoableChange(BEAN_COLOR, oldColor, newColor);
public Color getBeanColor() { return m_beanColor; }
public void setBeanString(String newString) { m_beanString = newString;
// Notify all ChangeListeners fireStateChanged(); }
public String getBeanString() { return m_beanString; }
public void setPreferredSize(Dimension dim) { m_beanDimension = dim; }
public Dimension getPreferredSize() { return m_beanDimension; }
public void setMinimumSize(Dimension dim) { m_beanDimension = dim; }
public Dimension getMinimumSize() { return m_beanDimension; }
public void addPropertyChangeListener( PropertyChangeListener l) { m_supporter.addPropertyChangeListener(l); }
public void removePropertyChangeListener( PropertyChangeListener l) { m_supporter.removePropertyChangeListener(l); }
public void addVetoableChangeListener( VetoableChangeListener l) { m_vetoer.addVetoableChangeListener(l); }
public void removeVetoableChangeListener( VetoableChangeListener l) { m_vetoer.removeVetoableChangeListener(l); }
// Remember that EventListenerList is an array of // key/value pairs. // key = XXListener class reference // value = XXListener instance public void addChangeListener(ChangeListener l) { m_listenerList.add(ChangeListener.class, l); }
public void removeChangeListener(ChangeListener l) { m_listenerList.remove(ChangeListener.class, l); }
// This is typical EventListenerList dispatching code. // You will see this in lots of Swing source. protected void fireStateChanged() { Object[] listeners = m_listenerList.getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event for (int i = listeners.length-2; i>=0; i-=2) { if (listeners[i]==ChangeListener.class) { if (m_changeEvent == null) m_changeEvent = new ChangeEvent(this); ((ChangeListener)listeners[i+1]).stateChanged(m_changeEvent); } } }
public class BakedBean extends JApplet implements Externalizable { // Property names (only needed for bound or constrained properties) public static final String BEAN_VALUE = "Value"; public static final String BEAN_COLOR = "Color";
// Properties private Font m_beanFont; // simple private Dimension m_beanDimension; // simple private int m_beanValue; // bound private Color m_beanColor; // constrained private String m_beanString; // change
// Manages all PropertyChangeListeners protected SwingPropertyChangeSupport m_supporter = new SwingPropertyChangeSupport(this);
// Manages all VetoableChangeListeners protected VetoableChangeSupport m_vetoer = new VetoableChangeSupport(this);
// Only one ChangeEvent is needed since the event's only // state is the source property. The source of events generated // is always "this". -- you’ll see this in lots of Swing code. protected transient ChangeEvent m_changeEvent = null;
// This can manage all types of listeners, as long as we set // up the fireXX methods to correctly look through this list. // This makes you appreciate the XXSupport classes. protected EventListenerList m_listenerList = new EventListenerList();
public BakedBean() { m_beanFont = new Font("SanSerif", Font.BOLD | Font.ITALIC, 12); m_beanDimension = new Dimension(150, 100); m_beanValue = 0; m_beanColor = Color.black; m_beanString = "BakedBean #"; }
public void setBeanFont(Font font) { m_beanFont = font; }
public Font getBeanFont() { return m_beanFont; }
public void setBeanValue(int newValue) { int oldValue = m_beanValue; m_beanValue = newValue;
// Notify all PropertyChangeListeners m_supporter.firePropertyChange( BEAN_VALUE, new Integer(oldValue), new Integer(newValue)); }
public int getBeanValue() { return m_beanValue; }
public void setBeanColor(Color newColor) throws PropertyVetoException { Color oldColor = m_beanColor;
// Notify all VetoableChangeListeners before making change // ...exception will be thrown here if there is a veto // ...if not we continue on and make the change m_vetoer.fireVetoableChange(BEAN_COLOR, oldColor, newColor);
public Color getBeanColor() { return m_beanColor; }
public void setBeanString(String newString) { m_beanString = newString;
// Notify all ChangeListeners fireStateChanged(); }
public String getBeanString() { return m_beanString; }
public void setPreferredSize(Dimension dim) { m_beanDimension = dim; }
public Dimension getPreferredSize() { return m_beanDimension; }
public void setMinimumSize(Dimension dim) { m_beanDimension = dim; }
public Dimension getMinimumSize() { return m_beanDimension; }
public void addPropertyChangeListener(PropertyChangeListener l) { m_supporter.addPropertyChangeListener(l); }
public void removePropertyChangeListener(PropertyChangeListener l) { m_supporter.removePropertyChangeListener(l); }
public void addVetoableChangeListener(VetoableChangeListener l) { m_vetoer.addVetoableChangeListener(l); }
public void removeVetoableChangeListener(VetoableChangeListener l) { m_vetoer.removeVetoableChangeListener(l); }
// Remember that EventListenerList is an array of // key/value pairs. // key = XXListener class reference // value = XXListener instance public void addChangeListener(ChangeListener l) { m_listenerList.add(ChangeListener.class, l); }
public void removeChangeListener(ChangeListener l) { m_listenerList.remove(ChangeListener.class, l); }
// This is typical EventListenerList dispatching code. // You will see this in lots of Swing source. protected void fireStateChanged() { Object[] listeners = m_listenerList.getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == ChangeListener.class) { if (m_changeEvent == null) m_changeEvent = new ChangeEvent(this); ((ChangeListener) listeners[i + 1]).stateChanged(m_changeEvent); } } }
public void init() { /* JFrame frame = new JFrame("BakedBean"); frame.getContentPane().add(new BakedBean()); frame.setVisible(true); frame.pack(); */ getContentPane().add(new BakedBean()); }
Synes godt om
Slettet bruger
13. april 2004 - 22:09#6
Ja. Men det er altså så ikke nok hos mig!? Jeg har slettet .class filen og compileret på ny. Men stadig åbnes applet'en i sit eget vindue. Denne er vel rigtig: <applet code="BakedBean.class" width=800 height=500>
Hov - denne metode skal selvfølgelig ikke med: initComponents();
Synes godt om
Slettet bruger
13. april 2004 - 22:51#14
Jeg ser på det imorgen. Det glæder jeg mig til.
Synes godt om
Slettet bruger
14. april 2004 - 19:30#15
Det fungere. Jeg anvender carstens i denne sammenhæng fordi applet'en i denne sammenhæng blot skal kunne vises i browseren. Skal du have point giver jeg også gerne dig 30. Men så send et svar carsten. > arne. Er der en "smart" måden at tømme memory cachen på (uden at slukke computeren). Således at jeg kan være 100% sikker på der ikke ligger noget?
Jeg har selv haft store problemer med cachede applets.
Man kan prøve at finde det sted i browseren hvor man kan slette cache.
Man kan prøve at CTRL + klik refresh i.s.f. bare klik refresh.
Man kan bede web serveren om at flushe cachen.
Men jeg har ikke *LØSNINGEN*.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.