Removing a window and adding a new one with swing.

Hi,
A friend of mine recently asked me to add a GUI for a small chat he made, so I thought I'd help him out. I've come across something that's troubled me in the past, and I could never find a solution. What I'm trying to do is make it so a log in window pops up (have that working alright) and then when you press sign in, it removes that window (log in) and adds the main chat window (have this fully functional, too).
If someone could provide an example or point me in the direction of the proper API to look into, so that I don't have to look through them all, I'd be extremely grateful.
Here's an SSCCE example:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
public class Gui extends JFrame {
     public static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
     public String sessionId;
     public int returnCode;
     public boolean recievedReturnCode;
     public boolean errorConnecting;
     public long lastActionDelay;
     private JScrollPane listScrollPane;
     private JList list;
     private JTextPane console;
     private JButton signInButton;
     private JScrollPane consoleScrollPane;
     private JTextField typingField;
     private DefaultListModel userList;
     private JButton sendButton;
     public static void main(String[] args) {
          try {
               SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                         new Gui().setVisible(true);
          } catch (Exception e) {
               e.printStackTrace();
     public Gui() {
          setResizable(false);
          setSize(500, 500);
          consoleScrollPane = new JScrollPane();
          console = new JTextPane();
          typingField = new JTextField();
          userList = new DefaultListModel();
          sendButton = new JButton();
          initializeLoginWindow();
          setDefaultCloseOperation(EXIT_ON_CLOSE);
     public void initializeLoginWindow() {
          setTitle("Login");
          signInButton = new JButton("Sign in");
          signInButton.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                    initializeChatWindow();
          signInButton.setBounds(5, 100, 75, 20);
          getContentPane().add(signInButton);
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(new JPanel());
     public void initializeChatWindow() {
          consoleScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          consoleScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
          consoleScrollPane.setViewportView(console);
          consoleScrollPane.setBounds(5, 5, 575, 350);
          console.setEditable(false);
          typingField.setEditable(true);
          typingField.setBounds(5, 360, 575, 25);
          list = new JList(userList);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setSelectedIndex(0);
        list.setVisibleRowCount(5);
        listScrollPane = new JScrollPane(list);
          listScrollPane.setBounds(585, 5, 110, 350);
          sendButton.setText("Send");
          sendButton.setBounds(585, 360, 111, 25);
          getContentPane().add(consoleScrollPane);
          getContentPane().add(typingField);
          getContentPane().add(listScrollPane);
          getContentPane().add(sendButton);
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(new JPanel());
}Thanks in advanced!

jduprez wrote:
I've come across something that's troubled me in the past, and I could never find a solutionWhat is the problem?
a log in window pops up (have that working alright)
and then when you press sign in, it removes that window (log in) and adds the main chat window (have this fully functional, too).Hum, between what is working alright and what is already functional, I fail to see what is missing. Again, what is your problem/question?
If someone could provide an example or point me in the direction of the proper API to look into, so that I don't have to look through them all, I'd be extremely grateful.
[url http://download.oracle.com/javase/tutorial/uiswing/components/frame.html]JFrames and [url http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html]dialogs seem to show enough API usage to do that. Still, I stronlgy encourage you to read the whole Swing tutorial: http://download.oracle.com/javase/tutorial/uiswing/index.html
Incase you didn't see the hyperlink above, here's the SSCCE link: http://www.mediafire.com/?e5e3ci3kbvickla
The "S" in SSCCE stands for "Short" (or, depending on authors, "Simple"). Anyway, a decent SSCCE should fit within a forum post (between code tags please). The whole idea is to provide the simplest thing to people willing to help. No doubtful sites. No non-standard extensions.
Best regards,
The problem is that I cannot seem to remove the first pane, leaving the second one to be drawn on the current one.
In reguards to SSCCE, I always thought it was just a short runnable class example, but I've added the class to the main post. I'll take a look at the API in a few as well.

Similar Messages

  • I deleted my old email address and added a new one, after my iPhone died iCloud keeps popping up asking for the password of my old email address. I can't remember my password and the account is still gone, it pops up every few seconds. How can I fix this?

    I deleted my old email address and added a new one, after my iPhone died iCloud keeps popping up asking for the password of my old email address. I can't remember my password and the account is still gone, it pops up every few seconds. How can I fix this?

    If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact AppleCare(or Apple ID Support), upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
    The operator will take you through some steps you may have already tried, however they need to be sure they have exhausted all usual approaches before trying to reset your account, so you should try to be helpful and show patience with the procedure.
    The operator will need to verify they are speaking to the account holder and may ask you some questions that only the account holder could know, and you will need to answer them if the process is to proceed.
    Once the operator has verified your identity they will send a message through to your device which contains an alpha numeric code, which you will need to read back to them.
    Once this has been completed they will send an email to your iCloud email address after a period of 24 hours, so you should check that mail is enabled in your devices iCloud settings.
    Upon receipt of the email, use the reset link provided to reset your password, after which you should be able to make the adjustments to iCloud that you wish to do.

  • Why do my animated themes only work the first time I open the window? Every one that I have tried stops animating if I close the window and open a new one.

    The headline pretty much sums up my problem. Basically, I picked a few different animated themes to try out in the Add-Ons section to personalize my browser window. They look great initially, and in the window that is open when I actually enable the theme. However, if I close that window and open a new one, the theme is stationary and no longer animates.

    Sorry......I was just too impulsive. ( Maybe because it was 4 AM at Taiwan, and I was still trying to solve the problem= = )
    Although to install the add-on "Personas Shuffler" can solve the problem to me, I don't think it was the BEST solution. This evening, I read why the add-on "Personas Shuffler" was made, and found that the BEST solution is:
    1. Open a new tab, and type "about:config" at the URL bar, then search for "lightweightthemes" with the filter.
    2. Change the values of "lightweightThemes.persisted.footerURL" and "lightweightThemes.persisted.headerURL" from true to false( by double click on them).
    3. After doing so, restart Firefox and you will see it works! You don't have to install any add-on.

  • I changed email address and had to delete my account and create a new one with the new email address. When I did this i lost all of the information in my calendar. How can I recover this vital information?

    My email address changed and I had to delete my account and create a new one with the new address. After I did this all of the data in my iPhone calendar is gone. How can I recover this vital data?

    It is my understanding that if you delete the account per the instructions below, you will be able recreate, but you will NOT have access to the prior BBM contacts.
    Read this for full information and suggestions to regain access to your BBID >> http://supportforums.blackberry.com/t5/BlackBerry-World/How-to-regain-access-to-your-BBID/td-p/25467...
    You have to remember either the BlackBerryID password, or the secret question answer. Without either, you're stuck.
    Your choices are:
    --Use another email account to create an entirely new BlackBerryID (with which you will lose access to any purchased apps using the "forgotten" first BlackBerryID, or
    --Find the initial email you were sent to confirm the initial BlackBerryID, and in it is a link to click to cancel and delete the account. Click on that, delete the account and then you can use that same email to create an entirely new account.
    Good luck.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I forgot the answer to the security questions and i forgot the email i put there to resend the link so i can change it. i want to close my apple ID and open a new one with the same email could i?

    i forgot the answer to the security questions and i forgot the email i put there to resend the link so i can change it. i want to close my apple ID and open a new one with the same email could i?

    i live in saudi arabia and i tried calling them and letting them call me but they said that it is unable to my country. ***** i don't know what to do!

  • How do i erase my old apple id and create a new one with a new email address

    I forgot my phones Apple ID password and along with that forgot my password to my email account. I use my work email so thats why i dont really know the email i created for my phone. 
    So I created a new email and a new Apple ID online but when i put it the new Apple ID in my phone it says its incorect and shows my username as my old email that i had.  If that made any sense my entire question is how do i erase my old apple id on my phone and replace it with the new one i submittes online?

    Contact Apple, either through the link in that article or by phoning them. Alternatively, just create a new Apple ID; previous iTunes Store purchases won't be transferred to it.
    (79271)

  • If I delete my blackberry ID and create a new one with the same email will I still be able to get my old bbm contacts?

    Hi so I forgot my bbid password and answer to security question so Im stuck now..please RIM really this is poor that you dont have a sytem to reset it without those two things I see hundreds of posts all over google with people with this problem so if there is a way let me know but as you can see in the subject that's my question if it's not possible to reset it without security queston answer
    Regards
    Garry

    It is my understanding that if you delete the account per the instructions below, you will be able recreate, but you will NOT have access to the prior BBM contacts.
    Read this for full information and suggestions to regain access to your BBID >> http://supportforums.blackberry.com/t5/BlackBerry-World/How-to-regain-access-to-your-BBID/td-p/25467...
    You have to remember either the BlackBerryID password, or the secret question answer. Without either, you're stuck.
    Your choices are:
    --Use another email account to create an entirely new BlackBerryID (with which you will lose access to any purchased apps using the "forgotten" first BlackBerryID, or
    --Find the initial email you were sent to confirm the initial BlackBerryID, and in it is a link to click to cancel and delete the account. Click on that, delete the account and then you can use that same email to create an entirely new account.
    Good luck.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I just tried the 'group tabs' function but when I close a window and open a new one, the last page I viewed opens every single time. I can't remove or ignore the group tabs function and it automatically opens with it. How can I stop this?

    Before I attempted using the 'groups tab' function for the first time, there was no icon (unlike currently). There is now the icon with for the function yet I am unable to remove it or its function.

    Try a clean reinstall and delete the Firefox program folder and desktop shortcut before (re)installing a fresh copy of the current Firefox release.
    Download a fresh Firefox copy and save the file to the desktop.
    *Firefox 23.0: http://www.mozilla.org/en-US/firefox/all.html
    Uninstall your current Firefox version, if possible, to cleanup the Windows registry and settings in security software.
    *Do NOT remove personal data when you uninstall your current Firefox version, because all profile folders will be removed and you lose personal data like bookmarks and passwords from profiles of other Firefox versions.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    *(32 bit Windows) "C:\Program Files\Mozilla Firefox\"
    *(64 bit Windows) "C:\Program Files (x86)\Mozilla Firefox\"
    *It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    *http://kb.mozillazine.org/Uninstalling_Firefox
    Your bookmarks and other personal data are stored in the Firefox profile folder and won't be affected by an uninstall and (re)install, but make sure that "remove personal data" is NOT selected when you uninstall Firefox.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/Profile_backup
    *http://kb.mozillazine.org/Standard_diagnostic_-_Firefox#Clean_reinstall

  • Deleting Old Outlook E-mail Address and Adding a New One

    I am using an SMT5800 and have recently moved. In my previous location, my phone was synced to my workplace Outlook E-mail address. Since moving, I have tried repeatedly to update my Outlook E-mail settings to match my new workplace. Unfortunately, when attempting to change the Outlook settings, the phone does not allow me to remove my old username. Since the phone also does not allow me to simply delete the old Outlook address and simply start over, I remain unable to Active Sync with my current place of employment. How might I go about rectifying this?

    Dareru76 wrote:
    I am using an SMT5800 and have recently moved. In my previous location, my phone was synced to my workplace Outlook E-mail address. Since moving, I have tried repeatedly to update my Outlook E-mail settings to match my new workplace. Unfortunately, when attempting to change the Outlook settings, the phone does not allow me to remove my old username. Since the phone also does not allow me to simply delete the old Outlook address and simply start over, I remain unable to Active Sync with my current place of employment. How might I go about rectifying this?
    I assume you were using MS Exchange for your work. If you can not delete the old account then you do have a problem. This should not be an issue. First back up your phone, Contacts, Settings etc using a backup program like PPCPIMbackup(free) or SPB backup or equivalent. For this message I used PPCpim Backup and backed up all my data to my storage card. Next start ACTIVESYNC on the phone, click MENU>OPTIONS and delete the Exchange account there. Then establish a account with your new workplace. Once the account is established Start PPCPIM backup and restore just the info you want, i.e. contacts etc. That should work.

  • Deleted Pricing Cond rec in MEK2 and added a new one, now no pricing in PO!

    Hello,
      we had a bad pricing Condition record for Stock Transport Order PO's that had to be deleted and we needed to add a new pricing condition record.
    We used MEK2 to delete the bad record (Purch. Info Rec Category was equal to a "space"), and then add a new pricing condition rec. with a "0" (Standard) in the Purch. Info Rec Category and a correct monetary amount.  Then saved.
    Now when we create a PO for the material we corrected the pricing condition rec, we get NO PRICING! 
    Even if I go into MEK1 to just add the new condition record and set the start date back further in the past and save ... nothing comes through on the PO for the material in question.
    Is there something wrong with Deleting Pricing Condition Records?  I can not find a note on this.  I can see the old deleted condition record in the KONP table and the new condition record, but the PO create program is not picking up the new condition record no matter what we do.
    Any one have a situation like this before?
    Scott.

    I did check the analysis before, but I took a closer look and the "Material Info Rec (Plant-Specific)" access was not defined.
    The problem is that on the Material info record, we did not have the info record extended to the plant, just the Purchase Org.
    Thanks.

  • HT1373 once i deactivated all 5 computers ,and authorized my new one, how do i see my music

    once i deactived all 5 of my computers and added my new one, how do i see my music that i have purchased

    Select the store on the left side of iTunes.
    Click on Purchased on the right side under Quick Links.
    You can re-download your available previous purchases.
    Hopefully those apply to iTunes for Windows too, but since you posted in the iTunes for Mac forum that's what you get.

  • HT5621 I recently changed my Apple ID but my cloud backup keeps asking for password to my old Apple ID.  If I go in and delete my cloud account and create a new one will I lose everything or does the cloud follow my new ID when I set it up?

    I recently changed my Apple ID but I keep getting messages from my Cloud account asking for my password to my old Apple ID.  If I go in and delete the current Cloud account that appears to still be associated with my old ID and set up new one with my current ID will I lose all the stuff in the Cloud?

    Did you just change the address or did you create a new Apple ID.

  • How do you delete an iCloud account on a Mac and create a new one?

    How do you delete an iCloud account on a Mac and create a new one with a totally new iCloud email address and ID??

    You can cannot delete an AppleID, you just sign out of all services, stop using it,  and start over with a new AppleID.  If your ID is an iCloud ID it cannot be changed, see this link.
    :  Apple ID: Changing your Apple ID
    To if you want to start over with a new AppleID, see this link to update all services:   Update the features and services

  • How do i shut down an old network and create a new one

    I have a network that requires a password.  I changed the password, but people who were previously signed in can still access the network.  How can I shut down the network and start a new one with a new password?

    Change both the name of the wireless network and the password
    Make sure that you are using WPA2 Security
    If you give the password to anyone, you should assume that they will give it to someone else.

  • If i cancel an account can I create a new one with the same e-mail address?

    I made an account with Game Center and I wanted to use it to get some free apps on the iTunes Store. When I tried to sign in on iTunes (for Windows) it said I had to review my details. I didn't have a credit card so I couldn't complete it and there wasn't any option for no credit card.
    I wondered if I could cancel my account and create a new one with the same e-mail address. There was a discussion that you could create a new account on the iTunes Store and have the choice to not have a credit card.
    Any help will help!
    SuperHoops

    No, it does not, not if the creation of the Apple ID was completed, which unless you are referring to a different Apple ID I presume it did since you are posting here. And once created, you can't get apps without providing a payment method; setting up for just free apps requires a very specific procedure or a payment method is necessary. Creating an account via Game Center does not work.
    If you can create a new email address (Gmail or Yahoo mail will work), take a look here:
    http://support.apple.com/kb/HT2534
    Read the steps carefully as the order in which you follow them is critical. Note that you can do this only when creating a new Apple ID. You cannot use an existing ID. 
    You will of course not be able to get anything other than the free apps without entering in some sort of payment method (credit card, prepaid iTunes card, gift certificate, etc.)
    Regards.

Maybe you are looking for

  • WILL NOT SYNC WITH oUTLOOK 2003 (CALANDER)

    I updated my Palm software as suggested on this blog and now my Zire 72S will not sync all my calander. Some (not many) appts get on. I see an error  Outlook Calendar synchronization aborted  Duration: 868.7 seconds  Outlook Calendar  OLERR:05-000D  

  • What should the"default behavior" be for WiFi network connections?

    I Have been able to at least temporarily fix the plethora of problems encountered after downloading Mountain Lion to my 2009 17" MBP just ten days ago.  Thanks to the time and effort of so many posters that are much more savvy than me, I successfully

  • Why does "Insert MathType Equation" not work in new Pages for Mac?

    Command opens MathType (6.7e).  After typing an equation, pressing Command-W closes the MathType window and returns to Pages.  (Instructions given here: http://help.apple.com/pages/mac/5.0/#/tan0e6bf8310  indicate that I should have to answer "Yes" t

  • Backup disc too small?

    I recently purchased a new MacBook Pro and used a Time Machine backup to transfer all the files from my old MacBook Pro to the new one. Now, I am trying to set up Time Machine on the new laptop with the same external hard drive I was using a Time Mac

  • Calling c program from oracle

    Hi i have a c program in SOlaris box..how to call it frm PLSQL and return a value from tht..can any one guide me..its urgent?????????