🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19848

Programmatically Posting Events To JBCL ButtonControl

#19848
From: David Brouse
Date: Tue, 09 Dec 1997 00:00
203 lines
5976 bytes
This is a multi-part message in MIME format.
--------------B4566855797D174FD07FE4DD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have written an application where I need to post an action
event for a push button through the program instead of from
a user mouse click. When I use the JAVA AWT Button, my code
works fine, but when I change the button to the JBCL
ButtonControl the code does not work.  Here is a trivial
example of my problem:

This code works.  It uses the JAVA AWT Button:

package untitled;

import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;

public class Frame1 extends Frame {
  BorderLayout borderLayout1 = new BorderLayout();
  Panel panel1 = new Panel();
  TextField textField1 = new TextField();
  BorderLayout borderLayout2 = new BorderLayout();
  Button button2 = new Button();
  Button button1 = new Button();

  //Construct the frame
  public Frame1() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  public void jbInit() throws Exception{
    this.setLayout(borderLayout1);
    this.setSize(new Dimension(296, 56));
    this.setTitle("Event Test");
    button1.setLabel("Print Text");
    button1.addActionListener(new
Frame1_button_actionAdapter(this));
    button2.setLabel("Create Event");
    button2.addActionListener(new
Frame1_button_actionAdapter(this));
    panel1.setLayout(borderLayout2);
    this.add(panel1, BorderLayout.CENTER);
    panel1.add(textField1, BorderLayout.CENTER);
    panel1.add(button2, BorderLayout.EAST);
    panel1.add(button1, BorderLayout.WEST);
  }

  void button_actionPerformed(ActionEvent e) {
    if (e.getSource() == button1) {
      // Print the event
      System.out.println("\nButton1   = " + e);

      // Set the text field
      textField1.setText("This is a test");
    }

    if (e.getSource() == button2) {
      // Create the new event
      ActionEvent ae = new ActionEvent(button1,
ActionEvent.ACTION_PERFORMED, null);

      // Print the new event
      System.out.println("\nNew Event = " + ae);

      // Try to process the new event
      EventQueue eq =
Toolkit.getDefaultToolkit().getSystemEventQueue();
      eq.postEvent(ae);
    }
  }
}

class Frame1_button_actionAdapter implements
java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_button_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.button_actionPerformed(e);
  }
}



Here is the same code with the JBCL ButtonControl.  It does
not work:

package untitled;

import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;

public class Frame1 extends Frame {
  BorderLayout borderLayout1 = new BorderLayout();
  Panel panel1 = new Panel();
  TextField textField1 = new TextField();
  BorderLayout borderLayout2 = new BorderLayout();
  Button button2 = new Button();
  ButtonControl buttonControl1 = new ButtonControl();

  //Construct the frame
  public Frame1() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  public void jbInit() throws Exception{
    this.setLayout(borderLayout1);
    this.setSize(new Dimension(296, 56));
    this.setTitle("Event Test");
    buttonControl1.setLabel("Print Text");
    buttonControl1.addActionListener(new
Frame1_button_actionAdapter(this));
    button2.setLabel("Create Event");
    button2.addActionListener(new
Frame1_button_actionAdapter(this));
    panel1.setLayout(borderLayout2);
    this.add(panel1, BorderLayout.CENTER);
    panel1.add(textField1, BorderLayout.CENTER);
    panel1.add(button2, BorderLayout.EAST);
    panel1.add(buttonControl1, BorderLayout.WEST);
  }

  void button_actionPerformed(ActionEvent e) {
    if (e.getSource() == buttonControl1) {
      // Print the event
      System.out.println("\nButton1   = " + e);

      // Set the text field
      textField1.setText("This is a test");
    }

    if (e.getSource() == button2) {
      // Create the new event
      ActionEvent ae = new ActionEvent(buttonControl1,
ActionEvent.ACTION_PERFORMED, null);

      // Print the new event
      System.out.println("\nNew Event = " + ae);

      // Try to process the new event
      EventQueue eq =
Toolkit.getDefaultToolkit().getSystemEventQueue();
      eq.postEvent(ae);
    }
  }
}

class Frame1_button_actionAdapter implements
java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_button_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.button_actionPerformed(e);
  }
}


--------------B4566855797D174FD07FE4DD
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Brouse, David
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             David Brouse
n:              Brouse;David
org:            Highmark, Inc.
adr:            Direct Access Services;;425 N. 21st Street, 4th Floor;Camp Hill;PA;17011;USA
email;internet: dbrouse@highmark.com
title:          Programmer Analyst
tel;work:       717-731-8053
tel;fax:        717-730-8968
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------B4566855797D174FD07FE4DD--
Technical Details
Message-ID: <348D692F.EF30B1E4@highmark.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b4629e8109bb925a,start
X-Google-Attributes: gidf74b3,public
From: David Brouse <dbrouse@highmark.com>
Subject: Programmatically Posting Events To JBCL ButtonControl
Date: 1997/12/09
Message-ID: <348D692F.EF30B1E4@highmark.com>
X-Deja-AN: 296621666
Organization: Highmark, Inc.
Newsgroups: borland.public.jbuilder.java.language