Let classes talk to one another

Hi,
I am doing a project in java but first I wanted to do a simple program that has three class - class with main, class for displaying buttons and a class that has a jtextarea. When you click on a button it then displays a message in the textarea.
I am having trouble letting the classes communicate. I want to have the main program as the overall controller. Please help asap.
This is the code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
public class project
public static void main(String[] args)
// Time time = new Time();
// System.out.println(time.getTime());
right r = new right();
left l = new left();
JPanel p = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JFrame aFrame = new JFrame();
aFrame.setTitle("Swing 3");
aFrame.setBounds(0, 0, 700, 500);
Container contentPane = aFrame.getContentPane();
p.add(l);
p.add(r);
p3.add(p);
//p3.add(p2);
contentPane.add(p3);
aFrame.setVisible(true);
class left extends project implements ActionListener
private JButton redButton,greenButton,blueButton,yellowButton;
public left()
///this.r=r;
JPanel pp = new JPanel();
setLayout(new BorderLayout());
redButton = new JButton("Red");
redButton.addActionListener(this); // step 4
greenButton = new JButton("Green");
greenButton.addActionListener(this);
blueButton = new JButton("Blue");
blueButton.addActionListener(this);
yellowButton = new JButton("Yellow");
yellowButton.addActionListener(this);
pp.add(redButton);
pp.add(greenButton);
pp.add(blueButton);
pp.add(yellowButton);
add(pp,BorderLayout.NORTH);
public void actionPerformed(ActionEvent e)
// e.getSource() // returns name of the button
if (e.getSource() == redButton){
r.textArea.setText("red");
if (e.getSource() == greenButton)
r.textArea.setText("green");
if (e.getSource() == blueButton)
r.textArea.setText("blue");
if (e.getSource() == yellowButton)
r.textArea.setText("yellow");
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
class right extends project
JButton oneButton,twoButton;
JTextArea textArea;
public right()
JPanel jp = new JPanel();
setLayout(new BorderLayout());
oneButton = new JButton("one");
twoButton = new JButton("two");
textArea = new JTextArea();
// add(textArea,BorderLayout.SOUTH);
jp.add(oneButton);
jp.add(twoButton);
add(jp,BorderLayout.SOUTH);
add(textArea,BorderLayout.NORTH);
}

