Changing JPanel with button click.

Hi, I have a class call TOC(Table of Content) which contains all the buttons. One class call MainController. All buttons I add an actionListener which the MainController class will handle. Anothe class which is the main one which contain a JPanel.
When I click on the button in TOC class, it will go through the MainController class and display the respective JPanel associate with the button.
Now the problem is how do I change the JPanel in the main class with a click on the button in TOC class?
Please advise. Thanks in advance.

Not sure what you mean exactly. However,
Assuming that your view class is a JPanel, when you create your controller,
ViewPanel view = new ViewPanel();
MainController controller = new MainController(viewPanel);
In MainController track a reference to your viewPanel. Also in viewPanel have a method called setCurrentPanel(JPanel panel). then int he controller's action listener
public void actionPerformed(ActionEvent ev) {
JPanel pnl = (JPanel) panelMap.get(ev.getSource().getName());
viewPanel.setCurrentPanel(pnl);
I am assuming you have a way of mapping each button to the panel it will use, which is what is in the panelMap. The viewPanel can have a CardPanel layout for the panels it displays and its setCurrentPanel, can bring to front/oradd the specified panel.
Good luck, hope this helps :-)

Similar Messages

  • Multiple flash files change when a button click using javascript function

    hi.. am new in flsh...
    i want to multiple flash files change when a button click using a javascript

    <script>
    var count=0;
    function mafunct(newSrc){
        alert("hi");
    var path="a"+count+".swf"; 
    flash+='<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="100%" HEIGHT="100%">';         
        flash+='<PARAM NAME=movie VALUE="'+path+'">';         
        flash+='<PARAM NAME="PLAY" VALUE="false">'; 
        flash+='<PARAM NAME="LOOP" VALUE="false">';
        flash+='<PARAM NAME="QUALITY" VALUE="high">';
        flash+='<PARAM NAME="SCALE" VALUE="SHOWALL">';
        flash+='<EMBED NAME="testmovie" SRC="Menu.swf" WIDTH="100%" HEIGHT="100%"PLAY="false" LOOP="false" QUALITY="high" SCALE="SHOWALL"swLiveConnect="true"PLUGINSPAGE="http://www.macromedia.com/go/flashplayer/">';
        flash+='</EMBED>';
        flash+='</OBJECT>';    
    count++;
    alert(path+"aa");
    </script>
    <button onclick="mafunct()">next</button>

  • Loading movie clip to stage with button click AS3

    I'm trying to figure out how to load a movie clip to the stage with a button click and have the movieclip close again using a close button. Does anyone have a step by step on how to do this or links to some tutorials.
    Below is an example of what I'm trying to do.

    Alrighty I changed the publish settings to as3. I'm still getting two errors:
    Scene 1
    1046: Type was not found or was not a compile-time constant: Popup1Btn.
    Scene 1, Layer 'as', Frame 1, Line 3
    1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
    So my setup on my main timeline is I have an actionscript layer with this code now:
    var popup1:Popup1
    Popup1Btn.addEventListener(MouseEvent.CLICK,addF);
    ClosePopup1.addEventListener(MouseEvent.CLICK,closeF);
    function addF(e:MouseEvent):void{
    popup1=new Popup1();
    addChild(popup1);
    function closeF(e:MouseEvent):void{
    removeChild(popup1);
    popup1=null;
    On the stage I have a button with the isntance/AS linkage name Popup1Btn. Inside my Popup1 MC I have a box with text and then a button with the instance/linkage name ClosePopup1 to close the popup.
    What am I missing?

  • Change skin on button click

    Basically I wanted to plant a toggle button to increase and decrease the size of the text my spaces. So, I created a new skin with large font size.
    How do I change the skin with a click of a single button?

    use something like this:
    <af:selectOneChoice label="Choose Skin:" value="#{sessionScope.skinFamily}" autoSubmit="true">
        <af:selectItem value="blafplus-rich" label="blafplus-rich"/>
        <af:selectItem value="blafplus-medium" label="blafplus-medium"/>
        <af:selectItem value="simple" label="simple"/>
    </af:selectOneChoice>The value of each selectItem is an existing skin. If you add your own skins, you just add them as selectItem.
    In trinidad-confix.xml you will also have to refer to the skin family:
    <skin-family>#{sessionScope.skinFamily}</skin-family>This way the skin is dynamicly.
    So if you don't want to use a selectOnChoice but a button than you will need to write an actionListener for that button. In that listener, you write the new value into the session variable.
    Edited by: Yannick Ongena on May 20, 2011 7:00 AM

  • Updating JPanel with buttons from a different class

    I have a JPanel in a class that has a gridlayout with buttons in it for a game board. And my problem is that when I want to update a button using setIcon() the button doesn't change in the GUI because the buttons are in a different class. The JPanel is in a Client class and the buttons are in a GamePlugin class. I've tried a bunch of different things but none of them worked or it was way too slow. I'm sure theres an easy way to do it that I'm not seeing. Any suggestions? Heres part of my code for updating the GUI.
    private JPanel boardPanel = new JPanel(); 
    Container cP = getContentPane();
    cP.add(boardPanel, BorderLayout.WEST);
    boardPanel.setPreferredSize(new Dimension(400, 400));
    boardPanel.setLayout(new GridLayout(8, 8));
    cP.add(optionsPanel, BorderLayout.CENTER);
          * Gets the board panel from the selected plugin.
         public void drawGameBoard(GamePlugin plugin) {
              board = (OthelloPlugin)plugin;
              boardPanel = board.getBoardPanel();
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++)
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        board.boardButtons[i][j].setActionCommand("" + i + "" + j);
                        board.boardButtons[i][j].addActionListener(this);
          * This method takes a GameBoard and uses it to update this class' data
          * and GUI representation of the board.
         public void updateBoard(GamePlugin updatedBoard) {
              board = (OthelloPlugin)updatedBoard;
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++) {
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        int cell = board.getCell(i,j);
                        if (cell == OthelloPlugin.PLAYER1){
                             board.boardButtons[i][j].setIcon(black);
                        else if (cell == OthelloPlugin.PLAYER2)
                             board.boardButtons[i][j].setIcon(white);
                        else
                             board.boardButtons[i][j].setText("");
         }

    txp200:
    I agree that a call to validate() , possibly repaint(), should fix your problem. In the class with the panel that the buttons are on, i would create a static repaint method that call panel.repaint(). You can then call that method in your other class. Just make sure u only use methods to change the properties of the button, never make a make a new one, as then you will lose the association with the panel. Hope this helps.
    -- Brady E

  • Changing activ tab with button click

    Hello,
    I have a tabstrip with several tabs. On Tab2 I have a list of invoices. If the user clicks on the copy button I want to copy several fields into a form on tab1. That is working well. I also want to change the activ tab from Tab2 to Tab1 so that the user is facing the formular but I do not know how to do it.
    regards
    stefan

    Hi Stefan,
    There is property for TabStrip UI element "selectedTab" (http://help.sap.com/saphelp_nw2004s/helpdata/en/f0/e5a8411fdbcc46e10000000a155106/frameset.htm). Bind it to context attibute and change in action handler accordingly.
    Best regards, Maksim Rashchynski.

  • Changing depths of movie clips with button clicks

    Hello all,
    I've got a file on working on that has 4 different movie clips on one layer that, when clicked, will zoom in (made with tweens in the timeline).
    The issue I'm having, is that when I click one of them, they are arranged in a way that won't work for what I need. I click one, and it works, but it is hidden by the movie clip that is on top of it in the heirarchy. Click another, zooms in, but is partially hidden by another one.
    My question is: Is there anyway in AS2 to code these so that when one is clicked, it will the top spot in the heriarchy? So that I can code them all like this so that whenever one is clicked, it goes to the top so it is not hidden?
    Thanks

    Correct me if I'm wrong, but isn't that just used to swap 2 movie clips?
    Or is there a number I can input instead of the movie clip name that will change all of them?

  • Opening a frame with button click

    hi all
    when i am going to click a button which is placed in JTabel it should
    open a JFrame with some component.
    thanks & regards
    daya

    This task can be decomposed in two logically unrelated subtasks:
    1: Adding a button in a table column and listening to it
    2: Showing a frame from some method
    In case you are hesitant how to solve the first task: you need to create your own cell editor (possibly by extending DefaultCellEditor) that returns a button as editor component. Of course this editor must be set to the desired column(that must be editable too). And just listen to that button's actions.
    Another possible solution is to just render the column with a button and listen the table for mouse clicks, then determine the ros/column for the click and act correspondingly.
    The solution of the second task depends entirely on you.
    HTH
    Mike

  • Play Audio On Webpage With Button Click

    Hello everyone. I'm new to Flash, so please bear with me.
    I'm creating a language learning website, and wish to add
    audio to it for all vocabulary words. I want the audio to be
    compatible across browsers and simply play when a button is
    clicked, without any controls or media players opening up.
    From what I hear, it sounds like Flash is a good way to go
    and would do the trick. It's just a matter of converting all the
    mp3s to Flash. The mp3 file size is already relatively small (1-2
    seconds in length each and about 30kb in size I believe).
    How could I create a button that plays the mp3 when it is
    clicked? I was
    researching the topic and came across a few things.
    What I am looking for is almost identical to this:
    Site
    demonstrating audio buttons
    While I could jump right in and use her example, it doesn't
    quite work. With hers, everything needs to be in different folders,
    and I would need a different button - her's is a little big. I
    can't put everything in different folders, because I will have
    hundreds of audio files. It would be much easier to put them all in
    an audio folder with different filenames.
    I also was reading at another site that it deals with
    Javascript controlling the Flash - when you click the button it
    plays the swf file. Since I am very new to Flash, I'm not exactly
    sure of what all it can and cannot do. The site also mentioned not
    all browsers allow Javascript to control Flash files. Again,
    however, I'm unsure of how accurate the information still remains.
    The browsers were older versions, and they were talking about how
    to do it in Flash 5 and Dreamweaver 4. Furthermore, the example
    located at the above link does not use any Javascript.
    Does anyone have any ideas on how I can do this? While I am
    beginning to learn Flash, I doubt I will understand what to do all
    on my own for a while, and I need to get the site finished as soon
    as possible. The audio is practically all that is left before the
    site launch. Like I said, I'm looking for a way to add audio to a
    webpage, that is played (without media players opening up, etc)
    with the push of a button, and also will load quickly, since there
    were be about 20 audio files per page.

    Here is some info on sound linkage, not sure if this is what
    you want but its a start:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=194&threadid =1208568

  • "Quit LV" creates exception - How can i exit created application with button-click?

    Hello,
    i added a small vi-popup at beginning of my program where user can select between 3 buttons. The fourth button is Exit that should exit the application.
    For this i added the "Quit Labview" = True.
    It works fine in developer-mode but when i run it in the application exe-file this creates the following exception:
    Why is this not working in a application?
    Is there a better thing to quit the program?
    Thx

    The problem is that this is sub-vi Nr 2 of 10 that are all connected in a row with the error in/out.
    That means i would have to put the other 8 sub-vis inside a case-structure and give the "close"-vi an output to feed the case.
    It is simpler to just kill the whole LV.
    #Date: Di, 9. Sep 2014 19:08:43
    #OSName: Windows 7 Ultimate Service Pack 1
    #OSVers: 6.1
    #OSBuild: 7601
    #AppName: XXXXX
    #Version: 13.0.1 32-bit
    #AppKind: AppLib
    #AppModDate: 09/09/2014 16:53 GMT
    #LabVIEW Base Address: 0x30000000
    starting LabVIEW Execution System 2 Thread 0 , capacity: 24 at [3493127323,39019060, (19:08:43,390190602 2014:09:09)]
    starting LabVIEW Execution System 2 Thread 1 , capacity: 24 at [3493127323,39019060, (19:08:43,390190602 2014:09:09)]
    starting LabVIEW Execution System 2 Thread 2 , capacity: 24 at [3493127323,39019060, (19:08:43,390190602 2014:09:09)]
    starting LabVIEW Execution System 2 Thread 3 , capacity: 24 at [3493127323,39019060, (19:08:43,390190602 2014:09:09)]
    <DEBUG_OUTPUT>
    09.09.2014 19:08:44.496
    Crash 0x00000000: Crash caught by NIER
    File Unknown(0) : Crash 0x00000000: Crash caught by NIER
    minidump id: 02df131c-8b0b-4227-860a-d1f27df161c8
    ExceptionCode: 0xC0000005
    </DEBUG_OUTPUT>
    0x30761D96 - lvrt <unknown> + 0
    0x3076211C - lvrt <unknown> + 0
    0x7C37FDB4 - MSVCR71 <unknown> + 0
    0x75A40303 - kernel32 <unknown> + 0
    0x77E174FF - ntdll <unknown> + 0
    0x77DD9F45 - ntdll <unknown> + 0
    0x00000000 - <unknown> <unknown> + 0

  • Java Swing Change background with button

    change the backgroung by press ing a swing buton and windowhandlers
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class backgrframe extends JFrame{
         class windowHandler extends WindowAdapter {
              public void windowClosing(WindowEvent e){
                   System.exit(0);
         class buttonHandler implements ActionListener {
              public void actionPerformed(ActionEvent e){
              String s = e.getActionCommand();
              System.out.println("S : " +s );
                   if( s.equals("Red") )
                        getContentPane().setBackground(Color.red);
                   else if( s.equals("Green") )
                        getContentPane().setBackground(Color.green);
                   else if( s.equals("Blue") )
                        getContentPane().setBackground(Color.blue);
              backgrframe(){
                   super("Background Frame");
                   setSize(400,300);
                   getContentPane().setBackground(Color.red);
                   getContentPane().setLayout( new FlowLayout() );
                   JButton red = new JButton ("Red");
                   JButton green = new JButton ("Green");
                   JButton blue = new JButton ("Blue");
                   buttonHandler bh = new buttonHandler ();
                   red.addActionListener(bh);
                   green.addActionListener(bh);
                   blue.addActionListener(bh);
                   windowHandler wh = new windowHandler ();
                   addWindowListener(wh);
                   getContentPane().add(red);
                   getContentPane().add(green);
                   getContentPane().add(blue);
                   setVisible(true);
         public static void main(String args[]){
                   new backgrframe();

    I could be wrong here but don't you have to set the actioncommand for each button?
    eg red.setActionCommand("Red") etc

  • Download pdf with button click??

    hi again guys,
    i have a pdf in my public_html and a button on my site that links to a PDF but when i click the button it opens the PDF in a browser window,
    is there a way to  save directly to the desktop?
    without opening in a browser window or zipping the file?
    thanks Mr A

    I believe you'll need to use the FileReference class, and its download method.

  • Change tabs with buttons

    Hi Everyone
    I have 5 tabs:
    tab1 = user tab (which will contain 4 buttons: button 1, button2, button3, button4)
    When button 1 is pressed tab 2 screen is user interface
    When button 2 is pressed tab 3 screen is user interface
    When button 3 is pressed tab 4 screen is user interface
    When button 4 is pressed tab 5 screen is user interface
    I tried to do this using Boolean buttons so when the button is pressed it will change to the correct page is there a better way to do this?
    Ailish

    I use this method quite a bit, within a state machine, attached is a basic example..
    Cheers
    Attachments:
    StandardStateMachine_UserTabs.zip ‏13 KB

  • Change color with mouse click

    I have a textfield that has a red background color. How do i make it white by just clicking the textfield?

    See
    Component.setBackground
    MouseListener / MouseAdapter
    java.awt.Color

  • How to generate random objects with a click?

    Hi Guys,
    I am new to the forum so hello to you all!
    I start here with a question that doesn't leave me sleeping during the night.
    I am working on a interactive slideshow.
    That's all right, ultil now.
    Now things becomes blurry for me.
    In every page I would like to add a little animal in the lower right angle of the screen so, when u click on this animal, a baloon appears with a wroten sentence inside it.
    But, I wanto to make the sentences inside the baloon RANDOMLY different every time u click on the animal (using a selection, for example, of 30 sentences at all), but I don't really know what I have to do in order to realize my idea.
    I am not interested to create a preset cycle of sentences, but a random behavior with a click.
    any suggestion please?
    Thaks a lot and best regards!
    Theus

    As I imagined,
    I got some problems to do do that because I am new to the director use. So I can't made it working, if u cant be a little patient with me please, that's will be good!
    What I need is a more "steb by step" help if is not boring for you.
    I go to insert>control>field in order to create a field and then, after double ciking the field, I type four example sentences into the text editor that apperars, right?
    How I have to write the sentences inside the text editor in order to subdivide the text into first sentence, second sentences and so on? There is a special syntax to follow?
    I wrote these exaple sentences:
    "Triangle" "Square" "Circle" "Cube"..... As u see, I am not sure where and how I have to put the sentences in order to select them randomy
    About handlers.
    What I have to do to create an event handler?
    I created a button then i rename it ChooseRandomSentence but now I don't know what I need to do to proceed.
    Here have I to write this script?
    On ChooseRandomSentence
      global gSentenceList, gPreviousNR
      x = gSentenceList.count -- X = count sentences
      y =  random(x) -- Picks a random number from X
      repeat While y  =  gPreviousNR then -- check if number is used previous time player clicked button
          y =  random(x)
       end repeat
      put gSentenceList[y] into field "ShowSentence"  -- Shows random sentence in a field
      put y into gPreviousNR -- add number to next check
    end
    and this?
    on MouseUP
    ChooseRandomSentence
    end
    Some other questions:
    -What about letters X and Y into the exaples scripts u wrote? If I have 4 sentences, which numbers I need to use to replace X and Y?
    -I need to change sentences with  mouse clicking, and not simply moving the mouse over the sprite or the button, is MouseUP command a script about clicking or about moving over?
    As u see I am a very very beginner but I really want to learn, so hope I don't boring u with all those questions.
    Thanks again a lot
    and, If u came in Italy, there is a beer for you! cheers!!!
    Theus

Maybe you are looking for

  • How to install easyIO on Mac OS X (10.2.8)?

    Hi, I began using MRJ SDK yesterday, but i cant get the compiler Javac to simply find the package easyIO, which iin the source file was imported by following command: import easyIO.*; What should i do?

  • Duplex printing switches to single page at a certain point in pdf file

    Hi everyone, I have combined about ten separate pdf files into one complete pdf file for a client. The problem is that when they print the file using duplex printing, they're saying that at a particular point in the document it switches to single pag

  • Songs coming up with an ' ! ' when I load i tunes.

    I have noticed recently that when I load my i tunes some songs from a specific album cone up with an ' ! ' and cannot be played. I need to find them on the hard drive and download them to i tunes again. Any advice as to why this is happening and how

  • Mail mail and attachments

    Hi, I have this issue, when I receive some email with attachments they are not displayed in mail, it's not all attachments though, some are displayed in the message body and some just work. The only way I have found to see the attachment is to go to

  • Jsp plugin for eclipse3.2

    Hi , can anyone ll give the link for jsp plugin for eclipse3.2 as i used with the 3.0 plugin it's not working. thank u in advance