Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34430
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-05-31 11:25 -0700 |
| References | <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com> <nikc0f$b0v$1@dont-email.me> <f46278e9-a64d-42d4-8c2d-5e0cfd168692@googlegroups.com> <nikk4d$ao3$1@dont-email.me> |
| Message-ID | <d8ea605f-0759-4b10-b293-235cc558d6e9@googlegroups.com> (permalink) |
| Subject | Re: How to extend an array |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Tuesday, May 31, 2016 at 2:11:36 PM UTC-4, Eric Sosman wrote:
> Since I'm still not sure I understand what you're trying to do,
> I can't comment. Not usefully, anyhow.
So, the same sample with the missing pieces you mentioned. Class1 is a customized JFrame. In this example it's just a default JFrame with a default close operation automatically set and a default window listener created. Class2 is a customized Class1. In this example it just adds another default to report window iconified (minimize) events. Does this structure make sense, just making an array in the extended class (which apparently adds a second array on top of the one in the super class even if I make that visible and give the second one the same name), passing listeners into both arrays from the second class?
In the full super complicated API, Class1 extends a JTable and reports table events like row change, and Class2 is a fancier Class1 table with all it's fonts, colors, events, etc which adds a JTree. The JTree renders one column and passes MouseEvents through to report tree events like treeWillExpand, reporting a tree node which is rendered in a single cell which triggers to add nodes which inserts rows...
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.EventListener;
import javax.swing.JFrame;
public abstract class TestStatic2 {
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
final Class2 myWindow = new Class2();
myWindow.addExtendedListener(new Listener2() {
@Override
public void eventWindowOpen() {
System.out.println("opened");
}
@Override
public void eventWindowIconified() {
System.out.println("iconified");
}
});
myWindow.setSize(400, 260);
myWindow.setVisible(true);
}
});
}
public static class Class1 extends JFrame {
protected ArrayList<Listener1> myArray = new ArrayList();
public Class1() {
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(final WindowEvent e) {
for (final Listener1 l : myArray) {
l.eventWindowOpen();
}
}
});
super.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void addListener(final Listener1 addMe) {
myArray.add(addMe);
}
}
public static class Class2 extends Class1 {
protected ArrayList<Listener2> myArray = new ArrayList();
public Class2() {
addWindowListener(new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
for (final Listener2 l : myArray) {
l.eventWindowIconified();
}
}
});
}
public void addExtendedListener(final Listener2 addMe) {
myArray.add(addMe);
super.myArray.add(addMe);
}
}
public interface Listener1 extends EventListener {
public void eventWindowOpen();
}
public interface Listener2 extends Listener1 {
public void eventWindowIconified();
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 07:52 -0700
Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:52 -0400
Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:56 -0400
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:19 -0700
Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:01 -0400
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:09 -0700
Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:11 -0400
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 11:25 -0700
Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 17:01 -0400
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:57 -0700
Re: How to extend an array Roedy Green <inquiry@mindprod.com> - 2016-05-31 21:56 -0700
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:49 -0700
Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-01 23:07 +0200
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 05:38 -0700
Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-04 19:17 +0200
Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 08:52 -0700
csiph-web