Create a new instance of a class without starting new windows.

I've a class with basic SWING functions that displays an interface. Within this class is a method which updates the status bar on the interface. I want to be able to reference this method from other classes in order to update the status bar. However, in order to do this, I seem to have to create a new instance of the class which contains the SWING code, and therefore it creates a new window.
Can somebody give me an example, showing how I might update a component on the interface without a new window being created.
Many thanks in advance for any help offererd.

I've a class with basic SWING functions that displays
an interface. Within this class is a method which
updates the status bar on the interface. I want to be
able to reference this method from other classes in
order to update the status bar. However, in order to
do this, I seem to have to create a new instance of
the class which contains the SWING code, and
therefore it creates a new window.
Can somebody give me an example, showing how I might
update a component on the interface without a new
window being created.
Many thanks in advance for any help offererd.It sounds like you have a class that extends JFrame or such like and your code must be going
           Blah  test = new Blah();
            test.showStatus("text");Whereas all you need is a reference to that Classs.
So in your class with basic SWING functions that displays an interface.
You Might have something like this
          // The Label for displaying Status messages on
          JLabel statusLabel = new JLabel();
          this.add( statusLabel , BorderLayout.SOUTH );What you want to do is provide other Classes a 'method' for changing your Status Label, so in that class you might do something like:
      Allow Setting of Text in A JLabel From various Threads.
     And of course other classes......
     The JLabel statusLabel is a member of this class.
     ie defined in this class.
    @param inText    the new Text to display
   public void setStatusText( String inText )
                final String x = inText;
                SwingUtilities.invokeLater( new Runnable()
                          public void run()
                                   statusLabel.setText( x );
  }You still need a reference to your first class in your second class though.
So you might have something like this:
        private firstClass firstClassReference;        // Store Reference
        public secondClass(  firstClass  oneWindow )
                      // create whatever.........
                     this.firstClassReference = oneWindow;
// blah blah.
      private someMethod()
                        firstClassReference.setStatusText( "Hello from Second Class");
    }Hope that gives you some ideas

