Presentation of the card: 2nd card doesn't show text in the TextField

I have a java swing application that implements the map layout and observer template. Basically, in the first map, I key in numbers in the button TextField and click on 'get number', it will run the Calculate class, which returns the number, which then informed his observer who is the Snd class. In the 2nd card (NDS class), it is supposed to set the number passed through the Observable (class Calculate) on the TextField. But my problem is that the textfield on the 2nd map does not appear any text. I already tried the getText method using the print method, and it returns the correct value for the observer last updated. It's just that TextField doesn't show anything. This is executable code.

CardWindow.java

import java.awt.CardLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class CardWindow {
  private JFrame f;
  private JPanel panel_2;
  private JPanel panel_1;
  private JButton btnNext, btnBack;
  Calculate watched;
  Snd watcher;


  /**
  * Launch the application.
  */
  public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
  public void run() {
  try {
  CardWindow window = new CardWindow();
  window.f.setVisible(true);
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  });
  }


  /**
  * Create the application.
  */
  public CardWindow() {
  initialize();
  }


  /**
  * Initialize the contents of the frame.
  */
  private void initialize() {
  f = new JFrame();
  f.setBounds(100, 100,500,300);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.getContentPane().setLayout(new CardLayout(0, 0));
  panel_1 = new Main_1();
  panel_2 = new Snd();
  f.getContentPane().add(panel_1);
  f.getContentPane().add(panel_2);
  panel_1.setVisible(true);
  panel_2.setVisible(false);
  btnNext = new JButton("Next");
  btnNext.setBounds(300, 100, 161, 29);
  panel_1.add(btnNext);
  btnNext.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent e) {
  panel_1.setVisible(false);
  panel_2.setVisible(true);
  System.out.println("Next card");
  }
  });
  btnBack = new JButton("Back");
  btnBack.setBounds(300, 100, 75, 29);
  panel_2.add(btnBack);
  btnBack.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent e) {
  panel_2.setVisible(false);
  panel_1.setVisible(true);
  System.out.println("Return previous");
  }
  });
  }
}



Main_1.Java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Main_1 extends JPanel {
  private static final long serialVersionUID = 1L;
  private JTextField textField;
  private JButton btnCalculate;
  Calculate watched;


  public Main_1() {
  System.out.println("View1()");

setLayout(new FlowLayout());

  textField = new JTextField();
  textField.setBounds(37, 80, 134, 28);
  add(textField);
  textField.setColumns(10);
  btnCalculate = new JButton("Get number");
  btnCalculate.setBounds(47, 131, 117, 29);
  add(btnCalculate);
  btnCalculate.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  watched = new Calculate();
  watched.calculate(textField.getText());
  }
  });
  }
}

Snd.Java

import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;

public class Snd extends JPanel implements Observer {

 private static final long serialVersionUID = 1L;
  JTextField textField2;
  private Calculate cal;
  private JLabel label;

  Snd() {
  System.out.println("View2()");

setLayout(new FlowLayout());


  textField2 = new JTextField();
  textField2.setBounds(85, 121, 134, 28);
  add(textField2);

  label = new JLabel();
  label.setBounds(129, 200, 61, 16);
  add(label);
  System.out.println("Testing");
  }

  public void update(Observable obs, Object obj) {
  System.out.println ("View      : Observable is " + obs.getClass() + ", object passed is " + obj.getClass());
  cal = (Calculate) obs;
  System.out.println("Update: " + cal.getNum() + " " + obj);
  textField2.setText(Integer.toString(cal.getNum()));
  System.out.println(textField2.isDisplayable());
  System.out.println(textField2.getText());
  label.setText(Integer.toString(cal.getNum()));
  }
}

Calculate.Java

import java.util.Observable;

public class Calculate extends Observable {
 private int abc;

  public Calculate () {
  System.out.println("Model()");
  }

  public void setValue(int num) {
  System.out.println("Initial value: " + abc);
  this.abc = num;
  setChanged();
  System.out.println("Initial notify observer");
  notifyObservers(abc);
  }

  public void calculate(String number) {
  Snd watcher = new Snd();
  addObserver(watcher);
  System.out.println("hasChanged: " + hasChanged());
  abc = Integer.valueOf(number);
  System.out.println("Number: " + abc);
  setChanged();
  System.out.println("hasChanged: " + hasChanged());
  notifyObservers(abc);
  System.out.println("Notify observer");
  }

