🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.programmer
5 messages
5 total messages Started by morris_newsgroup Mon, 29 Jun 1998 00:00
Pop up a message box in applet
#431
Author: morris_newsgroup
Date: Mon, 29 Jun 1998 00:00
23 lines
1994 bytes
I have an applet which accepts input from users through a GUI.	I'm trying to
pop up a message box with only an OK button when users make an error.  Is
this doable in applet or I can only do this in an application instead.	I
think this is a general java gui question.  By the way, I'm using JBuilder2
and found that when I dropped a message component onto my applet.  I can't
find a frame which the message component can use.  In other words, there was
nothing in the frame property of the message component.  I tried to create a
frame inside the applet source code and it seemed to have some security
errors when I ran the applet in the browser.

Does anyone know anything about this?  It may not be just a JBuilder2
question. In general, I would like to know if it's possible that I can pop up
a message box with either just a message or a text box which users can enter
something in an applet.

Sample code would be helpful if this is possible.

Thanks for your help in advance,
Morris

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Re: Pop up a message box in applet
#432
Author: cooljavafolks
Date: Mon, 29 Jun 1998 00:00
46 lines
2705 bytes
Hi,

You can do this by using the getParent() method. To pop-up any dialog box, we
need a Frame. The reference to a Frame can be obtained by doing a getParent()
on the applet, until we get a frame. Sometimes, simply passing a new Frame()
to the constructor of the dialog also will suffice.


CoolJava Folks!
<cooljavafolks@yahoo.com>
Java Development & Consultancy @ $25 / Hour in India.


In article <6n6nh9$bd1$1@nnrp1.dejanews.com>,
  morris_newsgroup@yahoo.com wrote:
>
> I have an applet which accepts input from users through a GUI.	I'm
trying to
> pop up a message box with only an OK button when users make an error.  Is
> this doable in applet or I can only do this in an application instead.
I
> think this is a general java gui question.  By the way, I'm using JBuilder2
> and found that when I dropped a message component onto my applet.  I can't
> find a frame which the message component can use.  In other words, there was
> nothing in the frame property of the message component.  I tried to create a
> frame inside the applet source code and it seemed to have some security
> errors when I ran the applet in the browser.
>
> Does anyone know anything about this?  It may not be just a JBuilder2
> question. In general, I would like to know if it's possible that I can pop up
> a message box with either just a message or a text box which users can enter
> something in an applet.
>
> Sample code would be helpful if this is possible.
>
> Thanks for your help in advance,
> Morris
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Re: Pop up a message box in applet
#433
Author: Rashid420
Date: Mon, 29 Jun 1998 00:00
48 lines
3148 bytes
I believe you will need to create a Frame or JFrame to "popup" a window.
Personally, I think it is a bad idea to popup windows from applets.  I can
never guarantee there "modality" and given the inconsistent support in
browsers, I stay away from then.

I recommend having a CardPanel for your main applet UI with an "error" panel
that you can switch too.  The error panel would describe the error and could
have controls to specify actions to be taken on the error.  In the simplest
case, the error panel would simply have a "Back" button to take you to the
"screen" where the error occurred, or to some place where the user should
interact after the error occurred.

I repeat, this is my recommendation.  Is anyone at Sun reading this?  PLEASE
ENDORSE IT!

In article <6n6nh9$bd1$1@nnrp1.dejanews.com>,
  morris_newsgroup@yahoo.com wrote:
>
> I have an applet which accepts input from users through a GUI.	I'm
trying to
> pop up a message box with only an OK button when users make an error.  Is
> this doable in applet or I can only do this in an application instead.
I
> think this is a general java gui question.  By the way, I'm using JBuilder2
> and found that when I dropped a message component onto my applet.  I can't
> find a frame which the message component can use.  In other words, there was
> nothing in the frame property of the message component.  I tried to create a
> frame inside the applet source code and it seemed to have some security
> errors when I ran the applet in the browser.
>
> Does anyone know anything about this?  It may not be just a JBuilder2
> question. In general, I would like to know if it's possible that I can pop up
> a message box with either just a message or a text box which users can enter
> something in an applet.
>
> Sample code would be helpful if this is possible.
>
> Thanks for your help in advance,
> Morris
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Re: Pop up a message box in applet
#434
Author: Joseph Ramsey
Date: Mon, 29 Jun 1998 00:00
114 lines
4337 bytes
morris_newsgroup@yahoo.com wrote:
> 
> I have an applet which accepts input from users through a GUI.  I'm trying to
> pop up a message box with only an OK button when users make an error.  Is
> this doable in applet or I can only do this in an application instead.  I
> think this is a general java gui question.  By the way, I'm using JBuilder2
> and found that when I dropped a message component onto my applet.  I can't
> find a frame which the message component can use.  In other words, there was
> nothing in the frame property of the message component.  I tried to create a
> frame inside the applet source code and it seemed to have some security
> errors when I ran the applet in the browser.
> 
> Does anyone know anything about this?  It may not be just a JBuilder2
> question. In general, I would like to know if it's possible that I can pop up
> a message box with either just a message or a text box which users can enter
> something in an applet.
> 
> Sample code would be helpful if this is possible.