Similar Messages

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • Do I have to buy Lion or snow lepoard or is there a way to updated from OS X 10.4.11?? I have a new ipod that will not work without the ne itunes, but the new itunes will not install without a newer vesion of Max OS X. Help please :)

    Do I have to buy Lion or snow lepoard or is there a way to updated from OS X 10.4.11?? I have a new ipod that will not work without the ne itunes, but the new itunes will not install without a newer vesion of Max OS X. Help please

    Need to know your Mac model. If it's a PowerPC, the max OS is Leopard 10.5.x. If it's an Intel procesor, you can upgrade to Snow Leopard (for $29) & later to Lion.
    *Mac OS X 10.5 Leopard installation system requirements*
    http://support.apple.com/kb/TA24950
    Leopard is no longer available at the Apple Store *but may be available by calling Apple Phone Sales @ 1-800-MY-APPLE (1-800-692-7753)*.
    Installing Mac OS X 10.5 Leopard
    http://support.apple.com/kb/HT1544
    Mac OS X 10.5 Leopard Installation and Setup Guide
    http://manuals.info.apple.com/en/leopard_install-setup.pdf
    After you install the base 10.5, download & install the 10.5.8 combo update at http://support.apple.com/downloads/Mac_OS_X_10_5_8_Combo_Update
     Cheers, Tom

  • Why when I register a new instance of app ias6, the File - New - Server... has no response

    Why when I register a new instance of app ias6, the File -> New -> Server... has no response

    Contact iTunes support : http://www.apple.com/support/itunes/contact/

  • Creating a new instance of a class within a superclass

    I have a class with 2 subclasses and in the top classs I have a method that needs to create a new instance of whihc ever class called it.
    Example:
    class Parent
         void method()
              addToQueue( new whatever type of event is calling this function )
    class Child1 extends Parent
    class Child2 extends Parent
    }What I mean is , if Child1 calls the method then a new Child1 gets added to the queue but if Child 2 calls method a new Child 2 gets added to the queue. Is this possible?
    Thanks.

    try
    void method()
    addToQueue(this.getClass().newInstance());
    }Is this what you want ?Won't that always add an object of type Parent?
    no if we invoke this method on the child object...
    we currently dun know how op going to implement the addToQueue()
    so... just making my guess this method will always add to same queue shared among
    Parent and it's childs......

  • How do I create an genericized instance of this class?

    Hi, I'm having trouble creating a proper generic instance of this class that I wrote. The class type is cyclic dependant on itself.
    public class MyClass<T extends MyClass<T>>
    I can create an instance like this:
    MyClass<?> class = new MyClass();But I would be mixing raw types and generic types.
    Is there anyway to create a proper generic instance of MyClass?
    Thanks a lot
    -Cuppo

    Ah thanks georgemc,
    your solution will certainly work.
    If i may ask your opinion of something...
    MyClass is designed such that the type parameter should always be the same as the class itself. It's kinda a hack to get the subclass type from the superclass.
    so a hierarchy looks something like this:
    class MyClass<T extends MyClass<T> >
    class SubClass<T extends SubClass<T>> extends MyClass<T>
    class FinalSubClass extends SubClass<FinalSubClass>So ideally i would want something like:
    MyClass m = new MyClass<MyClass>();
    (which is not possible)
    is there a way to get around this?
    -Cuppo

  • Unable to make a new instance of a class?

    Why can't I make a new instance of this object?
    This doesn't work:
            static void generateConfirmationDialog(String s1, String s2,
                String s3)
                int optionConfirmation = JOptionPane.showConfirmDialog(null,
                    "Confirm inputs: \n" +
                    "\n1: " + s1 +
                    "\n2: " + s2 +
                    "\n3: " + s3,
                    "Input Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
                if (optionConfirmation == JOptionPane.YES_OPTION)
                    //A new instance of an object.
                    //Class UserInterface
                    //Inner Class FileChooser
                    UserInterface.FileChooser fc = new
                        UserInterface.FileChooser.FileChooser();
                else if (optionConfirmation == JOptionPane.NO_OPTION)
                    //Returns the user to the main menu, with inputs intact.
            }Here's that class:
        public class FileChooser extends JFrame
            FileChooser()
                JFileChooser filechooser = new JFileChooser();
                int returnValue = filechooser.showDialog(this, "Upload");
                //Not done yet, but it should be able to display it
        }But this works:
        public static void main(String args[])
            UserInterface menu = new UserInterface();
        }

    1. Does class FileChooser need direct access to any nonstatic member variables or methods in the enclosing class (by your claim UserInterface)?
    If not, then just make the nested class static by:public static class FileChooser extends JFrame
        // body
    }note the static qualifier in the class definition. People frequently make inner classes where static nested classes would do equally as well or even better. Only if the nested class is "attached" to the instance is it necessary to make it non-static.
    2. If so, does the generateConfirmationDialog() have to be static?
    If not, simply remove the static qualifier from the method.
    3. If so, you will have to pass the instance created in your main() method to the method and use it to instantiate the inner class. The syntax isUserInterface menu = new UserInterface();
    FileChooser fc = menu.new FileChooser();4. Is there some reason you can't just use a filechooser from Swing?

  • Class not registered Exception while initializing a new instance of SpeechRecognizer Class

    Hi,
    in my Windows 8.1 Store App with HTML/Javascript I want to use Bing Speech Recognition Control.
    But when I call the contructor of Bing.Speech.Recognizer Class with the language and the authorization Parameters a WinRT "Class not registered" error occurs.
    What could be the reason for this problem?
    I am using Visual Studio 2013.4 by the way.
    Thanks in advance.

    You need to follow all the steps here:
    https://visualstudiogallery.msdn.microsoft.com/521cf616-a9a8-4d99-b5d9-92b539d9df82
    Jeff Sanders (MSFT)
    @jsandersrocks - Windows Store Developer Solutions
    @WSDevSol
    Getting Started With Windows Azure Mobile Services development?
    Click here
    Getting Started With Windows Phone or Store app development?
    Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

  • Why is it that sometimes when I use my middle mouse button to click on a link to open it in a new tab I will have it open it in an entirely new instance of Firefox instead of a new tab?

    Occasionally when I click on a link with my middle mouse button, instead of opening the page in a new tab, it will open a new instance of Firefox.
    I've looked through some of the settings and I wasn't able to find anything. It really gets to be bothersome at times because I prefer things to be in tabs instead of a new browser.

    It's not specific sites. I can middle-click on the same link 50 times and it will open it in a new tab 45 times and 5 of those times, it will randomly open it in an entirely new window. I don't know what's causing this.
    It happens so randomly that I don't know how to pin-point what it could be.

  • I need to transition my 1st Generation Apple TV from an older instance of iTunes to a new instance of iTunes on my brand new Mac... How do I "switch" from one instance of iTunes to another? How do I get the 5 Digit Code Network to come back on my Screen?

    I need to transition my 1st Generation Apple TV from an older instance of iTunes on my iBook to a new instance of iTunes on my new Mac... How do I get the 5 digit Network code to come back? Is there anyway for 1st Generation Apple TV to be synched to two instances of iTunes or do I have to choose one or the other? I appreciate any advice or suggestions. Thanks!

    The 5 digit code is every time different. That does not matter. Just integrate every device into your network.
    You can connect many computers to Apple TV but syncronisation works exactly with one computer. That's why I use "streaming". But you can sync one computer, then another, and so on. The content on your Apple TV is the content from your computer that has synced last. But you can not mix it.
    The new Apple TV has no syncronisation. Everything is streamed,
    Regards,
    Torsten,
    Germany

  • New administrator name and password without Start Up Drive

    I recently seperated from my partner but got to keep the family MacBook Air
    However, my partner set up the orginal administrator name and password and won't provide the details. He also won't supply the Start Up Drive which apparently I could use to do this if I had it.
    I am not very techy - is there a relatively easy way that I can set up a new administrtor name and passowrd without loosing the information I have on the computer?
    Thanks

    BumpkinBelles wrote:
    I recently seperated from my partner but got to keep the family MacBook Air
    However, my partner set up the orginal administrator name and password and won't provide the details. He also won't supply the Start Up Drive which apparently I could use to do this if I had it.
    I am not very techy - is there a relatively easy way that I can set up a new administrtor name and passowrd without loosing the information I have on the computer?
    Thanks
    Try this:
    http://osxdaily.com/2011/08/24/reset-mac-os-x-10-7-lion-password/

  • New instances of main class

    Hi People.
    I'm currently programming a toolbox of applications in Java - each tool is a main program in its own right (i.e. has main method). I'm also programming an organiser which has buttons, which will (eventually) run the main programs i have already mentioned 'on demand'. I've tried using ClassLoader etc. but keep getting errors (see below). Does anyone have a better solution, please? Links to helpful sites will be much appreciated!
    By the way, i'm fairly new to Java so be gentle! :)
    Cheers, folks.
    ERRORS I GET WHEN USING CLASSLOADER (and i'm 100% sure i've got the file name and directory correct):
    java.io.FileNotFoundException: (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:64)
    at java.io.FileReader.<init>(FileReader.java:38)
    at TestClass.main(TestClass.java:9)

    Ok now I think you have a fundamental flaw in your design, and also your understanding of object oriented programming.
    Here's what I think you want to achieve:
    -A series of components which can be accessed in two ways - either independently through running "java classname" on them, and also through a container which lets you access them via buttons.
    This is not a hard problem, and here is my (simplified) solution in code:
    File: Component1.java
    public class Component1 extends JFrame{
    //do some stuff in here specific to this component
    public static void main(String[] args){
      Component1 comp1 = new Component1();
      comp1.show();
    }========================================
    File: Component2.java
    public class Component2 extends JFrame{
    //do some stuff in here specific to this component
    public static void main(String[] args){
      Component2 comp2 = new Component2();
      comp2.show();
    }========================================
    File: Container.java
    public class Container extends JFrame{
    public Container(){
      //get a reference to the components
      Component1 comp1 = new Component1();
      Component2 comp2 = new Component2();
    //Button click listener code
    public void onClick(Component comp){
      comp.show();
    //do some stuff in here specific to this component
    public static void main(String[] args){
      Container cont = new Container();
      cont.show();
    }Ok so I simplified it a lot and missed out all the button listener stuff (plus the design would be a lot nicer using interafces for the components...but one step at a time!) but it should show you how main methods interact with classes in java.
    Please reply if you still dont understand, or this is wrong!

  • New install of PSE7 won't start on Windows XP Pro -- Part Two

    As Barbara Brundage suggested in an earlier thread. I unistalled PSE 7; paused Kaspersky Internet Security program; and reinstalled from the original CD. The installation process (again) completed with apparent success. Nevertheless, the program will not load. It generates the same error messages as before:
    Error Signature
    AppName: photoshop elements 7.0.exe AppVer: 7.0.0.0 ModName: adobelmlnhr_libfnp.dll ModVer: 11.5.0.0 Offset: 00090804
    Viewing "technical information about the error report" takes me to a lengthy screen and a reference to "C:\DOCUME~1\David\LOCALS~1\Temp\4f46_appcompat.txt" That file is very short:
    0 Photoshop Elements 7.0.0.0 Log (5) started 2009-01-06 20:16:05.950
    0 (+ 0) Windows OS Version as reported by Qt: 0x30
    47 (+ 47) Desktop Resolution: 1024 x 768 Depth: 32
    47 (+ 0) RegisterConnect matched
    The "Error Report Contents" lists "information about your process [that] will be reported." Unfortunately, I cannot copy and paste it into this message. The "Exception Information" is quite brief, however, and I re-type it below:
    Code: 0xc0000005 Flags: 0x00000000
    Record: 0x0000000000000000 /addressL 0x0000000001770804
    I am running Windows XP Pro with Service Pack 3. My CPU is an AMD Athlon 64 3500+ = 2.21GHz. SysInfo reports 2.93GB of RAM.
    Any other suggestions?

    The module adobelmlnhr_libfnp.dll appears to be related to the Adobe licensing, so perhaps you need to install the licensing patch, step 4 below:
    http://www.johnrellis.com/psedbtool/photoshopelements-6-7-faq.htm#_Install_the_licensing-s ervice
    If that doesn't work, try Adobe's generic troubleshooting steps for installation problems:
    http://www.johnrellis.com/psedbtool/photoshopelements-6-7-faq.htm#_Try_Adobes_generic

  • Can't create new instance of class in servlet.

    I'm running Tomcat 5.5 and am trying to create a new instance of a class in a servlet. The class is an Apache Axis (1.4) proxy for a Web Service.
    Is there any particular reason this is happening, and any way to fix it?
    The stack trace is as follows:
    WARNING: Method execution failed:
    java.lang.ExceptionInInitializerError
         at org.apache.axis.utils.Messages.<clinit>(Messages.java:36)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:184)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.access$200(EngineConfigurationFactoryFinder.java:46)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder$1.run(EngineConfigurationFactoryFinder.java:128)
         at java.security.AccessController.doPrivileged(Native Method)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:113)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:160)
         at org.apache.axis.client.Service.getEngineConfiguration(Service.java:813)
         at org.apache.axis.client.Service.getAxisClient(Service.java:104)
         at org.apache.axis.client.Service.<init>(Service.java:113)
         at server.proxies.webservicex.net.stockquote.StockQuoteLocator.<init>(StockQuoteLocator.java:12)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)

    Of course there's a particular reason it's happening. Nothing in a computer happens unless it's for a particular reason. You question ought to be what is that reason.
    Well, I don't know what it is. The class org.apache.axis.utils.Messages threw some kind of exception when it was being loaded, because <clinit> means "class initialization" in a stack trace. That would most likely be in a static initializer block in that class. I expect it is because of some mis-configuration in your system, but you'd have to read and understand the apache code to find out what. Or maybe ask over at the Axis site, where there might be a forum or a mailing list.

  • Create multiple instances of same class but with unique names

    Hi,
    I'm creating an IM application in Java.
    So far I can click on a user and create a chat session, using my chatWindow class. But this means I can only create one chatWindow class, called 'chat'. How can I get the application to dynamically make new instances of this class with unique names, for examples chatWindowUser1, chatWindowUser2.
    Below is some code utlising the Openfire Smack API but hopefully the principle is the clear.
        private void chatButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
            int selectedUserIndex = rosterList.getSelectedIndex();
            String selectedUser = rostAry[selectedUserIndex].getUser();
            System.out.println("Chat with: " + selectedUser);
            if (chatBox == null) {
                JFrame mainFrame = CommsTestApp.getApplication().getMainFrame();
                chatBox = new CommsTestChatBox(mainFrame,conn,selectedUser);
                chatBox.setLocationRelativeTo(mainFrame);
            CommsTestApp.getApplication().show(chatBox);
    }  

    yes, an array would work fine, just realize that by using an array, you're setting an upper bound on the number of windows you can have open.
    As for unique names, if you mean unique variable name, you don't need one. The array index serves to uniquely identify each instance. If you mean unique title for the window, set that however you want (username, index in array, randomly generated string, etc.). It's just a property of the window object.

Maybe you are looking for

  • Can't locate files in library

    i foolishly copied my existing itunes folder from c: drive to an external hard drive.and then even more foolishly deleted the old itunes folder from the c: drive, as needed more space. sadly now when i open itunes, i can see all the tracks, playlists

  • Virtual PC 7 and iPod

    I am trying to use Windows 2000 and my iPod to format to windows iPod but VPC7 will not let me use my ipod when I usb it to VPC it goes pass and mounts on my mac. I tried reformat without no iPod OS and still does not load on my VPC. Is there a trick

  • Wired to wireless problem

    Having a problem getting our wired devices to see the wireless devices on our network. Here is our setup. BEFCMU10 | RV042 |.........\ SR216 WRT54GL All of our wired connections go through the SR216 and the WRT54GL hooks up to the RV042 directly as w

  • How do I add apps to the iCloud backup

    I have iCloud backup up turned on and have purchased additional space to use. However the apps selected by the system do not include the ones I want. In fact it is not the whole system at all. How can I modify this please

  • IPhone 3GS with iOS 5.1 ,no GPS, weak wifi, no iMsg

    Soon after  I upgraded my phone to iOS 5.0 iMsg quit working, the GPS quit working, and it will barely pick up a wifi signal.  I have now upgraded to iOS 5.1 and the same features are still not working.  As for the GPS I get the triangulated location