Change a J(Component ) propeties from a different class?

Hello,
I've got:
class FirstClass(){
   public JButton btnSend;
   private void SetDisable(){
         btnSend.SetEnable(false);
   FirstClass(){
    // Constructor stuff...
    SetDisable();
class SecondClass(){
   private void SetEnable(){
    /// somehow to enable the first class's buton
}As mentioned, I would like to enable the FirstClass button, which is impossible to do so beacuse the JButton is not static (and can't be) and niether the "Enable" function in the first class...
Help anyone? :-)
Thanks!

class FirstClass(){
   public JButton btnSend;
   private void SetDisable(){
         btnSend.SetEnable(false);
   public FirstClass(){
    // Constructor stuff...
    SetDisable();
    new SecondClass();   // <---- Problem, it asks for another parameter
class SecondClass(){
   private FirstClass firstClass;
   public SecondClass(FirstClass referenceToFirstClass){
      firstClass= referenceToFirstClass;
   Public SecondClass(){
   //Consctructor
   private void setFirstClassButtonEnabled(boolean enabled){
      firstClass.setButtonEnabled(enabled);
}I marked where my problem is...
and Thanks in advance, again! :-)

Similar Messages

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • Updating Jlabel from a different class?

    Hi,
    Im in the middle of developing a program but swing is making it very hard for me to structure my code. The problem is I want to update the text of a Jlable from a different class when a button is pressed. THe event handling is done by a different class than the where the Jlabel is initiated which is why i think it doesnt work. But when the button is pressed it does execute a method from the main class that has the .setText() in it. Why wont the Jlabel update? Thank you

    Thanks for your help but i am still having trouble.
    This is the code from the button handler class
    public void actionPerformed(ActionEvent e)
           if ("btn3_sender".equals(e.getActionCommand()))
                JLabel j = temp2.getlblQuestion();
               j.setText("NEW TEXT");
           This is the code from the main class where the JLabel is created:
    public JLabel getlblQuestion()
        return lblQuestion;
    }How come this does not work??

  • Updating Swing components from a different class

    I would like to use the JTextArea component in a JFrame to display fast updating text from my application. My application is very simple. When the app launches the GUI is created then my application engine would start processing and displaying text data into the GUI. After reading about Thread safety when using Swing components I concluded it would not be a good idea for my app engine class to update the JTextArea class directly using methods such as .append(String).
    I would be grateful for any suggestions on how I should approach updating Swing components from different classes.
    Many Thanks in advance Sean

    Hi
    Why don't you just implement a basic callback method?
    To do this the right way you should probably define a simple Interface that has a public method like updateProcessText(String s). Your swing class then implements this interface, basically forcing it to provide the public method you defined (this is no different than implementing ActionListener, which forces you to define actionPerformed). Secondly modify your processing class, so that it take's a class that implements the interface you just created, as one of the arguments in it's constructor. Lastly assign the argument from your construnctor to a private var - this will enable your processing class to have a handle to your swing class and update it as it pleases.
    This might sound very complex, but it's really simple once you've done it once.

  • Updating JPanel with buttons from a different class

    I have a JPanel in a class that has a gridlayout with buttons in it for a game board. And my problem is that when I want to update a button using setIcon() the button doesn't change in the GUI because the buttons are in a different class. The JPanel is in a Client class and the buttons are in a GamePlugin class. I've tried a bunch of different things but none of them worked or it was way too slow. I'm sure theres an easy way to do it that I'm not seeing. Any suggestions? Heres part of my code for updating the GUI.
    private JPanel boardPanel = new JPanel(); 
    Container cP = getContentPane();
    cP.add(boardPanel, BorderLayout.WEST);
    boardPanel.setPreferredSize(new Dimension(400, 400));
    boardPanel.setLayout(new GridLayout(8, 8));
    cP.add(optionsPanel, BorderLayout.CENTER);
          * Gets the board panel from the selected plugin.
         public void drawGameBoard(GamePlugin plugin) {
              board = (OthelloPlugin)plugin;
              boardPanel = board.getBoardPanel();
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++)
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        board.boardButtons[i][j].setActionCommand("" + i + "" + j);
                        board.boardButtons[i][j].addActionListener(this);
          * This method takes a GameBoard and uses it to update this class' data
          * and GUI representation of the board.
         public void updateBoard(GamePlugin updatedBoard) {
              board = (OthelloPlugin)updatedBoard;
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++) {
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        int cell = board.getCell(i,j);
                        if (cell == OthelloPlugin.PLAYER1){
                             board.boardButtons[i][j].setIcon(black);
                        else if (cell == OthelloPlugin.PLAYER2)
                             board.boardButtons[i][j].setIcon(white);
                        else
                             board.boardButtons[i][j].setText("");
         }

    txp200:
    I agree that a call to validate() , possibly repaint(), should fix your problem. In the class with the panel that the buttons are on, i would create a static repaint method that call panel.repaint(). You can then call that method in your other class. Just make sure u only use methods to change the properties of the button, never make a make a new one, as then you will lose the association with the panel. Hope this helps.
    -- Brady E

  • Problem Using toString method from a different class

    Hi,
    I can not get the toString method to work from another class.
    // First Class Separate file MyClass1.java
    public class MyClass1 {
         private long num1;
         private double num2;
       public MyClass1 (long num1, double num2) throws OneException, AnotherException {
            // Some Code Here...
        // Override the toString() method
       public String toString() {
            return "Number 1: " + num1+ " Number 2:" + num2 + ".";
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        public static void main(String[] args) {
            try {
               MyClass1 myobject = new MyClass1(3456789, 150000);
               System.out.println(myobject);
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
    }My problem is with the System.out.println(myobject);
    If I leave it this way it displays. Number 1: 0 Number 2: 0
    If I change the toSting method to accept the parameters like so..
    public String toString(long num1, double num2) {
          return "Number 1: " + num1 + " Number 2:" + num2 + ".";
       }Then the program will print out the name of the class with some garbage after it MyClass1@fabe9. What am I doing wrong?
    The desired output is:
    "Number 1: 3456789 Number 2: 150000."
    Thanks a lot in advance for any advice.

    Well here is the entire code. All that MyClass1 did was check the numbers and then throw an error if one was too high or too low.
    // First Class Separate file MyClass1.java public class MyClass1 {
         private long num1;
         private double num2;
         public MyClass1 (long num1, double num2) throws OneException, AnotherException {              
         // Check num2 to see if it is greater than 200,000
         if (num2 < 10000) {
                throw new OneException("ERROR!:  " +num2 + " is too low!");
         // Check num2 to see if it is greater than 200,000
         if (num2 > 200000) {
                throw new AnotherException ("ERROR!:  " +num2 + " is too high!");
         // Override the toString() method
         public String toString() {
              return "Number 1: " + num1+ " Number 2:" + num2 + ".";    
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        // Main method where the program begins.
        public static void main(String[] args) {
            // Instantiate first MyClass object.
            try {
               MyClass1 myobject = new MyClass1 (3456789, 150000);
               // if successful use MyClass1 toString() method.
               System.out.println(myobject);
                         // Catch the exceptions within the main method and print appropriate
                         // error messages.
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
             }I am not sure what is buggy. Everything else is working fine.

  • Calling a method from a different class?

    Ok..
    I been trying for hours... but im stumped.
    How can I get this to work?
    (Note: I cut this code down from over 600+ lines of code.. I left in a REALLY raw framework that shows where the basic problem is.)
    public class Client extends JPanel implements Runnable {
    // variable declarations...
        Socket connection;
        BufferedReader fromServer;
        PrintWriter toServer;
        public Client(){
    // GUI creation...
    // Create the login JFrame
        Login login = new Login()
        public void connect(){
        try {
                //Attempt to connect to the server
                connection = new Socket(ip,port);
                fromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                toServer = new PrintWriter(connection.getOutputStream());
                //Launch a thread here to read incoming messages from the server
                //so I dont block on reading
                new Thread (this).start();
        } catch (Exception e) {
            e.printStackTrace();
        public void run(){
            // This keeps reading lines from the server
            String s;
            try {
                //Read messages sent from the server - add them to chat window
                while ((s=fromServer.readLine()) != null) {
                txtChat.append(s);
            } catch (Exception e) {}
        public static void main(String args[]){
            // some init frame stuff
            frame = new JFrame();
            frame.getContentPane().add(new Client(),BorderLayout.CENTER);
         frame.setVisible(true);
    class Login extends JFrame {
        JPanel pane;
        public Login() {
         super("Login");
         pane = new JPanel();
         JButton cmdConnect = new JButton("Connect");
            pane.add(cmdConnect);
         setContentPane(pane);
         setSize(300,300);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         cmdConnect.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ae){
              // I want to connect to the server when this button is pressed.
              // How can I call the connect method in the Client class?
    }

    Your posted code shows Login as an inner class. So one way to solve your problem is.
    1. Make an instance variable to hold the instance. For example, after "PrintWriter toServer;" add "private Client client;"
    2. In the Client constructor, add a line "client = this;"
    3. In the Login actionPerformed(), use "client.connect();"
    Another way is to have Login keep a reference to the Client that created it.
    1. Add an instance variable to Login "private Client client;"
    2. Change the Login constructor "public Login(Client c) {"
    3. Add a line in the constructor "client = c;"
    4. In the actionPerformed() "client.connect();"

  • Using main class's methods from a different class in the same file

    Hi guys. Migrating from C++, hit a few snags. Hope someone can furnish a quick word of advice here.
    1. The filename is test.java, so test is the main class. This code and the topic title speak for themselves:
    class SomeClass
         public void SomeMethod()
              System.out.println(test.SomeOperation());
    public class test
         public static void main(String args[])
              SomeClass someObject = new SomeClass();
              someObject.SomeMethod();
         public static String SomeOperation()
              return "SomeThing";
    }The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.
    Thanks.

    pfiinit wrote:
    The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?Yes you can by using a static import, but I don't recommend it. SomeOperation is a static method of the test class, and it's best to call it that way so you know exactly what your code is doing here.
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.Again, you could use static imports, but again, I don't recommend it. Myself, I use Eclipse and set up its template so that when I type sop it automatically spits out System.out.println(). Most decent IDE's have this capability.
    Also, you may wish to look up Java naming conventions, since if you abide by them, it will make it easier for others to understand your code.
    Much luck and welcome to this forum!

  • Accessing XML data from a different class

    Hi all,
    I have an xml class that loads xml data, I need to access the data from another class. I have imported the xml classinto the new class and created a new instance of it. However when I try to access the xml data it is coming back as null. I understand this is almost certainly because when it is called the xml data hasn't completed it's load. How can I get round this?
    xml class:
    package {
        import flash.xml.*;
        import flash.events.*;
        import flash.net.*
        import flash.display.*
        public class xml extends MovieClip
            public var xmlRequest:URLRequest;
            public var xmlLoader:URLLoader;
            public var xmlImages:XML;
            public function xml()
                xmlRequest = new URLRequest("images.xml");
                xmlLoader = new URLLoader(xmlRequest)
                xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
                xmlLoader.load(xmlRequest);
            private function xmlLoaded(event:Event):void
                trace(xmlLoader.data);
                xmlImages = new XML(xmlLoader.data);
    Thanks in advance

    One of the ways:
    package {
         import flash.xml.*;
        import flash.events.*;
        import flash.net.*
        import flash.display.*
        public class XMLLoader extends EventDispatcher
              public var xmlRequest:URLRequest;
              public var xmlLoader:URLLoader;
              public var xmlImages:XML;
              public function XMLLoader()
              public function loadXML(url:String):void {
                   xmlLoader = new URLLoader()
                   xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
                   xmlLoader.load(new URLRequest(url));
              private function xmlLoaded(event:Event):void
                   trace(xmlLoader.data);
                   xmlImages = new XML(xmlLoader.data);
                   dispatchEvent(event);
    Usage:
    var xmlLoader:XMLLoader = new XMLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
    xmlLoader.loadXML("images.xml"):
    function onXMLLoad(e:Event):void{
         trace(xmlLoader.xmlImages);

  • Problems calling a method from a different class

    Like many programmers, I'm having a go at making my own chat room. All has been going well so far, however I am having trouble calling the method which connects the client to the server, from the method which actually starts the server.
    The method for starting the server:
    public static void serverStart () throws IOException {
            new Thread () {
            public void run() {
                try {
                    ServerSocket serverSock = new ServerSocket (client.serverPort);
                while (true) {
                    Socket serverClient = serverSock.accept ();
                    ChatHandler handler = new ChatHandler(serverClient);
                    handler.start ();
                } catch (IOException ex) {     
                    connectTo.handleIOException(ex);     
            }.start();
            try {
                connectTo.start();
            } catch (IOException ex) {
                connectTo.handleIOException(ex);
        }The part of interest is the "connectTo.start()" line, as this is the one which calls a method in the class connectToMethod which tells the client to connect to this newly started server. Now for the client connection code:
    public synchronized void start () throws IOException {
          if (listener == null) {
              Socket socket = new Socket (client.serverAddr, client.serverPort);
              try {
                  dataIn = new DataInputStream
                          (new BufferedInputStream (socket.getInputStream ()));
                  dataOut = new DataOutputStream
                          (new BufferedOutputStream (socket.getOutputStream ()));
              } catch (IOException ex) {
              socket.close ();
              throw ex;
          listener = new Thread (this);
          listener.start ();
      }Now when the server starts, it should automatically start the connection method "start()" and connect to itself. However I am getting a NullPointerException error at the line "connectTo.start();" from the server code. The server and connection client actually work separately, just not when I try to connect from the server itself. I have tried a few ways of getting around this problem, all without success. If anyone could give some input on what might be wrong, or a possible way to fix it, I'd be very grateful.

    Sorry, connectTo comes from:
    connectToMethod connectTo = new
    connectToMethod();
    That doesn't necessarily mean this variable reference is the same one as in the code where the NullPointerException was thrown though.
    Or the exception was thrown inside the start() method. The runtime isn't lying to you. You have a null reference (pointer) where it says you do.

  • Writing in a Text Area from a different class.

    Hi,
    I need to write some text in a Text Area which is in a class I've call GUI where I handle all the graphic stuff but I need to do it from another class which handles packets that come through a COM port.
    Is there anyway to do that?
    Thanks!

    Thank you! I'll try that but I think I might have problems with that since an instance of the Gui class was already created. I'm using the NetBeans Gui design form wich already makes the code for the Gui and this is what I have public class Gui extends javax.swing.JFrame {
        Connection connection = new Connection();
        /** Creates new form Gui */
        public Gui() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            bnConectar = new javax.swing.JButton();
            cbPuerto = new javax.swing.JComboBox();
            lblPuerto = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            taPuerto = new javax.swing.JTextArea();
            bnPing = new javax.swing.JButton();
            jMenuBar1 = new javax.swing.JMenuBar();
            mArchivo = new javax.swing.JMenu();
            miNuevoP = new javax.swing.JMenuItem();
            miCargarP = new javax.swing.JMenuItem();
            miGuardarP = new javax.swing.JMenuItem();
            miSalir = new javax.swing.JMenuItem();
            mEdicion = new javax.swing.JMenu();
            mMonitorizacion = new javax.swing.JMenu();
            miMonON = new javax.swing.JMenuItem();
            miMonOFF = new javax.swing.JMenuItem();
            miPing = new javax.swing.JMenuItem();
            miConfig = new javax.swing.JMenuItem();
            mAyuda = new javax.swing.JMenu();
            miAcerca = new javax.swing.JMenuItem();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Monitorizaci?n");
            bnConectar.setFont(new java.awt.Font("Tahoma", 1, 11));
            bnConectar.setText("Conectar");
            bnConectar.setToolTipText("Conecta con el puerto seleccionado.");
            bnConectar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bnConectarActionPerformed(evt);
            cbPuerto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            lblPuerto.setFont(new java.awt.Font("Tahoma", 1, 14));
            lblPuerto.setText("Puerto");
            taPuerto.setColumns(20);
            taPuerto.setRows(5);
            jScrollPane1.setViewportView(taPuerto);
            bnPing.setFont(new java.awt.Font("Tahoma", 1, 11));
            bnPing.setText("Ping");
            bnPing.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bnPingActionPerformed(evt);
            mArchivo.setText("Archivo");
            miNuevoP.setText("Nuevo Proyecto");
            mArchivo.add(miNuevoP);
            miCargarP.setText("Cargar Proyecto");
            mArchivo.add(miCargarP);
            miGuardarP.setText("Guardar Proyecto");
            mArchivo.add(miGuardarP);
            miSalir.setText("Salir");
            mArchivo.add(miSalir);
            jMenuBar1.add(mArchivo);
            mEdicion.setText("Edici?n");
            jMenuBar1.add(mEdicion);
            mMonitorizacion.setText("Monitorizaci?n");
            miMonON.setText("Monitorizaci?n ON");
            mMonitorizacion.add(miMonON);
            miMonOFF.setText("Monitorizaci?n OFF");
            mMonitorizacion.add(miMonOFF);
            miPing.setText("Ping");
            mMonitorizacion.add(miPing);
            miConfig.setText("Configuraci?n");
            mMonitorizacion.add(miConfig);
            jMenuBar1.add(mMonitorizacion);
            mAyuda.setText("Ayuda");
            miAcerca.setText("Acerca");
            mAyuda.add(miAcerca);
            jMenuBar1.add(mAyuda);
            setJMenuBar(jMenuBar1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblPuerto)
                            .addGap(17, 17, 17)
                            .addComponent(cbPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bnPing)
                            .addComponent(bnConectar)))
                    .addGap(45, 45, 45)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(287, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cbPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblPuerto))
                            .addGap(18, 18, 18)
                            .addComponent(bnConectar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                            .addComponent(bnPing)
                            .addContainerGap(172, Short.MAX_VALUE))))
            pack();
        }// </editor-fold>
        private void bnConectarActionPerformed(java.awt.event.ActionEvent evt) {                                          
            try{
               connection.connect();
            }catch (XBeeException e){
        private void bnPingActionPerformed(java.awt.event.ActionEvent evt) {                                      
            try{
               connection.ping();
            }catch (XBeeException e){
        * @param args the command line arguments
        public static void main(String args[]) throws Exception, InterruptedException {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                   new Gui().setVisible(true);
        }Would that be a problem?
    Thanks again!

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • Refreshing AbstractTableModel from different class...

    Hi there ppl
    Anybody know how to call:
    model.fireTableStructureChanged()
    from a different class? when i try i get a compiler error saying that i cannot reference a non-static variable from a staic content.
    the first jframe holds a jtable that displays the model which consists of data from a db. the second jframe (which resides in another class) has a jtextfield which when submitted will update the db, therefore the db results need to be updated and then the model needs to be updated via
    model.fireTableStructureChanged()
    but from a different class. Is this possible and if so can somebody explain to me how?
    Thanks fellow Javites.

    Thanks for replying...
    The TrainServiceFrame.updateStationTable() exists within the TrainServiceFrame class and is intended to update the stationModel object when called from another class (which will be the NewTrainStationFrame class).
    <code>
         public static void updateStationTable() {
              stationModel.fireTableStructureChanged();          
    </code>
    The second code fragement is from the second class NewTrainStationFrame (which is not a subclass) which contains a jframe, jtextfield and a button. the method call to the stationModel(stationModel = AbstractTableModel) is done via: TrainServiceFrame.updateStationTable() when the submit button is clicked sending the string to a method ( addNewStation(newStation); )which updates the db.
    <code>
    button.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                        newStation = newStationField.getText();
                        addNewStation(newStation);
    // this would retrieve the updated db results + store in a TreeSet object
    // TrainServiceFrame.getTrainStations();
                        TrainServiceFrame.updateStationTable();
    </code>
    I have just noticed something that is missing which when attempted to fix resulted in the same problem. there should also be a method called to retrieve the updated db, but as this is from a static context yet again i fall into the same ditch as the variables that store these db results are non-static and exist within the TrainStationFrame class.
    Is the solution simply to change these relevent variables and methods that are to be called from another class, so that they are all static?

  • Display from non-MIDlet class?

    Display from non-MIDlet class?
    I havel a method in my main MIDlet that flashes up a message as an Alert:
    public void doAlert(String sAlertText) {
           Alert alSending;
           alSending = new Alert(null, sAlertText, null, AlertType.INFO);
           alSending.setTimeout(3000);
            m_display.setCurrent(alSending);
        }m_display is declared and instantiated in the main MIDlet:
    public class Boss extends MIDlet implements CommandListener {
            public static Display m_display;
            public Boss() {       /** Constructor*/
                    m_display = Display.getDisplay( this );
    }Now when I try to call this from another class:
         new Boss().doAlert("Eat lead, Bambi!");I get: "SecurityException: Application not authorized to access the restricted API". The same happens if I try to use a reference to a MIDlet, rather than to a Display. Apparently, you can't instantiate a MIDlet from with another MIDlet / class.
    So, how do you obtain a reference to the currently-running MIDlet or its Display from a different class?

    Thanks for your reply, but i finally solved it. I found a way of getting a reference to my MIDlet, so i had the control of its display.
    Maybe it could be a good idea having some classes to write to the cellular's screen without being a MIDlet, like System.out.* classes in traditional Java.
    See you.
    David.

  • Changing tab name in one component that used in different applications -FPM

    Hi gurus,
    I have an FPM component configuration, which have different tabs.
    This component i have used in different applications.
    I just want to know how can I dynamically change the name of one tab in different applicatins?
    I want to change only the tab name. content in the tab is same.
    For eg. If I open a Bid from Rfx, it should show "Rfx Information" as one tab name. But if i open a bid from Auction, it should show 'Auction Information'.
    Content in this tab is same.
    Is there any way to do that? Or shall I create different component config. for bid to use in Auction application  and another one for RFx application?
    Thanks,
    Poduval

    Hi, 3Sherill3. This may help:
    http://www.macupdate.com/info.php/id/16620

Maybe you are looking for

  • Windows Installer error message when installing or removing iTunes

    When I try to either upgrade, install, or remove iTunes, I get this message: "The Windows Installer Service could not be accessed. This can occur if you are running Windows in safe mode, or if the Windows Installer is not correctly installed. Contact

  • Centering Text within JLabel

    I am trying to figure out a way to center the text within a JLabel. I trying to set a specific size of the label, and then center the text in the very middle (horizontally) of that label. I have tried many different methods from this forum and other

  • Reg: POST GOODS ISSUE/Serial number.

    Dear Friends, we are facing one issue , with respect PGI. We are producing with serial number. In MMBE i can find sales order stock , which has serial Number. But at the time of Delivery i am getting an message Stock is not suitable for movement type

  • E-Mail Notification with https link to new item

    Hi all, we have a vibe 3.4 system and want to use the e-mail notification features so all in our team will get those status messages. Generally this feature works and we get mail. The problem is that the links in the mail to the new item starts with

  • No locales

    Perhaps this is a silly question but: Is there any kind of "risk" in installing packages (or something else "system related") while having no locales generated? I'm always using the "install from existing Linux" way to install Arch, basically using p