Multiple windows... closing one exits the app!
Hi, I've created a simple web browser where the class with the main method is supposed to create some windows and have the app exit when the last window is closed. The problem is that when I go to close just one of the windows all the windows close and the application exits.
Any help is appreciated! :)
Browser.java
package browser.Browser;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Browser {
public static void main(String[] args) {
BrowserFrame f1 = new BrowserFrame();
f1.setVisible(true);
BrowserFrame f2 = new BrowserFrame();
f2.setVisible(true);
/*public void newWindow() {
BrowserFrame f = new BrowserFrame();
f.setVisible(true);
BrowserFrame.java
package browser.Browser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.net.*;
import java.io.*;
public class BrowserFrame extends JFrame implements
ActionListener,
HyperlinkListener {
Color menuColor = new Color(220, 220, 220);
URL url;
JTextField URLBar;
static JButton goButton;
static JEditorPane ViewArea;
* The constructor.
public BrowserFrame() {
//look and feel
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
Toolkit.getDefaultToolkit().setDynamicLayout(true);
catch (ClassNotFoundException e) {/*do nothing*/}
catch (InstantiationException e) {/*do nothing*/}
catch (IllegalAccessException e) {/*do nothing*/}
catch (UnsupportedLookAndFeelException e) {/*do nothing*/}
//create the controls
try {
url = new URL("http://www.google.com");
}catch(MalformedURLException e) {/*do nothing*/}
URLBar = new JTextField();
goButton = new JButton("Go");
ViewArea = new JEditorPane();
JPanel upperPanel = new JPanel();
JPanel mainPanel = new JPanel();
upperPanel.setLayout(new BorderLayout());
mainPanel.setLayout(new BorderLayout());
//set the control's properties
goButton.setSize(new Dimension(12, 20));
URLBar.setText(url.getProtocol() + "://" + url.getHost() + "/");
URLBar.setBorder(BorderFactory.createEtchedBorder());
ViewArea.setEditable(false);
//Event handlers
goButton.addActionListener(this);
URLBar.addActionListener(this);
ViewArea.addHyperlinkListener(this);
//The scrollPane is for the ViewArea
JScrollPane scrollPane = new JScrollPane(ViewArea);
//add controls to the panel(s)
mainPanel.add(upperPanel, BorderLayout.NORTH);
upperPanel.add(URLBar, BorderLayout.CENTER);
upperPanel.add(goButton, BorderLayout.EAST);
mainPanel.add(scrollPane, BorderLayout.CENTER);
//frame setup
setJMenuBar(CreateJMenuBar());
getContentPane().add(mainPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 450);
URLBar.setSize(getWidth() - goButton.getWidth(), 20);
setVisible(true);
connectToURL();
//actionListener methods
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Exit")) {
dispose();
//System.exit(0);
else if(e.getSource() == goButton) {
try {
url = new URL(URLBar.getText());
connectToURL();
}catch (MalformedURLException err) { //try prefixing "http://"
try {
url = new URL("http://" + URLBar.getText());
connectToURL();
catch(MalformedURLException e2) {/*do nothing*/}
else if(e.getSource() == URLBar) {
System.out.println(URLBar.getText());
try {
url = new URL(URLBar.getText());
connectToURL();
catch (MalformedURLException err) { //try prefixing "http://"
try {
url = new URL("http://" + URLBar.getText());
connectToURL();
catch(MalformedURLException e2) {/*do nothing*/}
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
if (e instanceof HTMLFrameHyperlinkEvent) {
((HTMLDocument)ViewArea.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)e);
else {
try {
ViewArea.setPage(e.getURL());
URLBar.setText(ViewArea.getPage().toString());
catch(IOException ioe) {
System.out.println(ioe);
public void connectToURL() {
try {
URLBar.setText(url.toString());
ViewArea.setPage(url);
catch(IOException e) {
URLBar.setText("failed.");
public JMenuBar CreateJMenuBar() {
JMenuBar menuBar = new JMenuBar();
menuBar.setBorderPainted(false);
JMenu menu = new JMenu("File");
menu.setMnemonic(KeyEvent.VK_F); //for navigating the menu
JMenuItem menuItem;
menuBar.setBackground(menuColor);
menu.setBackground(menuColor);
menuBar.add(menu);
//the menuitems for "File"
menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
menuItem.getAccessibleContext().setAccessibleDescription("Exit the program");
menuItem.setBackground(menuColor);
menuItem.addActionListener(this);
menu.add(menuItem);
//the menuitems for "Edit"
menu = new JMenu("Edit");
return menuBar;
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);I don't know much of Swing but it might have something to do with this line. You might take a look at the Swing tutorials and the API docs.
Similar Messages
-
Angry birds froze- how do I exit the app
Using a new iMac and Angry Birds froze up. How can I exit the app? Is there a command similar to CtrlAltDel or something to exit?
Select Force Quit... from the Apple menu. Sometimes you will have to click to another application to get the Apple menu to respond. This will bring up the Force Quit Applications window; stuck applications may appear in this list in red. You can then select the misbehaving application and click the Force Quit button. Occasionally you will have to dismiss this window and repeat the process to really get the app to quit, but this should be rare. If necessary, you can Force Quit multiple applications from this window.
Control-click/right-click on an application's icon in the Dock. Usually you can simply quit an application from this menu. A stuck application will often say Force Quit in place of Quit, though you can hold down the option key if it does not. -
Photoshop crashes while using multiple windows with one image
Has anyone else encountered the following problem:
Photoshop CS4 crashes sooner or later when working with multiple windows with one image (window->arrange->new window for...).
I remember having same problem since CS2. Is this a bug in Photoshop or am I having a bad luck?
Technical specifics:
Ps CS4, iMac, 21.5, 10.6Don't know. I haven't heard of other people having that problem.
Do you have a crash report I could look at?
Or have you attached your email to crash reports sent to Adobe and can you tell me the date on one of them? -
Okay. I am totally in a bad situtation. I have IOS 6 and 2 things have gone wrong. The Music app where you have your music, is bad. I have songs and stuff. And when i touch a song nothing happens. The letters are grey and nothing happens. The app store is also a problem. The appstore on IOS 6, when im on search and i search for and app, it exits the app store in like 5 seconds. And when i first updated the IOS 6, it was still like that HELP!
Did you do a restore from iTune or iCloud backup recently?
-
When i try to open week cal it loads and then closes after a few seconds...I have checked for updates, turned the phone off then on, closed out of the app and then opened it again...nothing works! I have thought about deleting the app from my phone and then reloading it again but I worry that it will delete all my calendar info??? Any suggestions?
To reset, press and hold the Home and power buttons until the silver apple appears.
I would delete the app, reset the phone and then download the app again. Your calendar information should be stored on the phone as Week Cal uses the Calendar app information.
Best of luck. -
Hello, my iPod touch is not working right. It says its connected but if I select App Store, safari and other apps that require wifi pops out a note saying either"error loading" or "cannot connect to iTunes Store" and would exit the app automatically. Please help.
Thank You.See:
Can't connect to the iTunes Store -
i have a ipod nano 1st and 2nd generation and am trying to put music on it but every time windows says one of the usb devices attached to this computer has malufunctioned and windows does not recognize it code 43 can someone help me please
Try putting it into "Disk Mode" http://docs.info.apple.com/article.html?artnum=93651
Then with it in this mode connect it to the PC and try to run the latest iPod updater to do a restore and update software if you have the option. the latest iPod updater is 2006-03-23 and can be downloaded here http://www.apple.com/ipod/download/ -
i would like to go for older version of one of the app ( snipsnap ). previously i used to have in my iphone but during synching i did not got option to transfer apps to library so i lost all my apps. how can i get snipsnap v1.3 again? or if anyone have link to this older version app please let me know. thanks.
You appear to have an iPhone 5. Snipsnap 2.4.2, the current version, says it works on iPhone 5, iOS 5.0 or later. Why do you want an out of date version of the app?
-
my iphone froze last nite and i was unable to exit the app i was on, it then switched the screen off as if it was not in use, now i am unable to open my iphone or switch it off, calls are still comin thro as phone is vibrating but im unable to answer as cant activate the screen?????
pls helpSee Here for > Frozen or unresponsive iPhone
Try this First...
Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
Wait for the Apple logo to Appear...
Usually takes about 15 - 20 Seconds... ( But can take Longer...)
Release the Buttons...
http://support.apple.com/kb/ht1430
More Info here...
https://discussions.apple.com/message/19521062 -
I have a iPod touch 4 and updated the iOS 6 and always when I try to search for an app in the App Store it won't let me because it always exits the App Store. Why is this happening?
Have you tried resetting and restoring your iPod?
-
Why does my ipad2 suddenly exit the apps I use ?
How come that sometimes when I'm using my ipad2,it suddenly exits the app I'm using & go's back to my home screen?
Try restarting it. Press and hold the sleep / wake switch until the red slider appears, then slide it to power off.
If you updated to iOS 6, sometimes app developers just have to catch up. Check for updates in the App Store. -
Why does Calendar keep reverting from full screen each time I exit the app?
I'm using a 2014 Macbook Air. It's running Yosemite.
Why does Calendar keep reverting from full screen each time I exit the app?
On my older Macbook at work, calendar stays full screen whether I exit the app or restart the computer (similar to Mail - which is staying in full screen on both computers).
Please help me adjust settings so I don't have to keep putting Calendar into full screen.
Thanks!HI Thanks so much! It fixed porblem (for the moment) by reinstalling PS6 and NOT installing the 13.03 update which, although said it was performance related, probaly had that trial messge embeded in it. So just DON"T install update 13.03 till adobe gets it's sea legs and stops puking up this message over and over. aloha, U
Curt Y wrote:
Did you update recently? There is a bug in that causing your problelm. See this thread. http://forums.adobe.com/thread/1114727?tstart=0 -
Can I authorize my boyfriend's itunes or iphone to use one of the apps that I purchased?
Stormy25 wrote:
So if I log onto my itunes using his phone I can download the app to his phone?
That's called "stealing", plain & simple, same as if you stole something from a store. Sorry, but what you want to do is not permitted under the SLA & you won't get any help here...Apple owns/runs this forum. -
I've tried downloading 3 seprate songs thur iTunes on my iPhone 4S and every time it says download incomplete and ask to retry but continues the same message. I've restarted my phone, checked internet connection, closed out of the app, etc.
Hello Bdev15,
I would be concerned too if the songs I purchased from iTunes were not downloading to my iPhone. You have taken some great troubleshooting steps already, and thank you for providing the details of the steps you too. I have a few additional suggestions to get it downloaded to your iPhone.
First, I recommend checking to see if the download was interrupted:
If your download was interrupted using your iPhone, iPad, or iPod touch
From the Home screen, tap the iTunes app.
For iPhone or iPod touch, tap More > Downloads. For iPad, tap Downloads.
Enter your account name and password if prompted.
Tap the blue download arrow to resume.
iTunes: How to resume interrupted iTunes Store downloads
http://support.apple.com/kb/ht1725
If the songs still do not download, next I recommend downloading the songs when connected to another network. For example, if you are using the cellular network, you could switch to Wi-Fi, or you could try an alternate Wi-Fi network. Follow the steps in the section titled "iPhone, iPad, or iPod touch > Music" in the article below to download the songs:
Downloading past purchases from the App Store, iBookstore, and iTunes Store
http://support.apple.com/kb/ht2519
If you are still not able to download the songs, you can report an issue with these purchases using the steps in this article:
How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
http://support.apple.com/kb/ht1933
Best,
Sheila M. -
when i try to close my iPhoto app on my air it continuously says wait until import is finished and it won't let me exit the app and i cant even turn off my laptop, what can i do to close it?
Welcome to Apple Support Communities
Press Alt, Command and Esc keys or go to > Force Quit, choose iPhoto and force close it.
Maybe you are looking for
-
How to set up display properties for a crosstab is CSS?
I am woundring how to setup css class and code like in this tutorial. myalerting.css ? Set up display properties for a crosstab: Design Studio 1.2 - YouTube. Design Studio 1.2: Set up display properties for a crosstab if you have sample file please s
-
I have a spreadsheet with "expense categories" in one column and "dollar figures" in the second column. When I highlight the columns and create a chart I DON'T want to have to use "show legend" (with the color circles at the bottom) as it repeats my
-
I am trying to create a slide show from the pictures stored in iPhoto, but some of them do not show up in the slide show. Instead, there is a black screen for the three seconds that the photo should be showing. Others from the same library are fine t
-
well, went to a verizon store and replaced my REV. C MI424WR that was causing SLOW download speeds, they gave me a new in box MI424WR REV. E, plugged it in all in as usual... ORANGE internet LED, stays orange, never goes green. I tried unplugging the
-
[SOLVED] Is /opt empty by default?
Hello, i had some issue installing a third party program. I downloaded it as binary, the only thing to do was to place it to /opt. It was a tar.bz2 file. it contents was opt folder, then PorgramName folder and so on. so i issued: sudo tar xjvf archiv