How can I access data in different panels?

Hi,
I'm a beginner in Swing and have a simple(?) question. Unfortunately I didn't find the answer by oneself so I hope you can help me.
I have three classes. In the GUI.java class I build the JFrame and it's components. All components are added to the frame via panels that a separate classes.
My problem is: how can I acces the values in PanelB when I call the actionPerfomed in PanelA? Or is that always a bad design? How can I make it better?
GUI.java
JFrame frame = new JFrame();
PanelA panelA = new PanelA();
PanelB panelB = new PanelB();
frame.getContentPane().add(panelA);
frame.getContentPane().add(panelB);PanelA.java
private class ButtonCalculateAction implements ActionListener {
     public void actionPerformed(ActionEvent e){
          //calculate with valuesX and valuesY from Panel B
JButton buttonCalculate;
...PanelB.java
JList valuesX;
JList valuesY;
JButton addValueX;
...

Here is the code for a Short, Self Contained, Correct (Compilable), Example
GUI.java
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class GUI {
     public GUI(){
          JFrame frame = new JFrame();
          PanelA panelA = new PanelA();
          PanelB panelB = new PanelB();
          frame.getContentPane().setLayout(new FlowLayout());
          frame.getContentPane().add(panelA);
          frame.getContentPane().add(panelB);
          frame.setSize(400, 200);
          frame.setVisible(true);
     public static void main(String[] args) {
          GUI gui = new GUI();
}PanelA.javaimport java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class PanelA extends JPanel {
     public PanelA(){
          this.setLayout(new FlowLayout());
          this.buttonCalculate = new JButton("Calculate");
          this.buttonCalculate.addActionListener(new ButtonCalculateAction());
          this.add(buttonCalculate);
          this.result = new JTextField("...");
          this.add(result);
     private class ButtonCalculateAction implements ActionListener {
          public void actionPerformed(ActionEvent e){
               //calculate with values from PanelB. How??
               //result = ?
     private JButton buttonCalculate;
     private JTextField result;
}PanelB.java
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class PanelB extends JPanel {
     public PanelB(){
          this.addValueX = new JButton("Add X");
          this.addValueX.addActionListener(new ButtonAddAction());
          this.valuesXList = new DefaultListModel();
          this.valuesX = new JList();
          this.valuesX.setModel(valuesXList);
          this.add(addValueX);
          this.add(valuesX);
     private class ButtonAddAction implements ActionListener {
          public void actionPerformed(ActionEvent e){
               valuesXList.addElement(47);
     private JList valuesX;
     private DefaultListModel valuesXList;
     private JButton addValueX;
}

Similar Messages

  • HT3275 how can i retrieve information from  time machine if my computer has less storage capacity? How can I access data that is on my time machine but can not be copied to a computer with less storage capacity? I used to have 180 GB, now I have 128 GB.

    how can i retrieve information from  time machine if my computer has less storage capacity? How can I access data that is on my time machine but can not be copied to a computer with less storage capacity? I used to have 180 GB, now I have 128 GB.

    Plug an external drive into the computer and use that to expand data onto.
    http://pondini.org/TM/16.html

  • How can I insert data in different table dynamically?

    I have one requirement ,In these  I have transaction table in which payLoad contain data like employee record,PO record,SO record  in XML format.Now I have transfer the data from transaction table to particular table(Emp,SO,PO) dynamical ? how can I do it.. Give me your suggestion guys?? Thanks in Advance

    Hello,
    Still no luck.I am surely doing silly mistakes.Anyway,Here are my workings-
    1> student_mst (id(pk),studentname) and student_guard_mst(id(fk),guardianname)
    2> created EO from both of the tables,made id in both EO as DBSequence and an association was also generated.
    3> i made that association composite by clicking the checkbox
    4> i created 2 VO from 2 EO.
    5> put those VO in Application Module.
    6> dragged and dropped 2 VO on my jspx page and dropped them as ADF Form.
    Now what to do please?

  • How can I access data from accidentally deleted user?

    I was given a MacBook Pro by a family member. I set myself as the Administrator, but could not get rid of the previous owner's name on the Home folder.
    In my attempts I accidentally deleted something that made the entire computer unaccessable. I can boot up, however, all the work and applications I installed are unaccessable. I can't even open Preferences.
    I used TechTool Pro to start up and explore the drive, and found that the previous owner's name was on a folder with a red-circled minus sign. The data (considerable) was inside, but I can't access it.
    Is there any way I can get access to that data? I slaved the laptop to my iMac and transferred the folder (with 32 gb of data).
    When I tried to open it I got the message: "The folder "sandy....." can't be opend because you don't have permission to see its contents." I used Get Info on the folder and changed Sharing and Permissions to Read and Write, but still no access.
    What can I do, if anything to gain access to that folder?

    http://docs.info.apple.com/article.html?path=Mac/10.7/en/mchlp2968.html

  • Failing/Failed Harddrive - How can I access data?

    The HDD in my Powerbook G4 is seriously failing and when checked with Disk Utility it says that I must backup what I can and replace it.
    The computer won't boot and the drive is audibly shagged. The best I can do is boot to CD and use Disk Utility from there (where it tells me how broken my computer is). My computer gets an IP address when booted from CD and I can ping it from another computer but I cant access the user accounts as I normally can using \\ipaddress\username. This isn't too surprising really.
    Does anyone know how I might be able to access my data?
    Thanks
    Chris
    P.S. Please don't ask me if I've been taking regular backups over the last 2 years and as such might not have lost absolutely everything!

    Does this sound like the a hard-drive that is accessible? If I connect it via Firewire disk mode I assume that my HDD will act like an external HDD attached to the 2nd machine?
    Hi, Chris. That sounds like a hard drive that may be accessible on the same momentary and much-interrupted basis as it is now for a few more seconds, minutes, hours or days — there's no way to tell. You might get really lucky and have a chance to back all your files up in one attempt via FW Target Disk Mode, or you might get halfway through backing up the first file and have the drive quit for good. Or you might get part of your data backed up, but only in the course of a hundred restarts. All we can do is wish you luck and point out that given the uncertainty of the situation, you'd better begin the backup process with your most important files. Plan ahead, and have your highest-priority files listed.
    Yes, in FWTDM the drive will appear as an external drive connected to the host Mac.

  • How can I access data on an external drive in my mac after all folders have been turned into .lnk files? I am desperate!

    I don't know what happened, I connected my external hd today and all files had been turned into that!

    I know I am going to sound really stupid when I ask this, but how do I do that? There was this folder called Recycle Bin, which I have deleted already but the files are still in the same format. I know they are in the HD 'cause of the space taken up in it, but I would like to know exactly what to do to clear the malware altogether and have access to the stuff I have again.
    Thank you very much in advance and sorry for being such a dummy

  • How can i access remote front panel in RT with LabVIEW run time engine in client PC

    Hi to all,
    I have developed the RT application with cRIO 9075 integrated chassis. And i have access its remote front panel in client PC. Now i want to access the remote panel in the client PC without having LabVIEW runtime engine. If i connect the remote panel with that client, it shows only the vi border. i doesn't downloads the  front panel.
    How Can i access its remote front panel without LabVIEW runtime engine in the client PC?

    You cannot view a remote front panel without the LabVIEW runtime - the LabVIEW runtime is what makes the remote front panel possible.  What you will want to do instead is likely create a Web Service that you can access from a remote PC without requiring the LabVIEW runtime.  However, this will require you to develop a web-based HTML or similar UI to interact with the VIs running on your system - NI hasn't yet created a way to export a LabVIEW front panel as an HTML'ish page.  
    -Danny

  • How to access data in different server  with flex3 remoteobject

    I am trying to access data from cfc that is in different pc
    through network and coldfusion 8, flex3 and sql server are in diff.
    pcs. So how can I access the cfc file in different pc using remote
    object which will return the data from another server using dsn? I
    can connect to the service if coldfusion and flex are kept in same
    pc. How can I access it in diff. pc?what will be destination and
    source param values?
    Any help is appreciated.

    Hi,
    You should be able to achieve this by changing the end point
    URL of the channel you are using in the services-config.xml. The
    end point URL should point to the server where your CF is deployed.
    Hope this helps.

  • How can I access Address Book data from an older version of the application to transfer it to a newer version of Mac OS running on a second hard drive on the same MDD G4?

    I installed a hard drive from one PowerPC Dual 1.25 GHz MDD into another one with an older version of the OS X.  all my Address Book data are on the older hard drive, from which I now boot the computer.  When I launch Address Book as an app on the hard drive with the newer version of the OS, I get an error message that says I cannot run the version of Address Book from the older hard drive on the newer OS.  How can I access the data on the older hard drive version of the Address Book app so that I can transfer it to the newer version of the app on the boot drive?  The "Import" functionality will not work. I will be grateful for any help I can get.  I would also like to uninstall the older version of OS X from the older hard drive.

    Boot from the older version of OSX, then in AB use the File>Export>Export vCard after selecting all in AB.
    Then boot from the new OSx & use the new AB to import that VCF file.

  • How can I migrate data from an old MBA to a new one without having access to the screen of the old one? The screen of the old MBA is damaged !

    How can I migrate data from an old MBA to a new one without having access to the screen of the old one? The screen of the old MBA is damaged !

    If your "older" MBA has a Thunderbolt port then it isn't that old. See Target Disk Mode about how it's used. Note that without a monitor you won't be able to tell from the screen when it has fully started, and if it succeeded in starting in TDM. If it did, then the hard drive should appear on the Desktop of your new computer. You can then access it to transfer your files. You can even use Migration Assistant or any backup utility to transfer data. Just don't try to transfer system files.

  • I loos my APPLE ID, I have a new one, how can get access to data stored in the old one?

    I loos my APPLE ID, Now I have a new one, how can get access to data stored in the old one?

    Do you have the email & password of the old Apple ID?

  • ICloud storage space used up by old data from 1st gen iPad I traded in nearly 2 yrs ago for an iPad Mini. Can't backup any info for mini or new 6 plus. How can I access this old data to clear it out?

    My iCoud storage space is being used up by old data from a 1st  generation iPad I traded in nearly 2 yrs ago for an iPad Mini. The people at the sprint store where I made my trade were supposed to transfer everything over from my old iPad to the new Mini once they backed up the old device to iCloud. Well, long story short, none of the data ever got transferred to the new iPad, but it all got backed to iCloud, eating up all my storage space. Here I am almost 2 years later, and I've never been able to back-up my iPad mini. What's worse, My iPhone 4 wasn't backed up that whole time, and now I can't back-up my data from my new iPhone 6 Plus to iCloud either. Trying to find creative ways to store and save my information and data between all my devices is getting to be ridiculous. I don't want to upgrade my storage space though...just want to clear out a great deal of what is already being stored. How can I access this old data to clear it out?

    The only way to access data from an iCloud backup is to restore it to your device.  You could, for example, back up your iPad mini to your computer using iTunes (by connecting it, opening iTunes, then going to File>Devices>Back Up and choosing to back up apps and transfer purchases when prompted), then erase it and restore the old iPad backup (as explained here: iCloud: Restore or set up your iOS device from iCloud), save any recovered data you want to keep, then restore your iTunes backup back to your iPad mini (by connecting it to your computer, opening iTunes, then going to File>Devices>Restore from Backup).
    Once you're done with the old backup, delete it from your account to free up the space.

  • TS1538 I have just purchased an iPhone5 and created a new user instead of using my previous ID. How can I access my previous data?

    I have just purchased an iPhone5 and created a new user instead of using my iPhone3 ID. How can I access my previous data?

    don't just sign out!
    if you simply sign out, the stuff you recently purchased will be an issue in the future when an update comes out for apps or anything else. restore the device as new from itunes then restore from a back if you have one as stated above...or set up as new and use correct apple id. this will ensure you will be using the apple id that you used originally without issues from the new one.

  • I upgraded to the new IOS, but lost data and apps. When I try and restore the only backup I see is the one made AFTER the lost data. How can I access an older backup from the cloud?

    I upgraded to the new IOS, but lost data and apps. When I try and restore the only backup I see is the one it made AFTER the lost data. How can I access an older backup from the cloud?

    Why don't you talk to apple and find out if backup exists? That conversation with apple will stop your guessing.

  • How can I access Kuler panel and Italian Restaurant theme in Adobe Illustrator CC 2014.1.1

    How can I access Kuler panel and Italian Restaurant theme in Adobe Illustrator CC 2014.1.1

    Kuler has now changed to Colour Theme Adobe Color CC

Maybe you are looking for

  • Regarding putting trafic lights in alv report

    Hi frnds,                  I need to add Traffic lites to my program can any one help me how to do that. Below i m providing my code. <code> *ztest_alv *& Report  ZSAMPLEALV3                                                 * REPORT  ZSAMPLEALV3      

  • Reading a csv file and bind to a data grid

    hi. doing a school project and been searching. the application reads a csv file from c:\stocklist.csv, and then this in a button called btnLoadData, and now need to read in a data control called DmgDisplayData. do i put the code in the button, or in

  • Slip the sync in a merged clip

    Hello, I have tried to search everywhere, but couldn't find a answer. I have used Sync n Link to batch sync a feature film. Now i'm checking every take to see if it's really sync, and a lot of times it's 1 frame off. It would be great if you can chan

  • MBA as a Wifi hotspot without other connection

    Hi. I am running a web server on my MBA and I would like others to be able to connect to this server. For security reasons, I can't run a server on a specific network. I would like to disconnect my MBA from WiFi, turn it into a WiFi hotspot that othe

  • SAP XML Definitions

    Hello, How can I get the  XML definitions for all docs out of SAP   - order & invoice - PO & AP invoice - delivery & return . Thanks Max