  public int getNum() {
  return abc;
  }
}

It works for me:

public class CardLayoutTest {

     private static final String SECOND_PANEL = "secondPanel";
     private static final String FIRST_PANEL = "firstPanel";
     private static final CardLayout cardLayout = new CardLayout();

     public static void main(String[] args) {
          final JPanel mainPanel = new JPanel(cardLayout);

          JPanel firstPanel = new JPanel(new FlowLayout());
          JPanel secondPanel = new JPanel(new FlowLayout());

          mainPanel.add(firstPanel, FIRST_PANEL);
          mainPanel.add(secondPanel, SECOND_PANEL);

          final JTextField input = new JTextField(30);
          firstPanel.add(input);
          final JTextField output = new JTextField(30);
          secondPanel.add(output);
          Observer observer = new Observer() {

               @Override
               public void update(Observable o, Object arg) {
                    output.setText(String.format("got value from first panel %s", input.getText()));
               }
          };
          final Observable observable = new Observable(){

               @Override
               public void notifyObservers() {
                    setChanged();
                    super.notifyObservers();
               }

          };
          observable.addObserver(observer);

          firstPanel.add(new JButton(new AbstractAction("toSecondCard") {

               @Override
               public void actionPerformed(ActionEvent arg0) {
                    observable.notifyObservers();
                    cardLayout.show(mainPanel, SECOND_PANEL);
               }
          }));

          secondPanel.add(new JButton(new AbstractAction("back") {

               @Override
               public void actionPerformed(ActionEvent arg0) {
                    input.setText("");
                    cardLayout.show(mainPanel, FIRST_PANEL);
               }
          }));
          JOptionPane.showMessageDialog(null, mainPanel, "CardLayoutTest", JOptionPane.PLAIN_MESSAGE);

     }

}

Good bye

TT

Tags: Java

Similar Questions

  • I just purchased an annual membership, I presented my credit card information... clicket accept but I never had my license number, and there is nothing about my order in the history of my account... how much time does it take?

    I just purchased an annual membership, I presented my credit card information... clicket accept but I never had my license number, and there is nothing about my order in the history of my account... how much time does it take?

    Constanza,

    I see a subscription is active for you with the same adobe Id allows you to connect to this forum. Please, try to connect and creative cloud back in:

    log in and log out of the desktop Adobe Creative Cloud application

    If you still have any questions, do not hesitate to contact our support staff (be sure to connect to adobe.com with your Adobe ID first)

    CC_membership-account-payment-support

    Guinot

  • BlackBerry Smartphones Blackberry will honor my warranty if the account owner is not present in the store?

    I was 18 at the time of the purchase of my phone, so my father-in-law put the phone in his name at the time. Now I have problems with my blackberry, and he's not around more. So I'll need to take it in me, and I have the box, as well as the charger, cd tools user, the small manual books, my virgin mobile and conditions.

    I can't find the reception, but they would be able to look up from my account in order to check that it was purchased less than a year ago? In addition, the debit card used to pay the phone bill is mine and they can check that too if that helps.

    Then, the Blackberry will honor my warranty if the account owner is not present in the store?

    This ^^ above are true and all, I would say take the phone of your store, Virgin and the BlackBerry in hand, tell them what is wrong, etc., and they should simply check your account to see the unit on your account and probably will not plunge even in need of a reception, etc., as the device IS actually saved on YOUR Virgin mobile account right?

    Play dumb, not all volunteers 'too much information', unless specifically asked on a receipt (I doubt you will be). So yes, it's "my father-in-law bought for me as a gift, he's gone now and my BlackBerry does not work. What can you do? »

  • Wireless adapter is no longer present in the Device Manager

    Hello

    I have an Asus laptop 1015E (http://www.asus.com/us/Notebooks_Ultrabooks/1015E/#overview) running Windows 8.  I don't know when it happened, but the built-in wireless adapter is no longer present in the Device Manager.  I tried to use the Asus install app to reinstall the driver Asus Wireless Radio control, but it just says: it is already installed.  I also went to the site of asus via an ethernet connection and tried to download the latest drivers for wireless card, but installation cannot.  It seems as if the laptop detects most hardware, so I can't install driver software. Any ideas on how to proceed?
    Thank you

    Hi wolves.

    Do you receive an error message/code?

    When a device does not work, it's mostly because the driver has been corrupted.

    Here are some ways you can follow to resolve the problem:

    Method 1:

    Check out the link and follow the steps in the article:

    How can I troubleshoot network card?

    http://Windows.Microsoft.com/en-in/Windows-8/fix-network-adapter-problems#

    Method 2:

    You will need to install the Chipset Drivers first and later network adapter drivers.

    Reference:

    http://www.ASUS.com/us/supportonly/Drivers_For_Win8/#support_Download_36

    Method 3:

    Check the BIOS of the laptop to check that there isn't an option to toggle the map.

    Note: You can contact the manufacturer of the computer, if you are not comfortable access or make changes in the BIOS.

    Note: Changing the BIOS / semiconductor (CMOS) to complementary metal oxide settings can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the configuration of the BIOS/CMOS settings can be solved. Changes to settings are at your own risk.

    In addition, contact the OEM of your system and see if they can replace the adapter or run a test to make sure that the adapter is working properly.

    I hope this helps. If you have any other queries/issues related to Windows, write us and we will be happy to help you further.

  • Presentation of the action does not work during the Conference

    Hello world

    Here's the background
    -CUCM 10.5
    -Telepresence conductor XC4.1
    -Telepresence Server (VM) 4.2
    -Endpoint: MX300

    I have problem when sharing a presentation at the Conference meeting.
    It doesn't seem to work.
    However, the part of presentation works with success during a normal 2-way call

    I read an article by cisco,
    http://www.Cisco.com/c/dam/en/us/TD/docs/Telepresence/infrastructure/con...

    A field is related to the function of presentation,

    Allow the content
    (Available when the preference of Service has a type of telepresence MCU Conferencing Bridge)
    Whether or not, participants will be able to send video content, such as a presentation.

    Yes: one lane will be reserved on each cascade TelePresence MCU and TelePresence MCU primary specifically for content. Use this setting to enabled WebEx conferences.

    No: the participants will not be able to send content, regardless of the number of ports available on the MCU. Content can always be displayed, since some end points provide content in their main video channel.

    The default value is Yes.

    Need MCU allow sharing feature? or I missed something?

    Thanks in advance

    Sam

    Allow that content is available only when the conference bridge is an MCU and does not apply to a server of telepresence.  The only thing you need to do within the Orchestra, is ensure that "content quality" within the model of the Conference is not set to 'Off', see the top of pg 61 of the guide that you have linked to your post.  Also, make sure you have enabled on the SIP Trunk to driver in CUCM BFCP.

  • Theme 25 - items are not correctly displayed in the presentation of the grid

    Hi all

    APEX 4.2.5.00.08

    Oracle 11g Enterprise Edition

    I am new to 4.2. I created an application on 4.1 and exported 4.1 and imported to 4.2. I'm trying to view the forms as they were posted in 4.1. But I have problems with the presentation of the grid. The elements are the overlap between them and the regions is narrowed. I read a blog and he said to remove all the colspan which will then automatically display elements. I did, but it did not work. The form consists of several parts using a list of tabs on the page. Parts of the tab using the model 'Region without the buttons and titles' of the region. I tried to replace the template "no model", while he was a little better, it has not corrected the problem.

    I've migrated the application and objects in the db at the APEX. ORACLE.COM (it took a few hours) and I hope someone can resolve my problem until the site is upgraded to 5.0.

    Workspace: RGWORK

    Application: KIMBERLY (33925)

    Page: Vehicle details (13)

    Username: TESTER

    Password: test456

    The first screen will be a Update/View vehicles 1 choice menu

    Choose this option and a report with a single line id.

    Select this line and display page 13.

    You have Developer access but please keep me on what has been fixed. I don't want remedy you. I want to know what has been resolved as well.

    Please get back me to me as soon as POSSIBLE because the site is upgraded to 5.0 this Friday.

    Robert

    sect55 wrote:

    I am new to 4.2. I created an application on 4.1 and exported 4.1 and imported to 4.2. I'm trying to view the forms as they were posted in 4.1. But I have problems with the presentation of the grid. The elements are the overlap between them and the regions is narrowed.

    Why you want to switch to theme 25 instead of simply retain the theme that was used in 4.1?

    Go wrote:

    Robert,

    Look at your application. just a simple change.

    change:

    Region: Veh/equip Information

    Presentation of the grid:

    Start the new row: Yes

    That helps, but it's not the whole story, as it appears the layout is still affected by the problem described in the thread previous Theme 25 region without buttons and issuance of securities

    Applying the fix I suggested it (in 78449 application I created a copy to ensure that I was working with the initial problems) Gets the items on the same line, but I guess that's not the same as the original provision and it doesn't look very good.

    Basically, I would say either stick with the original theme or by switching to a 4.2 theme that still use the page layout based on a table (for example, 24 or 26). Theme 25 is difficult to work with and works best with presentations created especially for her from the start.

  • error message "cannot find your sd card, it can show abnormal."

    Hi ~

    I wanted to transfer my data from computer to droid but error message pop up, "cannot find your sd card, it can show abnormal" after l had clicked the button mount. So I cannot access to move my date for the droid here. I search in google and always found no right answer.

    I also checked in the system settings and space total is always available 14.83 GB. why it does not find the sd card that is alreay in the phone.

    Please let me know what to do. (My computer is MS xp professional 2002)

    If you get all your applications in the market so you don't have to check that the unknown sources box.  This setting is to be able to install an app that you don't get in the market.  If you want to look at your files on the SD card of your phone, you will need a file manager.  Personally, I like "Astro File Manager".  There are others available, but that's who I love.  If that does not answer your question please post again.  I think that I responded well.

  • I'm a language monitor, I use Adobe Presenter to work properly on both, English, Spanish and presentations with the same software?

    I'm a language monitor, I use Adobe Presenter to work properly on both, English, Spanish and presentations with the same software?

    It shouldn't be a problem. Ultimately, presenter doesn't care what language the audio content is in, he will give all the same. The only problem I could see because of problems would be the appearance of the player. There Spanish lables, but they show only on a computer with the operating system in Spanish. If you want the student to view the two Englishmen and a version in Spanish on the same computer, you may have two versions of the language.xml file where you have one that has the help of English labels in the 'fr' section and the other where it has Spanish labels in the section 'fr '. You would then share those files in and out of the folder located at, C:\Users\ {UserName} \AppData\Local\Adobe\Adobe Presenter\Themes, you must publish a presentation in English or Spanish.

  • No change in the presentation of the Tablet

    I am designing a site using sensitive design. I notice that the changes I made to the CSS for the presentation of the Tablet does nothing. But if I make a change in available Mobile changes his Mobile and tablet. Why is this?

    I just noticed it says / * Tablet Layout: 481px to 768px. Inherits the styles of: Mobile layout. */

    How can I configure it so it does not inherit the styles of Mobile? Is it still possible?

    That's how work layouts FluidGrid.  You build Mobile first b/c that's what everything comes. 2nd 3rd compressed build and office.

    Nancy O.

  • How can I show only music actually present on the iphone?

    I recently had to reformat completely in iPhone 6s. Now, the 'Music' application shows all the music on my laptop iTunes library: I just want to see music actually physically present on the iPhone. I don't want to see I have to listen to or download music. There is a way to do it, but I forgot where the toggle. Can anyone help?

    Start the music app and click the artists tab (the drop down menu) in the Center and go to only downloaded music > on.

  • Using firefox 14.0.1. Load a link using the right click and "Open link in new window", translates into a new window opens but doesn't show URL address bar...

    Using firefox 14.0.1. Load a link using the right click and "Open link in new window", translates into a new window opens but doesn't show URL address bar. However, if I click with the right button on a link and select "Open link in a new tab", the tab displays the URL in the address bar. If it works when a new tab it's not in a new window.

    The reset Firefox feature can solve a lot of problems in restaurant Firefox to its factory default condition while saving your vital information.
    Note: This will make you lose all the Extensions, open Web sites and preferences.

    To reset Firefox, perform the following steps:

    1. Go to Firefox > help > troubleshooting information.
    2. Click on the button 'Reset Firefox'.
    3. Firefox will close and reset. After Firefox is finished, it will display a window with the imported information. Click Finish.
    4. Firefox opens with all the default settings applied.

    Information can be found in the article Firefox Refresh - reset the settings and Add-ons .

    This solve your problems? Please report to us!

  • When I go to a secure site the usual security lock is not present at the bottom of the page

    I upgraded my browser Firefox 6.0.1 and now when I enter a secure site the security lock is no longer present at the bottom of the page.

    The status bar is gone and the 'blocking' with her, from Firefox 4.0. Safety information on a web page are shown by the Site identity button.

    The former lock could give users a false sense that a site is safe to not to provide information to the site and showed that there is a secure connection that does not guarantee that you are connected to the right server. The Site identity button is introduced in Firefox 3.0 to show more complete information of 'identity' for HTTPS web pages.

    https://support.Mozilla.com/en-us/KB/site+identity+button

    You can add a padlock in the address bar with the add-on locks- https://addons.mozilla.org/firefox/addon/padlock-icon

  • presentation of the homescreen - naming file has no

    Hello

    I found a problem in Apple Configurator 2.2 step-by-step

    (1) "edit Blueprints" by clicking the button of Blueprints

    (2) right click the master plan and choose "Edit-> presentation of the home screen. »

    (3) set up a few Apps and a dossier, rename this folder... can be of type "APPLE."

    4) click 'apply '.

    (5) try again step 2, you will see that the folder name is always the same.

    Someone at - he saw the same thing?

    iPad 2 Air, iOS 9.3.1 AC2.2

    Before Apple fix this problem, I found another way to do this.

    Use OS X Server and open the Profile Manager.

    Pick up an iPad and enrolled in OS X Server

    Create the "Home Screen Layout" parameter by setting in profile.

    Download this profile setting and using Apple Configurator 2.2 to install this profile to the Machine.

    This work!

  • Why the tool Alexa doesn't show "private"? (No ranking at all).

    Hello

    Since the last update of Alexa ranking tool doesn't show any ranking for any site. It shows constantly "private."

    I've tried everything recommended and checked all the settings but I can't find the problem.

    Kind regards
    Lizzi.

    It seems the policy of alexa rules changed. Thus, to solve the problem you must uninstall and reinstall again. When you reinstall, you will need to accept the policy of alexa (you will be redirected to http://www.alexa.com/toolbar/policy?v=status ).

    It seems that it is implemented like this since firefox 6.0

  • Bookmarks dropdown doesn't show the option "save all".

    I've upgraded to the new version 4.0 and have noted that it is a big eater of memory larger than ever! The annoying "creep" in memory has approached 700 +, requiring restarts regularly, but does not help even delete the contents of the bookmarks.

    The small up/down arrows does not work.

    I have not noticed any improvement in speed of consequence and certainly not a doubling!

    Can I download and install on top again?

    • "To bookmark all tabs" is no longer present in the bookmarks menu unless you open the bookmarks menu via the keyboard (Alt + B).
    • "To bookmark all tabs" are available through the context menu of a tab on the tab bar.

    See also:

    You can consult:

    You can also make these changes via code in userChrome.css, but you'll have to give more details on where you want to change the font sizes.

    See:

    #bookmarksMenuPopup, #personal-bookmarks { font-size: 14px !important; }

Maybe you are looking for

  • HP Pavillion Dv6 ci5, all hearts are working to 100% at idling

    Hello I have HP Pavilion dv6, 3 years old. For the last two days, my PC is really hot at 100 ° C or 90 c at idle, all hearts are 100% working. I closed all applications but still no use.  Here are pictures of the running process. Kindly help me how t

  • Vista - Error Code: 80070490 (cannot install updates)

    Tried everything but one thing, could you help and tell me what one thing please. I am running Vista Business 32-bit preloaded when bought.  problem started 2 weeks ago when I got 3 three updates 1 = update for Windows Vista (KB2158563) Installation

  • Is there a possible way to use my EOS Rebel XT EOS Utility?

    Okay, so I want to use my camera for Digital Rebel XT EOS Utility. In case you are wondering EOS Utility is used to take a picture with the camera simply by clicking a button on the computer. Its used to make pictures that I take are not fragile. Any

  • bought replacement computer

    3 years ago, we bought an HP computer with windows vista pre installed. He understood the re install disks. The hard drive died and he was succeeded and had no bad to re install the motherboard vista.now died, so we bought a generic pc Tower and the

  • GPS differences between CDMA carriers

    What I was asking is if a standalone GPS based on demand for a CDMA device (for example, the 8330 and 8830) is portable between carriers? Or are there other parameters I should know beyond what is detailed in the best practices for the design of the