I am supposed to write a program that converts kilometers to miles and vice versa. We are only supposed to use JOptionPane for this assignment. I am wondering if it is possible to customize the buttons in JOptionPane and associate a formula to those buttons.
For instance, I want to have the text field and then two buttons that read "Miles" and "Kilometers". If you click on Miles, it will convert the number entered to miles.
I have researched quite a bit, but I can't seem to find a definitive answer. Any help would be greatly appreciated.

Recommended Answers

All 2 Replies

how else were you thinking of doing this? of course you can do what you have explained. imagine if buttons didn't have "custom" events...

Using the showOptionDialog() from the JOptionPane class, you should be able to achieve that. As JOptionPane in the "showOptionDialog()"does allow you to add your own custom components.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.