Here's a message window with an OK button I wrote for a app I'm
working on.  I used JDK 1.1.5 for it on Windows.  You have to pass
it the frame of the applet you're in, so you have to find this.  You
probably know how to do that but I tacked code on the end just in
case.  (You have to put this code in the calling class.  Define a
class-level variable frame of type Frame.  Or rewrite the thing to
suit your quirks instead of mine.)

/*
 * DataWindowSpreadsheet.java		0.4	98/04/20
 * 
 * Copyright (c) 1998 Joseph D. Ramsey.  All Rights Reserved.
 */

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

/**
 * This class generates a popup message dialog which
 * displays a simple message and then disappears when
 * the user clicks 'OK' (or types 'Enter' or clicks
 * the window close tab).
 */
public class MessageDialog extends Dialog
{
	String message;
	Button okButton = new Button("OK");
	Label messageLabel;
	
	public MessageDialog(Frame frame, String message)
	{
		super(frame, "Message:", true);
		this.message = message;
		messageLabel = new Label(message);
		
		setLayout(new FlowLayout());
		add(messageLabel);
		add(okButton);
		pack();
		setResizable(false);
		
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				dispose();
			}
		});
		
		okButton.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					dispose();
				}
			}
		});
		
		this.addWindowListener (new WindowAdapter() {
			public void windowClosing(WindowEvent event) {
				dispose();
			}
		});
		
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension screenSize = toolkit.getScreenSize();
		
		int height = this.getSize().width;
		setLocation(screenSize.width / 2 - height / 2, 
			screenSize.height / 2);
		show();
	}
}

METHOD TO GET APPLET FRAME:

	/**
	 * This method returns the frame which ultimately contains
	 * this panel.  One needs to know which frame this is
	 * in order to display dialogs and charts in separate
	 * Dialog windows.
	 */	
	protected Frame getFrame()
	{
		if (this.frame == null)
		{		
			Component c = this;
			Frame frame = null;
			while ( (c = c.getParent() ) != null) 
			{
				if (c instanceof Frame)
					frame = (Frame) c;
			}
			this.frame = frame;
		}
		return this.frame;
	}
Re: Pop up a message box in applet
#435
Author: Nicholas J Anderson
Date: Tue, 30 Jun 1998 00:00
59 lines
2480 bytes
Hi, 

I just make a frame object in my applet, then pass this to the
constructor for my dialog box.
This works fine for me in appletviewer, IE4, Netscape 4.03+patch and
HotJava1.1.4 on Win95 and X-win.
by the way I am using sunJDK1.1.4.

e.g.  somewhere in my applet class (i.e where ever  you want to create
the dialog:

Frame f = new Frame();          
helpDialog d = new helpDialog(f, "Sorry, no help available");
d.setVisible(true);

Then the dialog class.....

class helpDialog extends Dialog implements ActionListener, ItemListener
{

Button ok = new Button("O.K");

//---  constructor      
helpDialog(Frame parent, String title){
                
super(parent, title, true);  //sets parent, frame title, and modality
setSize(300,210);            // set the size
setLayout(null);             //null layout
add(ok);                     //add the OK button
ok.setBounds(145,160,50,23); //set the position and size of the button
ok.addActionListener(this);  //register to recieve events from button
}

public void paint(Graphics g)
{

g.drawString("Sorry, no help topic for this area",10,40);

}


        
public void actionPerformed(ActionEvent ae)
        {
        String command = ae.getActionCommand();
        if (command.equals("O.K")) 
                        {
                        dispose();
                        }
                        
        }
        

}


Hope that helps////////
Nikk Anderson
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads