Re: have two panels, when button is pressed want second panel to show.

Please help:
I working with a very simple applet program.
All I want to do is when I click a button a new panel shows up and the earlier one disappers. Like you see
when you fill up online forms.
I am doing this with JPanels with setvisible true/false.
The program should work but when I click on the button the second panel deos not show up.
Please tell me what I am doing wrong...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
<applet code = "PanelTest.class" width=500 height=250>
</applet>
public class PanelTest extends JApplet {
Container cnt;
JPanel jpanel1, jpanel2;
JPanel mainjpanel;
public void init()
cnt = getContentPane();
mainjpanel = new JPanel();
cnt.add(mainjpanel);
jpanel1 = new JPanel();
JButton jbutton1 = new JButton("Account information");
jpanel1.setVisible(true);
jpanel1.add(jbutton1);
mainjpanel.add(jpanel1);
ButtonAction ba = new ButtonAction();
jbutton1.addActionListener(ba);
jpanel2 = new JPanel();
JButton jbutton2 = new JButton("Save");
jpanel2.setVisible(false);
jpanel2.add(jbutton2);
mainjpanel.add(jpanel2);
class ButtonAction implements ActionListener
{ public void actionPerformed(ActionEvent ae)
{ String name = ((JButton)ae.getSource()).getText();
if (name.equals("Account information"))
jpanel1.setVisible(false);
jpanel2.setVisible(true);
}

Hi,
here is a link http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html
with an example of using CardLayout and managing more than one component in an applet.
Hope it helps
regards

Similar Messages

  • I've upgraded my pc and now Im getting an error message when Im trying to sync my ipod saying I have two itunes libraries. The library thats there is only showing some songs and it's not uploading songs Ive just bought.

    I've upgraded my pc and now Im getting an error message when Im trying to sync my ipod saying I have two itunes libraries. The library thats there is only showing some songs and it's not uploading songs Ive just bought.

    You seem to have tried everything, and you say it's syncing fine on your Dad's iMac, so I assume, you have also  done a Disk Diagnostic from an earlier post by tt2 and conclude that your iPod Hardisk is good.
    You don't have to use it as a heavy paperweight, the problem is only using your Windows 7 machine for syncing.
    In your troubleshooting steps, did you try to use another High-Speed USB 2.0 port, USB controller resource are very scarce, so if you use other USB devices, while syncing your iPod, it may just freeze.
    Windows have a bad reputation for device conflict, so better don't connect other  USB devices, while syncing, better sync it while disconnected from Internet, stop antivirus just before you go to bed.
    Have a nice day!

  • I have two problems when install 9iR2 in the RH9.

    Hi, everyone:
    I have two problems when install 9iR2 in the RH9.
    1. I am going to 9iR2 in RH9 that the default character set is Chinese, so how I should set the environment variable NLS_LANG?
    2. When I set the default character set is English, after I run the "runInstaller", in the terminal will display some error messages:
    Warning: cannot convert string "<key>Escape,_Key_Cancel" to type VirtualBinding
    Warning: cannot convert string "<key>Home,_Key_Begin" to type VirtualBinding
    Warning: cannot convert string "<key>F1,_Key_Help" to type VirtualBinding
    Warning:cannot convert string "Shift<key>F10,_Key_Menu" to type VirtualBinding
    Warning:cannot convert string "<key>F10,Shift_Key_Menu" to type VirtualBinding
    Warning:cannot convert string "<key>KP_Enter,_Key_Execute" to type VirtualBinding
    Warning:cannot convert string "<key>Return,Alt_Key_KP_Enter" to type VirtualBinding
    How should I correct.
    Thanks a lot!

    Problem #2 is not a problem. We have been able to somewhat install Oracle when those warnings appear. The client install works fine with those warning messages in the terminal window. NOTE: They are just warnings...

  • I create a project w/iMovie and I have two problems:  When I try to finalize the project iMovie crashes; when I share to DVD sometimes it crashes also; if I can successfully send it to DVD and then burn a DVD there are wavy lines on the screen.  Help!

    I create a project w/iMovie and I have two problems:  When I try to finalize the project iMovie crashes; when I share to DVD sometimes it crashes also; if I can successfully send it to DVD and then burn a DVD there are wavy lines on the screen.  I'm uising photos in my project, not video.  Help!

    You can split a project in two by doing this.
    1) Go to the Project Library View.
    2) Select your project, and click FILE/DUPLICATE PROJECT. Give it a name like "your project name - part 1".
    3) Do this again. This time name it "your project name - part 2"
    4) Open Part 1 for editing. Delete everything in the second half.
    5) Open Part 1 for editing. Delete everything in the first half of the project.
    At the end you should have your original project, plus the same project in two parts.

  • ICloud - have two iPads and one Macbook and want to sync reminders on all three

    iCloud - have two iPads and one Macbook and want to sync reminders on all three. I have managed to get the Macbook and one iPad to sync, but wjat about the other iPad?

    First check that all your settings are correct, that reminders syncing (calendars on a computer) is checked on all devices (system preferences > iCloud on a mac and settings > iCloud on a iPhone, iPad or iPod).
    Make sure the reminders you are adding are added to your 'iCloud' account and not an 'On My Mac', 'On My Phone'  or other non iCloud account (you can do this by checking in accounts on an iOS device by tapping the icon with three lines in the top left corner of the screen, or the right side panel by clicking on the small triangle to the right of the word 'Reminders' in iCal on a computer), non iCloud reminders will not sync.
    If you are sure that everything is set up correctly and your reminders are in the iCloud group, you might try unchecking reminders syncing (calendars syncing on a computer) in the iCloud settings, restarting your device and then re-enabling notes syncing.

  • I have two itunes accounts because I used a second email address by mistake as an id.  Can I merge them?

    I have two iTunes accounts because I used a second email id by mistake years ago and have lived with it ever since.  How can I merge them to access all my music in one place?

    no way yet.

  • HT1349 I have two Apple itunes accounts and I want to merge them in to one.

    I have two Apple itunes accounts and I want to merge them in to one.  How do I do this.

    You cannot merge Apple ID's. Copied from Apple's FAQ about Apple ID's.
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    If you are wondering how using multiple Apple IDs relate to iCloud, see Apple IDs and iCloud.
    http://support.apple.com/kb/HE37

  • Now that I have upgraded to Yosemite I have a problem when I scan documents.  Before, a window showed today's activity.  Now I have to search through all my documents and hope to find what I just scanned.

    Now that I have upgraded to Yosemite I have a problem when I scan documents.  Formerly, a window showed today's activity.  Now, I have to search through all the documents in my history to find what I just scanned.  Sometimes I can't even find the doc.

    Most scan apps have a setting whereas, your scan(s) can go directly to your desktop.  No need to "hunt" for scanned docs.

  • When trying to download yosemite it sais that i do not have enough memory. when i look at my memory use it shows that 111.00gb of space is used by movies but when i go th the movie folder it is empty. how can i remove the non existant movies.

    when trying to download yosemite it sais that i do not have enough memory. when i look at my memory use it shows that 111.00gb of space is used by movies but when i go th the movie folder it is empty. how can i remove the non existant movies.

    Freeing Up Space on The Hard Drive
      1. See Lion/Mountain Lion/Mavericks' Storage Display.
      2. You can remove data from your Home folder except for the /Home/Library/ folder.
      3. Visit The XLab FAQs and read the FAQ on freeing up space on your hard drive.
      4. Also see Freeing space on your Mac OS X startup disk.
      5. See Where did my Disk Space go?.
      6. See The Storage Display.
    You must Empty the Trash in order to recover the space they occupied on the hard drive.
    You should consider replacing the drive with a larger one. Check out OWC for drives, tutorials, and toolkits.
    Try using OmniDiskSweeper 1.8 or GrandPerspective to search your drive for large files and where they are located.
    You will need a minimum of 10-12 GBs of free space to install Yosemite, however, that is a bare minimum and should be at least twice that amount.

  • Have two different iTunes/app store accounts want to make then 1

    have two different iTunes/app store accounts want to make then 1

    Welcome to the Apple community Todc.
    Besides signing out of the account, you will need to delete the apps on the device that were purchased under that ID.

  • Frame layout changes when button is pressed again...

    Okay so basically I have a button on my frame and when it's pressed it opens up another frame. This is fine, but when the button is pressed again it opens up the frame again but the layout is all over the place.
    Here is the code:
    if (ev.getSource() == seating)
    else
                   seatdisplay = new JFrame("Seating Display");
                   seatdisplay.getContentPane().setBackground(Color.orange);
                   seatdisplay.setLayout(new BorderLayout()); //Define border layout
                   seatdisplay.setVisible(true);
                   seatdisplay.setSize(550,500);
                   seatdisplay.add(panelLeft, BorderLayout.WEST); //Position object to the west
                   seatdisplay.add(panelMiddle, BorderLayout.CENTER);
                   seatdisplay.add(panelRight, BorderLayout.EAST);
                   seatdisplay.add(panelTop, BorderLayout.NORTH);
                   seatdisplay.add(panelBottom, BorderLayout.SOUTH);
                   panelLeft.setLayout(new GridLayout(4,2)); //Define new grid layout
                   panelLeft.setBackground(Color.black);
                   panelLeft.add(a1 = new JButton("A1")); //Add buttons
                   panelLeft.add(a2 = new JButton("A2"));
                   panelLeft.add(a3 = new JButton("A3"));
                   panelLeft.add(a4 = new JButton("A4"));
                   panelLeft.add(a5 = new JButton("A5"));
                   panelLeft.add(a6 = new JButton("A6"));
                   panelLeft.add(a7 = new JButton("A7"));
                   panelLeft.add(a8 = new JButton("A8"));
                   panelMiddle.setLayout(new GridLayout(3,6));
                   panelMiddle.setBackground(Color.orange);
                   panelMiddle.add(empty = new JButton("")); empty.setVisible(false);
                   panelMiddle.add(b1 = new JButton("B1"));
                   panelMiddle.add(b2 = new JButton("B2"));
                   panelMiddle.add(b3 = new JButton("B3"));
                   panelMiddle.add(b4 = new JButton("B4"));
                   panelMiddle.add(empty3 = new JButton("")); empty3.setVisible(false);
                   panelMiddle.add(empty1 = new JButton("")); empty1.setVisible(false);
                   panelMiddle.add(b5 = new JButton("B5"));
                   panelMiddle.add(b6 = new JButton("B6"));
                   panelMiddle.add(b7 = new JButton("B7"));
                   panelMiddle.add(b8 = new JButton("B8"));
                   panelMiddle.add(empty4 = new JButton("")); empty4.setVisible(false);
                   panelMiddle.add(empty2 = new JButton("")); empty2.setVisible(false);
                   panelMiddle.add(b9 = new JButton("B9"));
                   panelMiddle.add(b10 = new JButton("B10"));
                   panelMiddle.add(b11 = new JButton("B11"));
                   panelMiddle.add(b12 = new JButton("B12"));
                   panelRight.setLayout(new GridLayout(4,2));
                   panelRight.setBackground(Color.black);
                   panelRight.add(c1 = new JButton("C1"));
                   panelRight.add(c2 = new JButton("C2"));
                   panelRight.add(c3 = new JButton("C3"));
                   panelRight.add(c4 = new JButton("C4"));
                   panelRight.add(c5 = new JButton("C5"));
                   panelRight.add(c6 = new JButton("C6"));
                   panelRight.add(c7 = new JButton("C7"));
                   panelRight.add(c8 = new JButton("C8"));
    }The seat button is pressed and seatdisplay frame is opened, however, if I press the seat button twice another seatdisplay frame is opened and the layout is all over the place. Do I need to do some sort of refresh?

    Swing related questions should be posted in the Swing forum.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Stop displaying a message when button is pressed more than one

    Hi
    I have a forms with button 'save' and when user pressed this button i do some checks and display a message, what i want is to display the message only the first time user presses the button, if user presses the button again and again, message should not be displayed...but i do not know how to fix this, has someone an idea? Thanks.

    Take a look at About Global Variables. You might also want to bookmark the Oracle Forms Documentation web site.
    Basically, you will use a Global Variable as a counter. In your button code, you check the value of the Global Var to see if it is greater than 1. If it is, you exit. If it is not (in other words the Global is equal to zero) then you add 1 to the variable and you display your message. Pretty basic stuff.
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • My question is why does firefox close when I click another window off? I have a new window come up so I have two, but when I click one off it closes all of them.

    I usually have more than one tabs up and ready when I'm searching the web. But when I look at my mail or when a new window is opened if I click the "X" all of my windows are closed. What could be the problem?

    This is not a cure but will make it easier if Firefox locks up.
    '''https://support.mozilla.org/questions/997866''' {web link}
    From what I have been reading from other posts on this forum, the
    issue may be caused by the clear history settings. It was suppose
    to have been fixed in v30.
    Press the '''Alt''' or '''F10''' key to bring up the tool bar.
    Followed by;
    Windows; '''Tools > Options'''
    Linux; '''Edit > Preferences'''
    Mac; ''application name'' '''> Preferences'''
    Then '''Privacy'''.
    The button next to '''History''', select '''Use Custom Settings'''.
    At the bottom of the page, turn on '''Clear History When Firefox Closes.'''
    At the far right, press the '''Settings''' button. Turn on ONLY '''Cache''' and
    '''Form And Search History''' leaving the others off.

  • I have two time capsules (1TB, 2TB) and want to use one for another set of Macs (my Family). How do I set both up and keep all the Macs from joining both Time Capsules?

    I Have two Time Capsules (1TB and 2TB) and want to set one for business and the other for family - networking seperate Macs to each.

    Both should be plugged into the network with ethernet.. if at all possible.
    If you have a router already then both bridged otherwise one set to router and one to bridge.
    How do you access the TC? Ethernet or wireless?
    Are they located in the same area?
    You could set different wireless networks.. if they use wireless.. this is nice easy way to do it.
    You can set user account in the TC you want the business one to join with.. that will prevent access by the family.
    So there is a number of ways.. none are particularly secure btw.. the TC is a home not a business device.. if anybody wants access they press the reset for one second.. pofff all the passwords are default for 5min.. to allow people who forget their password to get access.
    On ML you can encrypt TM backups.. this is better for security if that is the problem.. and still use different user profile to prevent access.

  • I have two iTunes accounts somehow, and just want to merge them together.

    If you have two iTunes accounts by accident (one iPhone and one Computer...) how can you merge them together into one account?

    The simple answer is that you cannot.  Try contacting the store support staff and see what they can do to help: http://www.apple.com/emea/support/itunes/contact.html

Maybe you are looking for