Hi,
I am doing a project in java but first I wanted to do
a simple program that has three class - class with
main, class for displaying buttons and a class that
has a jtextarea. When you click on a button it then
displays a message in the textarea.Google for MVC pattern (Model View Control pattern).
I am having trouble letting the classes communicate.
I want to have the main program as the overall
controller. Please help asap.Don't write asap the next time please: it sounds rude. Why should your problem be more important than other people's questions (or more important than other people's time)?
Also, when posting code, use code tags: http://forum.java.sun.com/help.jspa?sec=formatting
Thanks.

Similar Messages

  • Help getting 7960 phones to talk to one another

    Hello experts,
    My classmates and I were assigned a lab to get two 7960's to talk to one another. We have a 2800 series router and a 2950 switch at our disposal as well as a PC. We were also given this video to help us out:
    http://www.youtube.com/watch?v=6rQakFGMZRM
    We were able to successfully perform the task in PacketTracer, but when it came time to physically perform the lab, we followed all the instructions and the phones are hung up on the "Configuring IP" screen. We honestly do not know where to go from here and have been  stuck for over a week with this. Could anyone please help us push forwards? Please mind that we are completely new to this and additional hand-holding may be needed
    Thanks!

    If you followed the video from the link the first thing that may be causing trouble is that the voice vlan on the switch is configured to be vlan 1.  On certain switches the phones will not function properly when the voice and access vlan are configured to the same value.  The default access vlan is 1 also so if this has not been changed the above configuration would make both the access vlan and voice vlan the same at vlan 1.  Try and change the access on the switch ports that your phones are connected to, to a different vlan such as vlan 2.  This can be done with "enable", "conf t", "interface fa", "switchport access vlan 2". 
    If you are still having trouble after that, make sure that CDP is enabled on your switch with "show cdp" and lastly looking at the phones themselves, pressing the settings button and navigating to status, then to status messages should show you what the current problem is with the phones, meaning if it is failing to learn the router's address to register or if you have a DHCP problem causing the phones not to get an IP address.

  • HT1688 Messaging does not let me move from one conversation to another without going to the contact info of the person and choosing "send a message", then I can continue the conversation. I'm sure it's a setting I have made by mistake, but can't figure it

    Messaging does not let me move from one conversation to another without going to the contact info of the person and choosing "send a message", then I can continue the conversation. I'm sure it's a setting I have made by mistake, but can't figure it out

    Hi Elaine
    Here si what I do:
    Since I tend to message with teh same people I leave the messages available to me.  If you are in one conversation with "Karen"  and want to message with "Kathy" tap the message back arrow and select Kathy.
    As always just be careful to rememeber who you are messaging to!

  • How can we call a class file of one package for class file of another

    How can we call a class file of one package from class file of another package and both packages exist in a same folder

    How can we call a class file of one package from
    class file of another package and both packages exist
    in a same folder
    Luckily they don't so it's really not a problem after all.

  • Putting photo layers on top of one another

    In Elements 4 can you put multiple layers of photos on top of one another and how?

    Eden,
    1. This program depends on utilization of layers to achieve the best result
    2. Open image 1 - the one that you want to add something into
    3. Open image 2 - the one that you want to select something from, to add to image 1
    4. Use one of the selection tools, for example the magnetic lasso tool, to select that which you want to copy from image 2. When you do this, you will see "marching ants" around the selection. Go to Edit>copy.
    5. Bring up image 1, go to Edit>paste. You should now see image 1 as the bottom layer, and the selected portion of image 2 above this. Surrounding the selection is a checker-board pattern which represents transparency, allowing you visibility.
    6. In order to position the pasted portion, use the move tool.
    Try this and let us know how you make out. Don't try for perfection initially, just attempt to follow this drill until you get the hang of it.
    Forget about the healing brush for now. This tool is used for another purpose.
    Ken

  • Navigating page to page while "registering" pages one another

    Okay,
    this may sound a little weird, but bear with me.
    Lets assume we are navigating a two pages PDF. The pages are same size and nearly same content except for some small details.
    If one fit the page into the window (CTRL+0), then pressing "pg-Up" and "pg-down" (or "up" and "down", or even "left" and "right") will make Acrobat navigate to the next page (or previous), while the fit to windows zoom level will remain unchanged.
    This provides the nice effect that you can basically "animate" between pages and the small differences will "jump" off the page much more easily.
    In other words, the pages register with one another, and becasue nowdays computers are fast enough to seamlessly swap pages on the screen, you can see an "animation" between one page to the next.
    Now, this nice registering of pages with one another appears to be possible only using CTRL+0, fit to window.
    The question is:
    If you zoom in a page, is there a keystroke that allows you to swap to the next or previous page while leaving the zoom level and the region being zoome unchanged?
    If I zoom into a page and press "pgeup/down" acrobat will scroll the view up/down in the same sheet, or page.
    If I zoom into a page and press "CTRL+pg-up/down" Acrobat will yes navigate to teh next/previous page, but it will always move the view crop to align with the top of the page...
    Anyone knows if there is a way to swap pages while keeping zoom level and view crop location with respoect to the pages?
    thank you (I hope I have been clear enough...)
    Regards
    gio

    What may be overlooked in Pages v5 is the notion of combining Text Boxes via the Menu > View > Show Arrange Tools. When you select two Text Boxes, an extra panel unfolds at the bottom of the Arrange Tools window. Uncheck one Text Box and this panel abruptly disappears.
    One can achieve text flow effects between Text Boxes differently based on how one positions the Text Box overlap, and choice of effect above. Though not the accustomed flow found in Pages ’09 v4.3, flow does occur. Consider the possibilities of combining a Shape and a Text box to cut an irregular Text box.
    If I create two Text Boxes and position them side by side with outline touching and choose Unite, this creates one larger Text Box and text flows across and down. On the otherhand, if I overlap the upper left corner of a lower Text Box over one above and to the left, then choose Union, pasted text fills the first Text Box and then flows across and down into the other box. Here is a Union example:
    Intersect will leave a small Text Box where the two overlap, so not much value there. Subtract will cut a chunk out of one Text Box that is the size of the overlapping piece of the second Text Box:
    And Intersect will leave an island in the center where the two Text Box overlap, with flow jumping over this bridge.
    Clearly, this is not what we were accustomed to in the past, but with imagination, style, and layout tuning, it does offer alternative Text Box creativity and layout. Of course, there is the option of simply returning to the previous Pages version for true Text Box linking that most will want to use.

  • My iMac and MacBook Pro have stopped being able to find one another.

    I have been sharing files between my iMac and MacBook Pro.  Recently they have stopped being able to detect one another.  When I look in the sidebar of the Finder window, neither computer shows the other.  I have file sharing enabled for both computers.  This is a recent problem, and I'm not sure what has changed.  I may have updated software - but don't remember what or when, as I tend to automatically do so when an update becomes available.  I would appreciate any help that you can give.
    Thanks,
    Linda

    Eric,
    Thank you.  I had all my settings right - I had checked and double checked.  The one thing I had failed to do - which is the one thing that often helps - is to shut everything down and restart.  I shut the router and the computers down and restarted them one at a time.  They are once more talking to each other.
    Thank you again,
    Linda

  • I know i am online but iChat won't let me talk or video chat

    I try to log onto my @mac.com account, as well as my AIM accounts, but it does not let me talk to anyone. It says i'm online, but i know that on other's buddy lists i am not. This is so frustrating because it happens all the time. The only way i have fixed it in the past is by making a new account, which i don't really want to do like every week. Can someone please help?

    Hi,
    From the way you describe things I think at the iChat Menu > Preferences > Accounts you are listing some AIM names with Running Men next to them and a Apple @mac.com one with a blue globe.
    There has been at least one other thread where the poster said he could not get his @mac.com name On-line.
    Until yesterday I had not had a problem but I can not get a response from my @Mac Name then.
    It has come back today
    8:01 PM Saturday; February 6, 2010
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
    Message was edited by: Ralph Johns (UK)

  • Threads treading on one another's feet...

    Dear All,
    I wonder whether you could help me with a couple of threads treading on one another's feet.
    Following is the class in question, which represents a sort of simple semaphore on object locking. The only two states allowed should be 0 and 1, respectively available and not available. (just for study purposes) immagine then Thread1 and Thread2 calling both acquire() and release() in their run() methods.
    <code>
    public class Atomic {
    private volatile int semaphore = 0;
    public void acquire() { semaphore = semaphore + 1; }
    public void release() { semaphore = semaphore - 1; }
    </code>
    and this is the javap -c Atomic result:
    <code>
    Compiled from Atomic.java
    public class Atomic extends java.lang.Object {
    public Atomic();
    public void acquire();
    public void release();
    Method Atomic()
    0 aload_0
    1 invokespecial #1 <Method java.lang.Object()>
    4 aload_0
    5 iconst_0
    6 putfield #2 <Field int semaphore>
    9 return
    Method void acquire()
    0 aload_0
    1 aload_0
    2 getfield #2 <Field int semaphore>
    5 iconst_1
    6 iadd
    7 putfield #2 <Field int semaphore>
    10 return
    Method void release()
    0 aload_0
    1 aload_0
    2 getfield #2 <Field int semaphore>
    5 iconst_1
    6 isub
    7 putfield #2 <Field int semaphore>
    10 return
    </code>
    When two threads interact on this particular object, the possible values for semaphore held in an unstable state are 2 and -1.
    If it's quite simple to account for 2, it's not so for -1.
    I would like to understand why. Furthermore, I have just approched opcodes, so don't take anything for granted, please.
    One more question: are incrementing and decrementing atomic operations, is then every single opcode an atomic operation?
    P.s. and the purpose of volatile in case?
    Thank you for your time
    luca

    It may be best to include the full example (from Eckel's Thinking in Java):
    //: c13:Invariant.java
    public interface Invariant {
    InvariantState invariant();
    //: c13:InvariantOK.java
    // Indicates that the invariant test succeeded
    public class InvariantOK implements InvariantState {}
    //: c13:InvariantFailure.java
    // Indicates that the invariant test failed
    public class InvariantFailure implements InvariantState {
    public Object value;
    public InvariantFailure(Object value) {
    this.value = value;
    //: c13:Semaphore.java
    // A simple threading flag
    public class Semaphore implements Invariant {
    private volatile int semaphore = 0;
    public boolean available() { return semaphore == 0; }
    public void acquire() { ++semaphore; }
    public void release() { --semaphore; }
    public InvariantState invariant() {
    int val = semaphore;
    if(val == 0 || val == 1)
    return new InvariantOK();
    else
    return new InvariantFailure(new Integer(val));
    //: c13:SemaphoreTester.java
    // Colliding over shared resources
    public class SemaphoreTester extends Thread {
    private volatile Semaphore semaphore;
    public SemaphoreTester(Semaphore semaphore) {
    this.semaphore = semaphore;
    setDaemon(true);
    start();
    public void run() {
    while(true)
    if(semaphore.available()) {
    yield(); // Makes it fail faster
    semaphore.acquire();
    yield();
    semaphore.release();
    yield();
    public static void main(String[] args) throws Exception {
    Semaphore sem = new Semaphore();
    new SemaphoreTester(sem);
    new SemaphoreTester(sem);
    new InvariantWatcher(sem).join();
    When I run the programme on my Pentium 133 with Windows 95, the InvrianteWatcher
    detects the semaphore's value in an invalid state (2). If you remove all the yields() withing the run() method
    the InvariantWatcher detect -1. What I'd like to know is the sequence of opcodes (the mixing of both threads)
    that would set semaphore's value to 2 and -1.
    I would be grateful if you could be as thorough as possible in your explanaition.
    I only trying to get a deeper understanding of the underlaying logic of threads.
    Many thanks
    Luca

  • How to seperate divs from one another

    Hi all and thank you for your help.
    I need to seperate <div>s with clear space between one another, something like at www.deonholtphoto.co.za The header, navigation and content are clearly 3 seperated blocks with space between them where the background clearly comes through. That site I have done for Joomla! with Artisteer.
    But, for the life of me I cannot get it right with normal CSS. I am sure I need to put something in between the "blocks" but don't know what. On the other hand I am almost sure that it is not padding?
    Please help me out here.
    Thank you very much.
    Deon

    Thanx John. I thought it had maybe something to do with <div class="cleared reset-box"></div> ... or something like that.
    Thank you once again.
    Deon

  • I am fed up with Spring and Apple passing me off to one another and neither will fix the problem. I am unable to receive a connection on my phone.

    I am fed up with Spring and Apple passing me off to one another and neither will fix the problem. I am unable to receive a connection on my phone.
    The internet goes out and I have to reset network setting each and every time. This is only a temporary solution which by the time I release the line with Spring or leave the apple store the issue is back. Sprint indicates that it is a know issue with the Iphone 5 and apple says it is a network issue as Sprint's network is not up to par with the Iphone and can not meet the expectations on the Iphone 5.
    I have attached a few picture, as you can see it clearly says I have 5 bars and 3g available but I have no connections what so ever.
    This issue affects all data and so I can not send or receive picture messages, use apps, or access the internet. The data goes in and out intermittently and it seems the phone chooses what I can and can't do.
    For example I can watch Youtube or Vevo videos but I can not access Facebook or Instagram.
    Is anyone else having this issue?
    I will soon loose my patience....
    I have reset my phone three time and have reset network and other setting mutltiple times.

  • How do you select and move more than one bookmark at a time? Shift+Click does not select multiple items that are next to one another in a list because the item

    How do you select and move more than one bookmark at a time?
    Shift+Click does not select multiple items that are next to one another in a list because the items open in firefox before this happens.

    Use the bookmarks library. You may use Shift +Click, and Ctrl + Click to create groupings of selected bookmarks to drag and drop.
    * one method of opening the bookmarks library is keyboard shortcut <br /> Ctrl+Shift+B (Windows)
    *see also [[How to use bookmarks to save and organize your favorite websites]]
    *and [[Use bookmark folders to organize your bookmarks]]

  • I have 2 new iPhone 4s. Messages from other iPhone users appear on both of my new phones. I want these seperate. How do I make these independent of one another?

    I bought my daughters new iPhones (4s) for Christmas.  They love them except that when another iPhone user text one daughter, the other daughter gets the messages and same for the other daughter's text.  How do I make these independent of one another without putting my family on separate ITunes accounts?

    When you were setting the phones up you should have been asked if you wanted to use the phone number or an email address for FaceTime/messaging. My guess is you used the same email for both phones. Just go in and change it. That or you have the same iCloud id on both phones, I'm not using the cloud so I can't help you there.

  • My wife and I share the same email address and Apple ID.  We are not able to send and receive Text Messages to one another.

    My wife and I share the same email address and Apple ID. We are not able to send and receive Text Messages to one another. Is the cause of this because we share the same Apple ID? Will we have to set up 2 separate primary email addresses to be able to  send and receive Tex Messages to one another? Like I said, we share the same email address and woul like to keep it that way to keep up with our email together. Is there a way to by-pass having to set up 2 primary emaill addresses if this is the problem?
    Thanks.

    go to the settings and turn off imessage
    but that don't change the issue that you will never be able to facetime eachtoher
    the appleID is really meant as the handle that identify you it was not meant to be shared
    but can see that people may want to do not buy apps more then once

  • Domain Controllers relies on one another

    I inherited a server system and was told that a certain server was the domain controller. For years we added accounts, servers, etc on this domain controller. Recently we made some changes and took other servers out of production. When doing so we noticed
    that when what we thought was the main server was rebooted it would not load dns or AD. After doing some commands we found that the pdc, master, etc roles were on a server we turned off. We then immediately transferred all roles. After rebooting
    again it still was not working without the old server. We then decided to just fire up the old server and had the same issues with loading the dns, ad, etc. We then fired up the old server and then server we thought was main(and is now
    since we transferred all roles to it). At first both servers were unable to access the dns and ad but then after a few minutes all was running properly on both. It almost appears that they rely on one another. We ran dcdiag on both and see no issues.
    One thing that is odd is that neither server has the same items within the netlogon. On the old server the folder within sysvol looks like and actual folder where as the other server it looks like a shortcut. I should mention the old server is windows 2003
    and the other is 2008 R2.
    My question is why would one another rely on each other and how do I make it so the old server is no longer required? I ensured the tcp properties/primary dns was set to itself. I also ran dcdiag /fix which was fine along with checking items with nslookup.
    I am at a complete loss.
    I do have some errors within the event viewer but they are not directing me to any possible solutions. Now just for the heck of it I tried creating another domain on a windows 2012 server and select only the one server for replication but each time it adds
    the old server as dns. I then thought maybe the old server was the main dns but when I look at each server the dns point to itself but if one is off the dns is inaccessible. Now the odd part is once I have all up I can then shut the old server off and all
    works fine until I reboot the server. Also both servers are GC too.
    Any advice?

    Checklist before demoting a Domain Controller.
    1) FSMOs is present or not . If present need to transfer.
    2) Need to DHCP scope accordingly.
    3) Application dependency like MS-Exchange , Citrix & so on.
    4) Use DNS debug log before demoting any DC.
    The Fun in DNS Debug Logging - Read the DNS Debug Log  
    http://social.technet.microsoft.com/wiki/contents/articles/13640.the-fun-in-dns-debug-logging-read-the-dns-debug-log.aspx
    Pls upload the below result & upload in skydrive and share the link.
    Run dcdiag, netdiag and repadmin in verbose mode.
    -> DCDIAG /V /C /D /E /s:yourdcname > c:\dcdiag.log
    -> netdiag.exe /v > c:\netdiag.log (On each dc)
    -> repadmin.exe /showrepl * /verbose /all /intersite > c:\repl.txt
    A quick little dump repadmin /replsum > c:\replsum.txt
    -> ADReplStatus
    -> dnslint /ad /s “ip address of your dc”
    https://dirteam.com/paul/2009/01/26/troubleshooting-active-directory-issues/
    Regards,
    Biswajit
    MCTS, MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, Enterprise Admin, ITIL F 2011
    Blog:
      Script Gallary:
      LinkedIn:
    Note: Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights..

Maybe you are looking for