Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2847 > unrolled thread

Question: jFranme and jDi

Started by"WhoWhatWhen" <whowhatwhen@THRWHITE.remove-dii-this>
First post2011-04-27 15:41 +0000
Last post2011-04-27 15:41 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  Question: jFranme and jDi "WhoWhatWhen" <whowhatwhen@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000
    Re: Question: jFranme and "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000
      Re: Question: jFranme and "WhoWhatWhen" <whowhatwhen@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000
        Re: Question: jFranme and "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000
    Re: Question: jFranme and "Jeff" <jeff@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000

#2847 — Question: jFranme and jDi

From"WhoWhatWhen" <whowhatwhen@THRWHITE.remove-dii-this>
Date2011-04-27 15:41 +0000
SubjectQuestion: jFranme and jDi
Message-ID<t4gdl3pmrfcbspphjltr2qdpfsi2sa8vgl@4ax.com>
  To: comp.lang.java.gui
Given a jFrame that also contains a checkbox and a jDialog.

The jDialog has been made visible and is modal.

Is there a way to access the value of the checkbox on the parent
jFrame from the jdialog?

Many thanks,

Ken B.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2848 — Re: Question: jFranme and

From"RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Date2011-04-27 15:41 +0000
SubjectRe: Question: jFranme and
Message-ID<4756cf36$0$21094$da0feed9@news.zen.co.uk>
In reply to#2847
  To: comp.lang.java.gui
WhoWhatWhen wrote:
> Given a jFrame that also contains a checkbox and a jDialog.
> 
> The jDialog has been made visible and is modal.
> 
> Is there a way to access the value of the checkbox on the parent
> jFrame from the jdialog?
> 

There are many many ways


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class FrameDialog implements ItemListener {
     public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 new FrameDialog();
             }
         });
     }

     private JCheckBox checkbox;

     private JFrame frame;

     FrameDialog() {
         checkbox = new JCheckBox("Fries", false);
         checkbox.addItemListener(this);
         JPanel p = new JPanel();
         p.add(checkbox);

         frame = new JFrame("Frame");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.add(p);
         frame.pack();
         frame.setLocationRelativeTo(null);
         frame.setVisible(true);
     } // constructor

     public void itemStateChanged(ItemEvent e) {

         final JDialog d = new JDialog(frame, "Dialog");

         JButton b = new JButton("True");
         b.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 d.setVisible(false);
                 d.dispose();
             }
         });

         JPanel p = new JPanel();
         p.add(new JLabel(checkbox.isSelected() ? "Fatso" : "Beanpole"));
         p.add(b);

         d.add(p);
         d.pack();
         d.setLocationRelativeTo(frame);
         d.setVisible(true);

     }

}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2849 — Re: Question: jFranme and

From"WhoWhatWhen" <whowhatwhen@THRWHITE.remove-dii-this>
Date2011-04-27 15:41 +0000
SubjectRe: Question: jFranme and
Message-ID<cgndl3hvflbv7nnnvdhlq2cftrtntp6lqt@4ax.com>
In reply to#2848
  To: comp.lang.java.gui
Thank you but that is not exactly the solution to the question as
asked:  In your solution the jdialog is opened by checing the
checkbox.  

I need to be able to ascertain from within the dialog box what the
value of the checkbox is.

For example, in VB6 I would say from another window:
if (frmMain.chkbox1.value=vbchecked) then
	blah blah blah
endif

Again, thank you.

Ken B.

On Wed, 05 Dec 2007 16:17:58 +0000, RedGrittyBrick
<RedGrittyBrick@SpamWeary.foo> wrote:

>WhoWhatWhen wrote:
>> Given a jFrame that also contains a checkbox and a jDialog.
>> 
>> The jDialog has been made visible and is modal.
>> 
>> Is there a way to access the value of the checkbox on the parent
>> jFrame from the jdialog?
>> 
>
>There are many many ways
>
>
>import java.awt.event.ActionEvent;
>import java.awt.event.ActionListener;
>import java.awt.event.ItemEvent;
>import java.awt.event.ItemListener;
>
>import javax.swing.JButton;
>import javax.swing.JCheckBox;
>import javax.swing.JDialog;
>import javax.swing.JFrame;
>import javax.swing.JLabel;
>import javax.swing.JPanel;
>import javax.swing.SwingUtilities;
>
>public class FrameDialog implements ItemListener {
>     public static void main(String[] args) {
>         SwingUtilities.invokeLater(new Runnable() {
>             public void run() {
>                 new FrameDialog();
>             }
>         });
>     }
>
>     private JCheckBox checkbox;
>
>     private JFrame frame;
>
>     FrameDialog() {
>         checkbox = new JCheckBox("Fries", false);
>         checkbox.addItemListener(this);
>         JPanel p = new JPanel();
>         p.add(checkbox);
>
>         frame = new JFrame("Frame");
>         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>         frame.add(p);
>         frame.pack();
>         frame.setLocationRelativeTo(null);
>         frame.setVisible(true);
>     } // constructor
>
>     public void itemStateChanged(ItemEvent e) {
>
>         final JDialog d = new JDialog(frame, "Dialog");
>
>         JButton b = new JButton("True");
>         b.addActionListener(new ActionListener() {
>             public void actionPerformed(ActionEvent e) {
>                 d.setVisible(false);
>                 d.dispose();
>             }
>         });
>
>         JPanel p = new JPanel();
>         p.add(new JLabel(checkbox.isSelected() ? "Fatso" : "Beanpole"));
>         p.add(b);
>
>         d.add(p);
>         d.pack();
>         d.setLocationRelativeTo(frame);
>         d.setVisible(true);
>
>     }
>
>}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2850 — Re: Question: jFranme and

