Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2004

Tip: Looking for answers? Try searching our database.

JButton prob :os

Thread view: 
Jean-Philippe Martin - 24 Feb 2004 00:10 GMT
Hi all,

It must because I'm tired... It's so a dummy prob...

Here it is:

Imagine you have a frame called F1 with only one JButton.
You have a main prog with something like that:

main{
   int res = 0;
   F1 frame = new F1();
   System.out.println(res);
}

You have to assume that the Button in frame change the value of res if we
click on it. I would like to force the user to click
on this button. So that the value 0 never appear on the standart output !

But I can't realize this easy thing :o(

Could you help me ?

ps: In my real application, I would like to receive the selectedIndex of a
JComboBox in place of just modify a value of a int. "I force the user to
choose a Item in the ComboBox" before to continue".

Thx in advance.

Jean-Philippe
Andrew Thompson - 24 Feb 2004 00:30 GMT
...
> Imagine you have a frame called F1 with only one JButton.

Sounds like a job for a JDialog

> You have a main prog with something like that:
>
[quoted text clipped - 7 lines]
> if we click on it. I would like to force the user to click
> on this button.

JDialog, definitely.

JDialog.setModal(true)

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Jean-Philippe Martin - 24 Feb 2004 00:42 GMT
> ...
> > Imagine you have a frame called F1 with only one JButton.
[quoted text clipped - 19 lines]
> --
> Andrew Thompson

Hi my professor ;o)

Is it possible to add a JComboBox with a JDialog ? Because in reality in my
app, the frame contains a JComboBox and the user select a Item and then
click on the button wich send me the value.

Thx for your answer :o) (I didn't post anywhere else this time :o) )
Andrew Thompson - 24 Feb 2004 01:28 GMT
>> ...
>>> Imagine you have a frame called F1 with only one JButton.
>>
>> Sounds like a job for a JDialog
...
> Is it possible to add a JComboBox with a JDialog ?

JDialog.getContentPane().add( Component c )

Since JComboBoxes and JPanels, JButtons..
are sub-classed from Component, any one,
or combination of them, can be added.

If you needed to, you could have a textfield,
two combo boxes, a list and a handful of
buttons all in a single panel that you add
to the dialog.

You can either return a single value when
the dialog is closed, or hand it a combination
of controls (like above) that you can examine
after it is closed.

>..(I didn't post anywhere else this time :o) )

Nice work.  :-)

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Adam - 24 Feb 2004 07:33 GMT
> > > Imagine you have a frame called F1 with only one JButton.
> >
[quoted text clipped - 7 lines]
> > >     System.out.println(res);
> > > }
[cut]

> Is it possible to add a JComboBox with a JDialog ? Because in reality in my
> app, the frame contains a JComboBox and the user select a Item and then
> click on the button wich send me the value.

If you don't need anything more than a combo box, use JOptionPane:

<code>
import javax.swing.*;
public class Input
{
public static void main(String[] args)
{
 Integer[] possibleValues = new Integer[]{new Integer(1), new
Integer(2), new Integer(3)};
 Object selectedValue = JOptionPane.showInputDialog(null,
          "Choose a number",
          "Input",
          JOptionPane.INFORMATION_MESSAGE,
          null,
          possibleValues,
          possibleValues[0]);
 System.out.println("You have selected "+selectedValue);
}
}
</code>

Adam
Jean-Philippe Martin - 29 Feb 2004 17:40 GMT
> <code>
> import javax.swing.*;
[quoted text clipped - 17 lines]
>
> Adam

Thx Adam, I've found a solution but yours is easier. Its was perfectly what
I was searching for.

ps: It's my first "middle" software with GUI, I didn't know all the main
class yet.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.