home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-25 | 5.1 KB | 190 lines |
- // This snippet creates a new about box.
- // <File=DualListBox.java>
-
- //Title:
- //Version:
- //Copyright:
- //Author:
- //Company:
- //Description:
- //
-
- //<PACKAGE>
-
- import java.awt.*;
- import java.awt.event.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.control.*;
-
- public class DualListBox extends BevelPanel {
- XYLayout xYLayout1 = new XYLayout();
- List source = new List();
- List destination = new List();
- Button addOne = new Button();
- Button addAll = new Button();
- Button removeOne = new Button();
- Button removeAll = new Button();
- Label label1 = new Label();
- Button ok = new Button();
- Button cancel = new Button();
- Label label2 = new Label();
-
- public DualListBox() {
- try {
- jbInit();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void jbInit() throws Exception {
- xYLayout1.setWidth(368);
- xYLayout1.setHeight(231);
- addOne.setLabel(">");
- addOne.addActionListener(new DualListBox_addOne_actionAdapter(this));
- addAll.setLabel(">>");
- addAll.addActionListener(new DualListBox_addAll_actionAdapter(this));
- removeOne.setLabel("<");
- removeOne.addActionListener(new DualListBox_removeOne_actionAdapter(this));
- removeAll.setLabel("<<");
- removeAll.addActionListener(new DualListBox_removeAll_actionAdapter(this));
- label1.setText("Source list");
- ok.setLabel("OK");
- ok.addActionListener(new DualListBox_ok_actionAdapter(this));
- cancel.setLabel("Cancel");
- cancel.addActionListener(new DualListBox_cancel_actionAdapter(this));
- label2.setText("Destination list");
- this.setLayout(xYLayout1);
- this.add(source, new XYConstraints(13, 22, 140, 172));
- this.add(destination, new XYConstraints(214, 20, 140, 176));
- this.add(addOne, new XYConstraints(166, 35, 32, 21));
- this.add(addAll, new XYConstraints(166, 61, 32, 21));
- this.add(removeOne, new XYConstraints(166, 130, 32, 21));
- this.add(removeAll, new XYConstraints(166, 160, 32, 21));
- this.add(label1, new XYConstraints(13, 4, 140, 14));
- this.add(ok, new XYConstraints(198, 206, 78, 21));
- this.add(cancel, new XYConstraints(283, 205, 68, 21));
- this.add(label2, new XYConstraints(213, 3, 140, 17));
- }
-
- void addOne_actionPerformed(ActionEvent e) {
- destination.addItem(source.getSelectedItem());
- source.remove(source.getSelectedIndex());
- }
-
- void addAll_actionPerformed(ActionEvent e) {
- for (int i = 0; i < source.getItemCount(); i++) {
- destination.addItem(source.getItem(i));
- }
- source.removeAll();
- }
-
- void removeOne_actionPerformed(ActionEvent e) {
- source.addItem(destination.getSelectedItem());
- destination.remove(destination.getSelectedIndex());
- }
-
- void removeAll_actionPerformed(ActionEvent e) {
- for (int i = 0; i < destination.getItemCount(); i++) {
- source.addItem(destination.getItem(i));
- }
- destination.removeAll();
- }
-
- void ok_actionPerformed(ActionEvent e) {
-
- }
-
- void cancel_actionPerformed(ActionEvent e) {
-
- }
- //<Exclude>
- // Test case
- public static void main(String[] argv) {
- DecoratedFrame frame = new DecoratedFrame();
- DualListBox dlb=new DualListBox();
- dlb.source.addItem("One");
- dlb.source.addItem("Two");
- dlb.source.addItem("Three");
- dlb.source.addItem("Four");
- dlb.source.addItem("Five");
- frame.add(dlb);
- frame.pack();
- frame.show();
- }
- //</Exclude>
- }
-
- class DualListBox_addOne_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_addOne_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.addOne_actionPerformed(e);
- }
- }
-
- class DualListBox_addAll_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_addAll_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.addAll_actionPerformed(e);
- }
- }
-
- class DualListBox_removeOne_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_removeOne_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.removeOne_actionPerformed(e);
- }
- }
-
- class DualListBox_removeAll_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_removeAll_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.removeAll_actionPerformed(e);
- }
- }
-
- class DualListBox_ok_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_ok_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.ok_actionPerformed(e);
- }
- }
-
- class DualListBox_cancel_actionAdapter implements ActionListener {
- DualListBox adaptee;
-
- DualListBox_cancel_actionAdapter(DualListBox adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.cancel_actionPerformed(e);
- }
- }
-