Applet window closing problem
hi all,
I am in need of some guidance, my program uses a GUI but i have a problem in that when the user clicks the window close button at the top right of the screen i need to execute some code but i am unable to do so, have i got the correct method? :o(
public boolean handleEvent (Event e)
boolean value = false;
if ((e.target == this) && (e.id == Event.WINDOW_DESTROY))
if (listener != null)
//here i would like to execute some code before setting the boolean variable
value = true;
else
value = false;
return value;
}//end handle event()
Good day,
As far as I'm concered, the "handleEvent (Event e)" has been deprecated and "processEvent(AWTEvent event)" should be used instead since JDK 1.1.
I have an occurance of that "handleEvent" thing that I would like to "convert" to "processEvent", however I'm having problems with that.
The first, which is simple, is to remove the true/false on the return statement of the handler. "handleEvent()" returns a boolean, whereas "processEvent()" returns nothing.
When I try to get the value of the "event.id" or "event.target", the compiler claims that the information is protected.
Can someone be nice enough to provide a code snippet to ease the transition between the "handleEvent()" and "processEvent()" things ?
Best regards.
Similar Messages
-
How to trap applet window closing event?
Hi all,
I would like to know how could one trap the event of the browser window containing an applet being closed by the user?
Thank you,Hi. this would be useful to me too.
Trouble is, I'm not sure that you can. applet.stop( )
and applet.destroy( ) might be called, but there is
no guarentee that you can complete processing before
you are terminated, especially if you need to do
something slow, like returning state data to your
server. And you can't stop the broswer closing.
I know that in Javascript, you can catch and even
stop the browser window being closed, which is how
things like goggledocs can ask for confirmation
before closing. (window.onbeforeunload( ) ).
I have toyed with the idea of having a
javascript/ajax thread in my html, to catch this
termination, and communicate back to the server from
java to say a document has changed, but it all seems
rather heavyweight for such a simple task.Look at Runtime.addShutdownHook()
You could also try using a WindowListener as well and trap the WindowClose Event.
stop() should do very little other than invalidate the current thread/run flags
and then exit. ie: a stop() example
public void stop()
task = null;
or
public void stop()
running = false;
Your run method should look for a stop condition and then exit.
Otherwise you could be doing stop processing while run is still
running.
(T) -
No such element exception when applet window closed
My applet can throw a NoSuchElementException as it closes during sudden death. The Java Console reports:
Exception in thread "AWT-EventQueue-2" java.util.NoSuchElementException
at java.util.LinkedList.getFirst(Unknown Source)
at java.awt.SequencedEvent.getFirst(Unknown Source)
at java.awt.SequencedEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)Sometimes that sequence displays once, sometimes twice. The error appears to be 90% or more repeatable.
1) open link in new window http://r0k.us/graphics/SIHwheel.html
2) view Color Log (menu item Help -=> Show Log)
3) close the whole browser window
It does not appear to happen without the dialog for the Color Log displayed. Nor does it appear to happen simply upon leaving that page. I'm guessing it is some sort of race condition as the applet is shut down and it doesn't have the surrounding window it started with. It only happens when running as an applet. When ran as a program, it always shuts down cleanly.
It occurs less often if you:
1) open the link in new window
2) leave the page
) come back to it while the Java Console is still alive (before JVM goes away)
3) view the Color Log
4) close the browser window.
I am running 64-bit Windows 7, and have observed this problem in Firefox, IE, and Chrome.
With no hints as to where within my code this is occurring (if indeed it is within "my" code), I have no idea how to write an SSCCE. The exception seems to relate to enumerations, which I believe must be occuring during the shut down seqence. See:
* http://download.oracle.com/javase/1.5.0/docs/api/java/util/NoSuchElementException.html
What can I try doing to prevent the error from occurring? (Besides not closing the browser window while my applet is running and has a dialog open. ;) )
*(added immediately before posting)* I just noticed that if any of the first three dialogs in the Help Menu are open, this behavior can occur. So it probably has nothing to do with the tables in the Color Log. The fourth, About, item is a simpler modal dialog, and you aren't even able to close the browser window while it is open.
Now that I know the crash can happen with any of the non-modal dialogs, I will write an SSCCE, just to see if it occurs in a much simpler applet, if nothing else.As promised, an SSCCE with build instructions and an applet environment.
CloseMyWindow.java import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import javax.swing.*;
public class CloseMyWindow extends JApplet
public JPanel makeContent() {
JButton help = new JButton("Help");
help.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
Dimension size = new Dimension(400, 250);
HelpBox hb = new HelpBox("CloseMyWindow Help",
"cmwHelp.html", false, size);
JPanel jp = new JPanel();
jp.add(help);
return jp;
// method expected by applets
public void init()
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JPanel frame = makeContent();
setContentPane(frame);
} catch (Exception e) {
System.err.println("makeContent() failed to complete: " + e);
e.printStackTrace();
public static void main(String[] args)
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(new CloseMyWindow().makeContent());
frame.pack();
frame.setVisible(true);
class HelpBox extends JDialog
{ // general window for display of HTML page
HelpBox(String title, String pUrlS, boolean modal, Dimension pSize)
super((Frame)null, title, modal);
final String urlS = pUrlS;
final Dimension size = pSize;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JEditorPane ep = new JEditorPane();
ep.setEditable(false);
try {
URL url = getClass().getResource(urlS);
ep.setPage(url);
JScrollPane eps = new JScrollPane(ep);
eps.setPreferredSize(size);
getContentPane().add(eps, BorderLayout.CENTER);
} catch (IOException ioE) {
System.err.println("Unable to display help pane");
ioE.printStackTrace();
pack();
setLocationRelativeTo(null);
setVisible(true);
}cmwManifest.txt (be sure to end line with a carriage return) Main-Class: CloseMyWindowcmwHelp.html <html>
<head><title>Help for CloseMyWindow</title></head>
<body>
Good, you've opened this dialog. Now close the browser window containing
my applet.
</applet>
</body>
</html>cmw.html <html>
<head><title>Close My Window</title></head>
<body>
<applet code="CloseMyWindow.class"
archive="CloseMyWindow.jar"
width="450" height="300">
Your browser is completely ignoring the <i>applet</i> tag!
</applet>
</body>
</html>1) capture the 4 code segments above and save them as correspondingly-named files.
2) compile:
] javac CloseMyWindow.java
3) build the jar:
] jar cvfm CloseMyWindow.jar cmwManifest.txt *.class cmwHelp.html
4) test the jar:
] java -jar CloseMyWindow.jar
5) run the applet. Open page cmw.html in a new browser window
6) enable Java Console (mine is set to autostart on any applet or JNLP)
7) click the applet's Help button. A new dialog should open up.
8) close the browser window
9) observe if an error is reported in Java Console
I am seeing the error in this small applet. Maybe the .java file will give you guys some clues. -
IE locks out after applet window closed
I am using an applet which communicates with the server through RMI.
I am launching a browser window with my applet in it from a secure socket layer server.
When I close this window IE locks out but Netscape doesn't.
I tried overriding Applet.destroy() in order to dispose() any windows which I make using the browser frame and which might still be hanging around.
I notice that Netscape calls Applet.destroy() but IE doesn't or does not get that far.
Please can anyone tell me if I am on the right track and/or what I might try to fix this lockout.
Thanks,
NickHi,
I have a similar problem. From watching he trace file of the Java plug-in, IE 5.50.4134.0600 is calling the STOP, DESTROY, DISPOSE, and QUIT applet events all together. It doesn't wait for the applet.stop and applet.distroy functions to finish. My applet saves the user settings in serialized objects and sends it to the server to be saved in the database. If this process finishes before the shutdown of IE, it goes through to the server. Unfortunately, it's not always that fast.
My applet is not signed. That means that any restricted call in applet.stop() and applet.distroy() will be restricted because they are not called from inside the sand box. I read somewhere that signing the applet will solve this. However, Is that the cause of my problem?
Thanks,
BYTTNerd -
hello guys
i have a main GUI frame and one button on that fires another frame with few graphs. i have an exit button the child one that needs to close that window and return to main one but that button is not working.
i have tried almost everything so far viz. dispose(), DISPOSE_ON_CLOSE, ChildFrame.this.dispose(), setVisible(false),,,,,, but nothing is working.
please please help .....
thanks a lotok.. its a bit longer to read but i m doin it
################ child class ###################
/* Split pane to view simulation results*/
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
public class GraphPane extends JFrame implements ActionListener {
private JPanel base,graphic;
private JButton first,second,third,fourth,fifth,viewer,quit;
private JTextField firstT,secondT,thirdT,fourthT,fifthT;
private JSplitPane hPane;
private TitledBorder title;
private JFileChooser fc;
//mode constants
private final String FIMB="fimB graphs";
private final String FIME="fimE graphs";
private final String FIMBOTH="Co-ordinated graphs";
//mode flag
private String modus=FIMBOTH;
// arrays to hold data of the simulation(s)
private int[] reader1=new int[75];
private int[] reader2=new int[75];
private int[] reader3=new int[75];
private int[] reader4=new int[75];
private int[] reader5=new int[75];
// arrays to supply data
private int[] supply1=new int[25];
private int[] supply2=new int[25];
private int[] supply3=new int[25];
private int[] supply4=new int[25];
private int[] supply5=new int[25];
// comboBox to choose viewing option
private JComboBox selector;
//change determiner
private boolean isChange;
//setting up gridbag layout
GridBagLayout gridbag;
GridBagConstraints c;
public Component createViewcom() {
//put a relevant image on buttons
ImageIcon opnerIcon = createImageIcon("images/opener.gif");
//create a file chooser
fc=new JFileChooser() ;
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setFileFilter(new NewFileFilter());
// create the mode chooser
selector=new JComboBox();
selector.addItem(FIMBOTH);
selector.addItem(FIMB);
selector.addItem(FIME);
selector.setFocusable(false);
//adding item listener
ModeListener modeListener=new ModeListener();
selector.addItemListener(modeListener);
selector.revalidate();
//selection buttons
first=new JButton("Simulation_1",opnerIcon);
first.setHorizontalTextPosition(AbstractButton.LEFT);
first.setForeground(Color.red);
first.setFocusable(false);
first.addActionListener(new ButtonAction1());
second=new JButton("Simulation_2",opnerIcon);
second.setHorizontalTextPosition(AbstractButton.LEFT);
second.setForeground(Color.blue);
second.setFocusable(false);
second.addActionListener(new ButtonAction2());
third=new JButton("Simulation_3",opnerIcon);
third.setHorizontalTextPosition(AbstractButton.LEFT);
third.setForeground(Color.green);
third.setFocusable(false);
third.addActionListener(new ButtonAction3());
fourth=new JButton("Simulation_4",opnerIcon);
fourth.setHorizontalTextPosition(AbstractButton.LEFT);
fourth.setForeground(Color.orange);
fourth.setFocusable(false);
fourth.addActionListener(new ButtonAction4());
fifth=new JButton("Simulation_5",opnerIcon);
fifth.setHorizontalTextPosition(AbstractButton.LEFT);
fifth.setForeground(Color.cyan);
fifth.setFocusable(false);
fifth.addActionListener(new ButtonAction5());
// textfields
firstT=new JTextField(14);
firstT.setEditable(false);
secondT=new JTextField(14);
secondT.setEditable(false);
thirdT=new JTextField(14);
thirdT.setEditable(false);
fourthT=new JTextField(14);
fourthT.setEditable(false);
fifthT=new JTextField(14);
fifthT.setEditable(false);
// viewer button
viewer=new JButton("View Result");
viewer.setFocusable(false);
viewer.addActionListener(this);
//quit button
quit=new JButton(" Exit ");
quit.setFocusable(false);
quit.addActionListener(new QuitButtonListener(this));
//add them to panel
base=new JPanel();
// layout manager
gridbag = new GridBagLayout();
c = new GridBagConstraints();
base.setLayout(gridbag);
base.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
// set constarins for the panel
//add combo box
c.gridx = 0;
c.gridy = 0;
c.gridheight = 1;
c.gridwidth = 2;
c.insets = new Insets(10,0,50,45);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(selector, c);
base.add(selector);
// first set
c.gridx = 0;
c.gridy = 1;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(first, c);
base.add(first);
c.gridx = 1;
c.gridy = 1;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(firstT, c);
base.add(firstT);
//second set
c.gridx = 0;
c.gridy = 2;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(second, c);
base.add(second);
c.gridx = 1;
c.gridy = 2;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(secondT, c);
base.add(secondT);
// third set
c.gridx = 0;
c.gridy = 3;
c.gridheight = 1;
c.gridwidth = 1;
gridbag.setConstraints(third, c);
c.insets = new Insets(10,0,10,10);
base.add(third);
c.gridx = 1;
c.gridy = 3;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(thirdT, c);
base.add(thirdT);
//fourth set
c.gridx = 0;
c.gridy = 4;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fourth, c);
base.add(fourth);
c.gridx = 1;
c.gridy = 4;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fourthT, c);
base.add(fourthT);
//fifth set
c.gridx = 0;
c.gridy = 5;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fifth, c);
base.add(fifth);
c.gridx = 1;
c.gridy = 5;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fifthT, c);
base.add(fifthT);
//the viewer button
c.gridx = 0;
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(15,0,0,0);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(viewer, c);
base.add(viewer);
//the quit button
c.gridx = 1;
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(15,0,0,0);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(quit, c);
base.add(quit);
base.setPreferredSize(new Dimension(320,440));
title=BorderFactory.createTitledBorder("Simulation Comparison");
base.setBorder(title);
base.setVisible(true);
base.setOpaque(true);
base.updateUI();
//split pane creation
hPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
boolean b = hPane.isContinuousLayout(); // false by default
hPane.setContinuousLayout(true);
b = hPane.isOneTouchExpandable(); // false by default
hPane.setOneTouchExpandable(true);
//hPane.resetToPreferredSizes();
hPane.setDividerLocation(365);
//allocate left component
hPane.setLeftComponent(base);
//allocate right component with a default graph panel
DefaultGraph prelude=new DefaultGraph();
graphic=new JPanel();
graphic.add(prelude);
graphic.setPreferredSize(new Dimension(590,440));
graphic.setVisible(true);
graphic.validate();
hPane.setRightComponent(graphic);
hPane.setPreferredSize(new Dimension(945,440));
hPane.setVisible(true);
return hPane;
// action performed for view Result button
public void actionPerformed (ActionEvent e) {
if(modus.equals(FIMBOTH))
System.out.println("3");
for(int i=50,j=0;i<75;i++,j++)
supply1[j]=reader1;
supply2[j]=reader2[i];
supply3[j]=reader3[i];
supply4[j]=reader4[i];
supply5[j]=reader5[i];
else if(modus.equals(FIME))
System.out.println("2");
for(int i=25,j=0;i<50;i++,j++)
supply1[j]=reader1[i];
supply2[j]=reader2[i];
supply3[j]=reader3[i];
supply4[j]=reader4[i];
supply5[j]=reader5[i];
else if (modus.equals(FIMB))
System.out.println("1");
for(int i=0;i<25;i++)
supply1[i]=reader1[i];
supply2[i]=reader2[i];
supply3[i]=reader3[i];
supply4[i]=reader4[i];
supply5[i]=reader5[i];
System.out.println("works fine!");
if(isChange)
viewer.setEnabled(false);
else
System.out.println("button enabled");
// add GraphReceptorData panel to the splitPane
GraphReceptorData graph = new GraphReceptorData(this);
graphic.removeAll();
graphic.add(graph);
//reset the divider location
hPane.setDividerLocation(365);
//repaint the pane after change
graphic.validate();
graphic.paintImmediately(graph.getX(),graph.getY(),570,400);
//add graph to the the split pane finally
hPane.setRightComponent(graphic);
// isChange boolean method
public boolean isChanged() {
if ((first.isSelected())||(second.isSelected())
||(third.isSelected())||(fourth.isSelected())||
(fifth.isSelected()))
isChange=true;
return isChange;
//Action listeners for buttons
class ButtonAction1 implements ActionListener {
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == first) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
firstT.setText(fc.getName(file));
RandomAccessFile simulation1=new RandomAccessFile(firstT.getText(),"r");
if ((firstT.getText().equals(fourthT.getText()))||(firstT.getText().equals(thirdT.getText()))||(firstT.getText().equals(secondT.getText()))||(firstT.getText().equals(fifthT.getText())))
firstT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation1.seek(i);
reader1[i/4]=simulation1.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction2 implements ActionListener {
// action performed for button2
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == second) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
secondT.setText(fc.getName(file));
RandomAccessFile simulation2=new RandomAccessFile(secondT.getText(),"r");
if ((secondT.getText().equals(firstT.getText()))||(secondT.getText().equals(thirdT.getText()))||(secondT.getText().equals(fourthT.getText()))||(secondT.getText().equals(fifthT.getText())))
secondT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation2.seek(i);
reader2[i/4]=simulation2.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction3 implements ActionListener {
//action performed for button3
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == third) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
thirdT.setText(fc.getName(file));
RandomAccessFile simulation3=new RandomAccessFile(thirdT.getText(),"r");
if ((thirdT.getText().equals(firstT.getText()))||(thirdT.getText().equals(secondT.getText()))||(thirdT.getText().equals(fourthT.getText()))||(thirdT.getText().equals(fifthT.getText())))
thirdT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation3.seek(i);
reader3[i/4]=simulation3.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction4 implements ActionListener {
//action performed for button4
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == fourth) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
fourthT.setText(fc.getName(file));
RandomAccessFile simulation4=new RandomAccessFile(fourthT.getText(),"r");
if ((fourthT.getText().equals(thirdT.getText()))||(fourthT.getText().equals(secondT.getText()))||(fourthT.getText().equals(firstT.getText()))||(fourthT.getText().equals(fifthT.getText())))
fourthT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation4.seek(i);
reader4[i/4]=simulation4.readInt();
} //end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction5 implements ActionListener {
//action performed for button5
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == fifth) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
fifthT.setText(fc.getName(file));
RandomAccessFile simulation5=new RandomAccessFile(fifthT.getText(),"r");
if ((fifthT.getText().equals(fourthT.getText()))||(fifthT.getText().equals(thirdT.getText()))||(fifthT.getText().equals(secondT.getText()))||(fifthT.getText().equals(firstT.getText())))
fifthT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation5.seek(i);
reader5[i/4]=simulation5.readInt();
} //end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
//selector listener
class ModeListener implements ItemListener {
// This method is called only if a new item has been selected.
public void itemStateChanged(ItemEvent evt) {
selector = (JComboBox)evt.getSource();
// Get the affected item
String s=(String)selector.getSelectedItem();
if (evt.getStateChange() == ItemEvent.SELECTED) {
// Item selected
modus=s;
System.out.println("cell selected is " + modus);
} else if (evt.getStateChange() == ItemEvent.DESELECTED) {
// Item is no longer selected
} // end of mode listener
// Returns an ImageIcon, or null if the path was invalid
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = GraphPane.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
//get methods to retrieve the values of supply arrays to feed into GraphReceptorData class
public int[] getSupplyOne() {
return supply1;
public int[] getSupplyTwo() {
return supply2;
public int[] getSupplyThree() {
return supply3;
public int[] getSupplyFour() {
return supply4;
public int[] getSupplyFive() {
return supply5;
// listener for the exit button
class QuitButtonListener implements ActionListener {
private Window myWindow;
public QuitButtonListener(Window w) {
myWindow = w; }
public void actionPerformed(ActionEvent evt) {
myWindow.setVisible(false);
myWindow.dispose();
######################## parent class#################
the button there is just calling this class.
// ActionListener for viewGraph button
class ButtonGraph implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFrame frame=new JFrame("Graph view screen");
frame.getContentPane().add(new GraphPane().createViewcom(), BorderLayout.CENTER);
frame.setSize(945, 440);
frame.setResizable(false);
frame.setVisible(true);
}hope this will explain more...
thanks a lot for help guys -
I am setting the seperate window = TRUE in my formsweb.cfg. This opens up the form as a seperate applet. This is what I want. But how do I close the window which loaded this applet? I want only the applet to be active, remaining all windows closed.
I followed the recommendation, but in my case it doesn't work.
The code
HTMLbodyAttrs=onLoad='javascript:self.moveTo(2000,2000)'
or
HTMLbodyAttrs=onLoad='javascript:self.moveTo(1601,1201)'
doesn’t work properly. I have noticed that if the browser original size is not full screen, then when that javascript code runs, the browser just moves down to maximum possible bottom position, but it doesn’t disappear or get minimized – browser window size doesn’t change.
Who knows what the problem is?
Thanks,
Dmitri -
How to tell embedded jinitator applet is still running when window closed
Hello, we are trying to accomplish the same thing that is mentioned in this post from Metalink. I've searched for a solution and hope someone here can help. Instead of restating the issue I think David Wilson does a good job of explaining what is needed. Can anyone please suggest a possible solution?
From: David Wilton 07-Oct-05 01:08
Subject: How to tell embedded jinitator applet is still running when window closed
How to tell embedded jinitator applet is still running when window closed
Hi,
We run an oracle 10g forms application through 9iAS over an intranet. All users are running windows 2000 professional.
We run separate frame = true but I would like to switch to separate frame = false
With separate frame = true if the user clicks the outer windows "X" close button (forms mdi window) the user is prompted to save changes before the application ends.
BUT
when using separate frame = false
If the user clicks the upper window "X" button (no longer form mdi window but regular browser window) the window and application is abruptly closed.
I'm interested in using a onbeforeunload function to confirm if the user wants to close the window. This would be placed in the basejini.htm file. This could always ask if the user wants to exit or not. If they click OK then the window closes but if they click "Cancel" you are returned to the forms application exactly where you left. something like event.returnvalue="do you really want to exit?";
However if the user exited using the normal exit form method then the applet is already closed before the onbeforeunoad event fires and there is nothing to go back to and I want the window to close automatically. This is accomplished using close.html file in post forms trigger.
So what I want and what I think many may also want is the check if the embedded applet is still running and if so prompt the user to return to the application or continue to close. Of course If the applet is no longer running then just close because there is no reason confirm closing anymore.
Does anyone have a html/JavaScript solution that can be placed in the jinitiator.htm file? or similar?
Thank you
David
[email protected]
From: Andrew Lenton 07-Oct-05 08:58
Subject: Re : How to tell embedded jinitator applet is still running when window closed
I don't know if this is exactly what you are after but you can add the following to the top of your basejini.htm file and it should prompt the user before exiting the IE window.
<BODY %HTMLbodyAttrs%>
%HTMLbeforeForm%
<SCRIPT>
<!--
window.onbeforeunload = unloadApplet;
function unloadApplet(){
message = "Warning! Please exit the Java Applet prior to
exiting the browser"
return message;
//-->
</SCRIPT>
From: Oracle, mohammed pasha 07-Oct-05 09:55
Subject: Re : How to tell embedded jinitator applet is still running when window closed
David,
Well I could not understand your complete requirement.
Refer to Note.201481.1 How to Close the Browser Window When Closing Forms And How to Simulate SeparateFrame By Javascript
Note.115905.1 How to Close Browser Window When Closing Webforms Applet
Kind Regards,
Anwar
From: David Wilton 07-Oct-05 14:37
Subject: Re : How to tell embedded jinitator applet is still running when window closed
Thank you for your reply and yes you did not understand my question fully.
Sorry if this is a long reply
I am able to close the browser window using information in notes 115905.1 and 201481.1, this is not the issue. We implemented this several years ago. It is workable for both separate frame = true or false.
It is most important to not allow the user to end their forms application by closing the windows browser, they must close using normal form exit commands.
What I want is to have separate frame = false, the big drawback to this option is the user can exit the application and bypass all forms code by pressing the windows "X" close button. This is why we need the code as just provided by Andrew Lenton above in this thread.
BUT Andrew's code will always prompt the user before closing the window and I do not want that. I want the user to be prompted only under scenario 2 listed below.
Here's the 2 case scenario for exiting the application.
1. If the user closes properly and uses exit form which fires all normal form triggers including post_form with it's call to close.html file.
All uncommitted changes are saved or rollback and the users session is ended normally both on the database and in the application server.
All browser windows will close, great all is good. And without Andrew's code the window will close but with Andrew's code the user will be prompted to close or not, if they select Cancel the window will remain but the applet has already ended so why prompt? ...This is what I want to avoid.
2. In the forms app. if the user clicks the windows "X" close button with uncommitted changes. The browser just closes the changes are rollback without prompting the user to save. The users sessions are now lost and still running in the database and application server until they are timed out.
If I use Andrew's code then the user will be prompted to continue to close or go back, if they click Cancel to go back then focus returns to the forms application and the user can continue to work. If the user clicks OK then the window closes and unfortunately their sessions are still lost until timed out.
So what I desire is to add to Andrew's code to check if the embedded applet is still running and prompt the user to close or not accordingly.
Something like:
Basejini.htm like
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function maximizeWindow()
window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);
function confirm(){
If(document.embeddedapplet.closed())
Win.opener = self;
win.close();
Else if
event.returnValue = "Closing Forms Application. OK to continue?";
</SCRIPT>
<BODY %HTMLbodyAttrs%, onload="maximizeWindow()", onbeforeunload="confirm()">
%HTMLbeforeForm%
I hope this explains my requirements.
David
From: Oracle, Evelene Raechel 10-Oct-05 06:45
Subject: Re : How to tell embedded jinitator applet is still running when window closed
Hi,
Note.199928.1 How to Alert User on Closing Client's Browser Window in Webforms
Regards,
Rachel
From: David Wilton 11-Oct-05 17:40
Subject: Re : How to tell embedded jinitator applet is still running when window closed
I'm sorry this is not helpful at all.
Note 199928.1 is only an alert which does not stop the closing of the window and still displays as an alert if the user does close properly using exit form ... so why would you want to display the alert then?
This is exaclty what I do not want and why I want to determine if the applet is still running before displaying any kind of message.
David
From: Oracle, Evelene Raechel 17-Oct-05 12:23
Subject: Re : How to tell embedded jinitator applet is still running when window closed
Closing thread.
Thanks,Hello,
I had the same issue last year - wanting to provide a warning on closing the browser, but only if the Forms session is still running. The approach I took is described below, see also the thread where I originally posted this at Closing brower window
Hi there,I've had a similar requirement - or rather, the two conflicting requirements: to warn when the browser is being closed, but for the app to be able to close the browser without a warning being fired.
To always provide a warning when someone (the user or the Forms app) tries to go to a different page (e.g. your close.htm), use Javascript like:
function confirmExit(){
if(appletRunning==true) {
msg="Closing this window or navigating to another page will end your SomeGreatApp session.";
window.event.returnValue=msg;
And make a call to confirmExit() in the onBeforeUnload event of your main page.
You'll notice I first check an 'appletRunning' variable before displaying the warning. This Javascript variable is set to true by my app when it starts up, using an embedded Javabean that calls out to Javascript. Once that variable is set to true, then the warning will be displayed if the user tries to shut the browser by clicking on the 'x' button, or to go to a different URL.
When my app is shutting down, it uses the same Javabean to set appletRunning back to false. It then navigates to a close.htm - which will be done without a warning being displayed.
See Re: How can a Javabean call Javascript function of the basejpi.html?? for example code on how to call Javascript from a bean embedded in your Forms app.
Hope these ideas help you out, it's worked for me (so far, anyway!!)
James -
i have two Q:
1) how do i close applet window ?
2)how can i know that the X button of the applet window was pressed?1) You don't...the browser takes care of that!
2) In IE, the applet's stop and destroy methods are called when the user moves from your HTML to another or the window is closed. In NN4+, the applet's stop method is called when the user moves away from your HTML and the destroy method is call when the window is closed. I don't bother with NN6.2+ because to me it's still a beta product based on Mozilla version .9 something and is so slow.
V.V. -
how to close the applet window using a button on the applet
ravindra.alld wrote:
how to close the applet window using a button on the appletIs your applet in a web browser? If so the only way to hide visibility of the applet would be through javascript and css. So you would need an html button outside the applet to do this. -
We are using separate_frame=true and trying to close the applet window (the one with the large gray box) after using the following post-form trigger:
if :system.last_form = 0 then
message('Please wait while Forms closes - '||:system.last_form);
web.show_document('/forms/html/close.htm','_self');
end if;
This works fine for the first form we open, but if that same form using Open_Form to open a child form we have a problem. When the child form is closed the user is returned to the parent calling form (which is expected), but then when the parent form is closed the separate applet window fails to close. Any suggestions?I guess you mis-interpreted the value of :SYSTEM.LAST_FORM. From the online-help:
SYSTEM.LAST_FORM represents the form document ID of the previous form in a multi-form application, where multiple forms have been invoked using OPEN_FORM.So LAST_FORM shows always the ID of the last activated form, and this will never be 0 if you issued one OPEN_FORM in your application. -
Reports 6i windows display problem on Windows NT system
Iam using Reports 6i on Windows NT.All the reports 6i windows are became transporent windows, displying problem (repainting problem). I did fresh installation. But iam not able to solve this.
I am using same fonts on all these plateforms.Look more closely at those fonts. They may have the same names, but the Windows 2000 versions may be larger (able to render more characters).
-
I need help with java on windowsXP after updating iTunes to the latest version. My java will not work and I get error message need java virtual machine to run applet window. Did not have this problem prior to the iTunes update.
Please help, ThanksIf your library was working on your computer and then popped up empty all of a sudden then this might be what you need...
Empty/corrupt library after upgrade/crash
Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping. In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
When you get it all working make a backup!
tt2 -
Java Applet Window Warning - Appearing through
Hello
The warning that is displayed on applet windows now when using java is causing a problem.
When you bring a fresh web page or word document over the top of the applet window, the java applet warning is still visible as if it has been brought to the front layer. but the rest of the applet is behind the new active window.
Really weird.
Ben.Our team is also using a signed applet and are having trouble with popup items not being accessible outside of the JFrame.
In appletviewer the popup (JXDatePicker) is fully accessible. If running in Internet Explorer on Windows 2000 the portion of the popup outside of the JFrame paints correctly but cannot receive click events correctly.
It would be preferrable that if the popup cannot receive events outside of the applet frame that the popup would be smart enough to pop itself fully in the applet frame.
Any suggestions?
Thank you. -
Java applet window blocking yahoo games
not a devloper, but I really need some help handling this java problem. when I log onto yahoo games, bar that says "java applet window" blocks the bottom portion of the screen. how can I get rid of this?
i found out how to get older verison of java6-7 verison .
Go to search bar type in OpenOffice.org 3.0 and download this.it will take about 30 minute to download this file.after download this go to add & REMOVE PROGRAM to see if download and if did delete java 6u10 version . email me at [email protected] to see it work -
Java Applet Window showing on signed applet popups
I have an applet deployed that is signed, but I'm experiencing a very annoying problem with JPopup windows that cross outside the border of the JFrame created by the Applet.
Those pop-up windows still show the warning at the bottom "Java Applet Window". That part is pretty annoying and I don't understand why it's doing that since they are coming from a signed, trusted applet.
Just to be clear, any of the JPopups or JDialogs or anything else we display inside the frame doesn't have this warning since we signed the applet.Our team is also using a signed applet and are having trouble with popup items not being accessible outside of the JFrame.
In appletviewer the popup (JXDatePicker) is fully accessible. If running in Internet Explorer on Windows 2000 the portion of the popup outside of the JFrame paints correctly but cannot receive click events correctly.
It would be preferrable that if the popup cannot receive events outside of the applet frame that the popup would be smart enough to pop itself fully in the applet frame.
Any suggestions?
Thank you.
Maybe you are looking for
-
Accessing Element's name in Message mapping
Hi, I need to Access the Element's name in Message mapping (Using graphical tool or in user defined function). For Example: Element: <Company_Name>XYZ Co </Company_Name> I need to access the Element's name(i.e.)<b>"Company_Name"</b>. So that I can
-
Can't open 1.0 projects in CS3 (no subtitles)
After working with Encore 1.0 for forever and a day, I finally got PPro CS3 with its accompanying Encore (running on Windows XP SP2). But I cannot open any Encore 1.0 projects. Trying to open my current project, I get this complaint: >Encore cannot o
-
Hey there, I've been having some trouble with (I presume) my graphics card. Basically I can play games just fine after my computer has just started up (or reset). But after a while of playing games or using 3d software in general I can't start a new
-
NullPointerException when opening a script in SQL Developer 4.0.0.12
I recently upgraded to SQL Developer v.4.0.0.12 64 bit, and am running into some issues. I am running this on 64 bit Windows 7. I have a 64 bit Oracle 11, and in addition have the 32 bit oracle client installed. I made an association between the .sql
-
Cannot insert duplicate key row in object
This is a JPA question. The tbHardware table has a PK identity column and a unique non-clustered index on CoxBarcode column. I have a SFSB in a Seam2.0.0.GA app running on JBoss 4.2.1.GA. I am using flushMode=FlushModeType.MANUAL (Seam specific when