Solved

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

Posted on 2003-11-23
8
308 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

757 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

21 Experts available now in Live!

Get 1:1 Help Now