Solved

How can I make an extra button on the top-right of my form near border icons?

Posted on 2003-11-23
8
310 Views
Last Modified: 2010-04-17
Hello Experts!
I want to add some new buttons near the border icons (Close, Minimize,maximaise-Restore) and want to add glyphs or bitmaps as an icon on them. First, how can this be done so that I can define events for theses button when the user clicks on them. Secondly, is it possible to define hints for these buttons? If Yes, Please How?
Best regards,
<Email addresss removed by GhostMod, CS Moderator>
0
Comment
Question by:eisgzm
  • 3
8 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9806570
Which language?
0
 
LVL 2

Accepted Solution

by:
override_y2k earned 50 total points
ID: 9807387
If you are using java then you must use listeners.

After a button is created, you will add a listener to it. Eg,
b.addActionListener(listener_object);
When the button is clicked, a call is made to the actionPerformed method defined in the class of the listener object. An ActionEvent object is passed as a parameter to it.

Here is a simple example using awt that sets up a frame, adds buttons and labels , and also adds action listeners and window listeners.

import java.awt.*;
import java.awt.event.*;

public class FrameTest extends Frame implements ActionListener {

  private static final String HELLO = "Hello";
  private static final String GOODBYE = "Goodbye";
  private String message = HELLO;
  private Panel counterPanel;
  private Button counterButton;
  private Label counterLabel;

  public FrameTest() {
    super("HelloGoodbye");
    counterLabel = new Label(message);
    counterButton = new Button("Click me");
    counterButton.addActionListener(this);
    counterPanel = new Panel();
    BorderLayout b = new BorderLayout();//Predefined awt layout
    this.setLayout(b);
    counterPanel.add(counterLabel, BorderLayout.CENTER);
    counterPanel.add(counterButton, BorderLayout.SOUTH);
    this.add(counterPanel);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);;
      }
    });
    pack();
    setVisible(true);
    this.setSize(300,200);
  }

  public void actionPerformed(ActionEvent e) {
    if(message.equals(HELLO)) {
      message = GOODBYE;
    } else {
      message = HELLO;
    }
    counterLabel.setText(message);
    }

  public static void main(final String[] args) {
    FrameTest app = new FrameTest();

  }

}


Regards.
0
 
LVL 2

Expert Comment

by:override_y2k
ID: 9812787
I also find it worrying that you have asked 3 questions and have not awarded points for any of them to the experts.

0
 
LVL 2

Expert Comment

by:override_y2k
ID: 10318078
All Parts of Question Were Answered
0
 
LVL 3

Expert Comment

by:Phoenixric
ID: 10936972
I agree with override y2k, dont we have some control regarding this matter; someone posting a question and experts spend time and efforts finding the solution, but some very inconsiderate one leaves their question seems that they dont care. Why? hard to give points? WEll, this is just an opinion. . "Just be considerate for someones effort" Besides this is an expert-exchange not a childs play.

Close this question and give points to override y2k -> All Parts of the Question were answered.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now