From"RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Date2011-04-27 15:41 +0000
SubjectRe: Question: jFranme and
Message-ID<0a6dnR9YLuxTkMranZ2dnUVZ8qminZ2d@bt.com>
In reply to#2849
  To: comp.lang.java.gui
WhoWhatWhen wrote:
> Thank you but that is not exactly the solution to the question as
> asked:  In your solution the jdialog is opened by checing the
> checkbox.  

That has no bearing on the way the JDialog constructor accesses the 
JCheckBox. It would be the same whether a JMenuUtem or JButton or 
Exception handler invoked the JDialog constructor.

> 
> I need to be able to ascertain from within the dialog box what the
> value of the checkbox is.

The code that creates the dialog refers to checkbox
    p.add(new JLabel(checkbox.isSelected() ? "Fatso" : "Beanpole"));
If that's not the sort of thing you want to do, you should explain in 
more detail.


> 
> For example, in VB6 I would say from another window:
> if (frmMain.chkbox1.value=vbchecked) then
> 	blah blah blah
> endif

You can do it that way too.
   if (frame.checkbox.isSelected()) {
      blah blah blah;
   }

It's a question of the scope of either the variable which refers to the 
JFrame instance or the scope of the variable that refers to the 
JCheckBox instance. Or both.

Alternatively you could pass a reference to either of these variables 
into the method or constructor that creates the JDialog instance.

I'd prefer something like ...

class Whatever {
    Whatever() {
        ...
        JButton dialogInvokingButton = new JButton("Click me");
        dialogInvokingButton.addActionListener(this);
        ...
        frame.setVisible(true);
    }

    void actionPerformed(ActionEvent e) {
        new DialogCreatingClass(frame, checkbox.isSelected());
    }
}

class DialogCreatingClass {
     DialogCreatingClass(JFrame frame, boolean likesFries) {
         JDialog d = new JDialog(frame, ...);
         ...
         if (likesFries)
         ...
         d.setVisible(true);
     }
}

There's zillions of ways to do what you describe.

What I posted before was an SSCCE (Google will explain). Maybe you 
should construct one that better illustrates your question and post it.


A: It disturbs the natural flow of conversation
Q: Why is that?
A: Top-posting
Q: What irritates many comp.lang.java.programming readers?

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2858 — Re: Question: jFranme and

From"Jeff" <jeff@THRWHITE.remove-dii-this>
Date2011-04-27 15:41 +0000
SubjectRe: Question: jFranme and
Message-ID<1e7b2821-8982-48d6-b90f-510e65fd621a@w56g2000hsf.googlegroups.com>
In reply to#2847
  To: comp.lang.java.gui
On Dec 5, 10:18 am, WhoWhatWhen <w...@what.net> wrote:
> Given a jFrame that also contains a checkbox and a jDialog.
>
> The jDialog has been made visible and is modal.
>
> Is there a way to access the value of the checkbox on the parent
> jFrame from the jdialog?
>
> Many thanks,
>
> Ken B.

If I understand correctly - the object based on a jFrame is the parent
object of a jDialog, and you wish the behavior of the jDialog to vary
based on the value of a checkbox on the jFrame.

There are indeed several solutions. One is to push the information to
the dialog. For example, to display a simple AboutBox dialog that I
display with:
        AboutBox AboutBoxDlg =  new AboutBox(this, true);
        AboutBoxDlg.setSize(450,300);
        AboutBoxDlg.setVisible(true);
You can add a public variable to the definition of the AboutBox class
and set that variable value before the setVisible call.

Alternatively, pull the information. Make sure the checkbox value is
copied to a public value (example Boolean MyValue). Then pull the
information from the dialog with:

Boolean CheckBoxValue = parent.MyValue;

Since the dialog is passed a reference to the parent in its
constructor, you have access to the jFrame through the parent variable.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web