How can I update a JTextArea from another class

I am new to Java so forgive me if this is confusing, or if I seem to be taking an overly complex route to acheiving my goal.
I've got a JTextArea component added to a JPanel object, which is then inserted into the JFrame. I have a JMenuBar with a JMenu "file" and a JMenuItem "connect" on this same JFrame. When clicked, the actionEvent of JMenuItem "connect" calls a class "ConnectToDb" to establish a connection with the Database. On a successful connection, I want to append the String "Connection Successful" to the JTextArea component, but since the component is a part of the JPanel object, I cannot seem to get access to the JTextArea component to update it. I tried instantiating the JPanel object from within the "ConnectToDb" class and then called a method I created to set the JTextArea. No luck. Can someone give me an idea of what I need to do that would allow me to update the text of the JTextArea component from anywhere in my program? Once it has been contained in the JPanel or JFrame, can it be updated?
This is the class that establishes the simple Db Connection
package cjt;
import java.io.*;
import java.sql.*;
* Get a database connection
* Creation date: (04/01/2002 4:08:39 PM)
* @author: Yaffin
public class ConnectToDB {
public Connection dbConnection;
// ConnectToDB constructor
public ConnectToDB() {
public Connection DbConnect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL = new String("jdbc:odbc:CJTSQL");
Connection dbConnection = DriverManager.getConnection(sourceURL, "Encryptedtest", "pass");
System.out.println("Connection Successful\n");
//this is where I originally tried to append "Connection Successful
//to the JTextArea Object in WelcomePane()          
} catch (ClassNotFoundException cnfe) {
//user code
System.out.println("This ain't working because of a class not found exeption/n");
} catch (SQLException sqle) {
//user code
System.out.println("SQL Exception caused your DB Connection to SUCK!/n");
return dbConnection;
This is the JPanel that contains the JTextArea "ivjStatusArea" I am trying to update from other classes. Specifically the "ConnectToDb" class above.
package cjt;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
* Build Welcome Pane
* Creation date: (04/01/2002 3:42:50 PM)
* @author: yaffin
public class WelcomePane extends JPanel {
     private JTextArea ivjtxtConnect = null;
     private JLabel ivjwelcomeLbl = null;
     private JTextArea ivjStatusArea = null;
* WelcomePane constructor comment.
public WelcomePane() {
     super();
     initialize();
* Return the StatusArea property value.
* @return javax.swing.JTextArea
private javax.swing.JTextArea getStatusArea() {
     if (ivjStatusArea == null) {
          try {
               ivjStatusArea = new javax.swing.JTextArea();
               ivjStatusArea.setName("StatusArea");
               ivjStatusArea.setLineWrap(true);
               ivjStatusArea.setWrapStyleWord(true);
               ivjStatusArea.setBounds(15, 153, 482, 120);
               ivjStatusArea.setEditable(false);
               // user code begin {1}
               // user code end
          } catch (java.lang.Throwable ivjExc) {
               // user code begin {2}
               // user code end
               handleException(ivjExc);
     return ivjStatusArea;
* Initialize the class.
private void initialize() {
     try {
          // user code begin {1}
          // user code end
          setName("WelcomePane");
          setLayout(null);
          setSize(514, 323);
          add(getStatusArea(), getStatusArea().getName());
     } catch (java.lang.Throwable ivjExc) {
          handleException(ivjExc);
     // user code begin {2}
     // user code end
This is the main class where evrything is brought together. Notice the BuildMenu() method where the JMenuItem "connect" is located. Also notice the PopulateTabbedPane() method where WelcomePane() is first instantiated.
* The main application window
* Creation date: (04/01/2002 1:31:20 PM)
* @author: Yaffin
public class CjtApp extends JFrame {
private JTabbedPane tabbedPane;
private ConnectToDB cdb;
private Connection dbconn;
public CjtApp() {
super("CJT Allocation Application");
// Closes from title bar
//and from menu
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
tabbedPane = new JTabbedPane(SwingConstants.TOP);
tabbedPane.setForeground(Color.white);
//add menubar to frame
buildMenu();
//populate and add the tabbed pane
populateTabbedPane(dbconn);
//tabbedPane.setEnabledAt(1, false);
//tabbedPane.setEnabledAt(2, false);
getContentPane().add(tabbedPane);
pack();
* Build menu bar and menus
* Creation date: (04/01/2002 2:42:54 PM)
private void buildMenu() {
// Instantiates JMenuBar, JMenu,
// and JMenuItem.
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item1 = new JMenuItem("Connect");
JMenuItem item2 = new JMenuItem("Exit");
//Opens database connection screen
item1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//call the ConnectToDb class for a database connection
ConnectToDB cdb = new ConnectToDB();
dbconn = cdb.DbConnect();
}); // Ends buildMenu method
//Closes the application from the Exit
//menu item.
item2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}); // Ends buildMenu method
//Adds the item to the menu object
menu.add(item1);
menu.add(item2);
//Adds the menu object with item
//onto the menu bar     
menubar.add(menu);
//Sets the menu bar in the frame
setJMenuBar(menubar);
} //closes buildMenu
public static void main(String[] args) {
CjtApp mainWindow = new CjtApp();
mainWindow.setSize(640, 480);
mainWindow.setBackground(Color.white);
mainWindow.setVisible(true);
mainWindow.setLocation(25, 25);
* Add tabs to the tabbedPane.
* Creation date: (04/01/2002 2:52:19 PM)
private void populateTabbedPane(Connection dbconn) {
     Connection dbc = dbconn;
     tabbedPane.addTab(
     "Welcome",
null,
new WelcomePane(),
"Welcome to CJT Allocation Application");
     tabbedPane.addTab(
     "Processing",
null,
new ProcessPane(dbc),
"Click here to process an allocation");
     tabbedPane.addTab(
     "Reporting",
null,
new ReportPane(),
"Click here for reports");
//End
Thanks for any assistance you can provide.
Yaffin

Thanks gmaurice1. I appreciate the response. I believe I understand your explanation. I am clear that the calling code needs access to the WelcomPane() object. I am assuming that the constructor for the calling class must have the JPanel WelcomePane() instance passed to it as an argument. This way I can refer directly to this specific instance of the object. Is this correct?
Also, where would you create the set method? I tried to create a set method as part of the WelcomePane() class, and then call it from the calling class, but it didn't seem to work. Lastly, a globally accessible object? Can you explain this concept briefly? Thanks again for your help.
yaffin

Similar Messages

  • How can I call a variable from another class

    hi
    If I have two classes : one and two
    In class two I have a variable called : action
    In class one I want to check what is the value of action.
    How can I call action?

    Thank you scorbett
    what you told me worked fine, but my problem is that MyClass2 is an application by itself that I don't want to be executed.
    Creating myClass2 as in the following:
    MyClass2 myClass2 = new MyClass2();
    [/code]
    executes myClass2.
    Can I prevent the exectuion of MyClass2, or is there another way to call the variable (action)?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?

    If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?  I imported music from a CD into my compter at work and when I got home and went to my iTunes account none of the songs were in my library.  I also noticed that on my Work computer there were a couple songs that I had to click on the little 'cloud' icon before I could listen to them (these were not songs I imported they were songs that were already in my library).  Not sure if this makes semse...help.

    jamie171 wrote:
    My question is since I have imported them into my iTunes library from one computer why can't I access them from my iTunes library from another computer that I have authorized to access whats in my library?  Is there no way to import songs only once into the library and then access them from all my authorized computers?
    Only if you have iTunes Match or of the computers are on the same local network.

  • How can I edit my website from another computer? and how can I create a new website next to the one, I have already? Can anyone help, please?

    How can I edit my website from another computer? and how can I create a new website next to the one, I already have? Can anyone help, please?

    Move the domain.sites file from one computer to the other.
    The file is located under User/Library/Application Support/iWeb/domain.sites.  Move this file to the same location on the other computer and double click and iWeb will open it.  Remember, it is your User Library that you want and not your System Library, as you will not find iWeb there.
    Just create a new site on the same domain file and it will appear below the other site.  If you want them side by side then duplicate your domain file and have one site per a domain file and they can then be side by side.

  • My  ipod touch is 3rd gen how can i update my ios from 4.2.1 to 5.1.1 when i shift   restore and load the ipod3_5.1.1.ios its always say your firmware is not compatible

    my  ipod touch is 3rd gen how can i update my ios from 4.2.1 to 5.1.1 when i shift + restore and load the ipod3_5.1.1.ios its always say your firmware is not compatible

    I suspect you have a 2G iPod. Those can only go to iOS 4.2.1.
    Identifying iPod models
    iPod touch (3rd generation)
    iPod touch (3rd generation) features a 3.5-inch (diagonal) widescreen multi-touch display and 32 GB or 64 GB flash drive. You can browse the web with Safari and watch YouTube videos with Wi-Fi. You can also search, preview, and buy songs from the iTunes Wi-Fi Music Store on iPod touch.
    The iPod touch (3rd generation) can be distinguished from iPod touch (2nd generation) by looking at the back of the device. In the text below the engraving, look for the model number. iPod touch (2nd generation) is model A1288, and iPod touch (3rd generation) is model A1318.

  • My slide presentation (with sound) is done. How can I change one song from another?

    My slide presentation (with songs) is done. How can I change one song from another?

    Do you still have your Aperture Slideshow project? Then open the slideshow and select the one of the green audio file clips in the film strip that you want to replace. Press the "delete" key and drag another audio file from the Media Browser directly onto the slide, where the sound should start.

  • How can i display at  JTextArea from right to left

    how can i display at JTextArea from right to left?
    i try to write setAlignmentX(JTextArea.RIGHT_ALIGNMENT)
    but this not help,
    thanks for help.

    use this
    JTextArea.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);

  • HT204266 how can I update my app with another account?

    how can I update my app with another account?

    kambiz.fakhr wrote:
    how can I update my app with another account?
    Anything Downloaded with a Particular Apple ID is tied to that Apple ID and Cannot be Merged or Transferred to a Different Apple ID
    Apple ID FAQs  >  http://support.apple.com/kb/HT5622

  • How can I watch apple tv from another country?

    How can I watch apple tv from another coutry?

    I live in country A and when I log on to the itunes store I´m automatically connected to that country´s store.But I know that certain films I would like to rent are possible to rent in the US Itunes store. To rent from the US store you have to register an apple id in that store and to do that you have to have a valid billing adress within the US and a valid credit card from the US. Is there any other way I can connect to the US Itunes store from another country?

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How to get a int value from another class method?

    Hi,
    how can I get a value of another class method variable value.
    example,
    class elist
            int a;
         ArrayList<Event> eventArray;
         void addEvent(Event e);
         Event getEvent(int index);
         void removeEvent(int index);
         void orderEventByTime();
    interface Event
         void Command();
    class servo implements Event
         String ip;
         int time = 10;
         void Command();
    class servo_2 implements Event
         String ip;
         int time = 20;
         void Command();
    [\code]
    I want to get the time value in elist variable a; 
    and want to compare each class time?.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    1) this foum provides means to format/tag code, no need to manually add -tags
    2) by default, classname start with a capital letter, method names with a lower case letter
    3) where do you want to get the time value to Elist.a? During addEvent()?
    4) what do you want to do with the time value of each event? Sum all values up to make a an overall sum?
    5) where do you want to compare the time value(s)?
    To put it in one sentence: please be more specific with your description and answer.
    Bye.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can i open the popup from java class

    Hi,
    Please tell me how can i open the popup from java class.
    I am using jdev 11.1.1.7.0
    I have used the below code which works fine in jdev 2.1 but it will have some errors in 11.1.1.7.0.
    Please tell me some way to do this in all jdev versions.
    Bean obj = (Bean)RequestContext.getCurrentInstance.getExternalContext.getPageFlowScope(“obj”);
    Code for hide pop-up
    FacesContext context = FacesContext.getCurrentInstance();
    String popupId = obj.getPopUpBind().getClientId()
    ExtendedRenderKitService service = Service.getRenderKitService(FacesContext.getCurrentInstance(),
    ExtendedRenderKitService.class);
    String hidePopup = "var popupObj=AdfPage.PAGE.findComponent('" + popupId +
    "'); popupObj.hide();";
    service.addScript(FacesContext.getCurrentInstance(), hidePopup);
    Code to Show pop-up
    StringBuffer showPopup = new StringBuffer();
    showPopup.append("var hints = new Object();");
    showPopup.append("var popupObj=AdfPage.PAGE.findComponent('" +
    obj.getPopUpBind().getClientId() + "');popupObj.show(hints);");
    service.addScript(FacesContext.getCurrentInstance(), showPopup.toString());
    Code need to be added in jsff pop tag
    binding="#{pageFlowScope.bean.popUpBind}
    Variable need to be added in Bean.java
    private RichPopup popUpBind;

    Hari,
    Since you're using a non-public build of JDeveloper, you should be using a non-public forum.
    John

  • How can i create proxy service from another proxy on different domain

    i have a demo webservice. it has many operations on proxy service's message flow. How can i create proxy service from demo's wsdl on different domain
    Edited by: fresh man on Jul 1, 2012 11:17 PM

    You can either export the WSDL in a sbconfig.jar and then import this sbconfig.jar in the new domain. Then you can create a new Proxy in new domain based on the WSDL you imported.
    Alternatively, you can open the WSDL in the old domain, copy the text content of WSDL, then open new domain sbconsole and create a new WSDL type resource and paste the content you copied from old domain WSDL here. Then you can create a new Proxy Service based on this WSDL resource you created.
    Although, may I ask why do you need to create this new Proxy Service on a different domain? If you want to create a service similar to existing Proxy Service on different domain, then you can export the existing proxy service along with any dependencies to a sbconfig.jar and them import them in any other domain.
    If you want your new Proxy Service to invoke the existing Proxy on different domain, then you need to create a Business Service in the new domain (calling domain) which can invoke your existing Proxy service in other domain.

  • How can i update my ios from Iphone 3g

    Hello i need your help my iphone has ios 4.2.1 but i need ios 4.3.1 becouse more aps go with ios 4.3.1 i have iphone 3g 16 gb white
    Hallo ich brauche eure Hilfe mein Iphone hat das ios 4.2.1 aber ich brauche das ios 4.3.1 weil viel mehr apps über ios 4.3.1 laufen ich habe das iphone 3g 16 gb weiß
    How can i update?
    Wie kann ich es updaten?
    I´m German but i can speak a little bit english thx
    Ich bin Deutscher kann aber auch ein bisschen Englisch , danke

    Sorry, you can't. iOS 4.2.1 is the end of the line for an iPhone 3G, there are no further updates available. You'll have to purchase a new phone in order to run a higher iOS.

  • How can I see one mac from another mac?

    I have two macs, an imac at home and a MBPro.
    If I have them both at home, how can I see one Mac´s hard drive from another?
    Is this possible? with back to my mac??
    thanks
    J

    Do you have a home network?
    Personal File Sharing: You can connect Macs on a local network with Tiger’s Personal File Sharing, which allows you to mount folders from the sharing Mac on the master Mac—note that the slave Macs do the sharing; the master Mac doesn’t have to. To turn on Personal File Sharing on the slave Mac, do this:
    Open System Preferences.
    In the System Preferences window, click Sharing.
    In the Sharing pane, click Services.
    In the Select a Service to Change Its Settings list, select the Personal File Sharing checkbox.
    Now that the slave Mac has sharing turned on, you can mount it on the master Mac’s Desktop:
    In the Finder, choose Go -> Network.
    In the Network window, select the sharing Mac.
    Click Connect.
    In the Connect to Server window, click Registered User, enter the user account name and password for the sharing Mac, and then click Connect.
    In the window that appears, select the volume that contains the folder you want to sync with, and then click OK.
    LN

Maybe you are looking for

  • HR Abap ques - Process Dynamic Actions in BDC mode

    Hi friends. We are using HR_INFOTYPE_OPERATION to update some infotypes. The problem is that dynamic action does not get triggered as SY-BINPT = 'X' when we use this FM or BDC to update. Now, is there any workaround so that we can process dynamic act

  • HT4623 my phone volume keep flashing on alot after my update 4s

    I update my 4s io6 and now my ringers keeps flashing on and stays on the screen for a long time.  Also I took a picture today and it keep taking pictures with out me pushing the buttons.  Please help

  • Mail is changing settings in preferences!

    Lots of users are exposed to the Mail 3 bug (Leopard) where Mail is randomly changing settings in "Preferences"-"Account"-"Advanced" from "Password" to "APOP". (The visual effect of this bug for the average user is that Mail will promt you for a pass

  • W520 as a second display

    Hi all, is it possible to use the internal display of a W520 as an secondary display of another workstation via displayport? Thanks a lot. Pitti

  • Interim Disk Solution for Enthusiast First Build

    First, let me say that I have benefited greatly from the discussions on these boards. I am an amateur filmmaker planning to build (have built for me) a custom PC along the lines of the great information I've gathered in this forum. I plan to use PP C