Results 1 to 5 of 5
  1. #1
    kwaspl is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default Accessing class defined within a constructor

    Is there a way to access a class defined within a constructor and if their isn't how can i change value of specific cell from the main method.

    PHP Code:
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    
    public class SimpleTableDemo extends JPanel {
      public SimpleTableDemo() {
            super(new GridLayout(1,0));
            String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
            };
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
            JScrollPane scrollPane = new JScrollPane(table);
            add(scrollPane);
    //------------------------------------------
            class wewn
            {
            public void mma()
            {
             table.setValueAt(new String("qqq"),1,1); 
            }
            }
    //-------------------------------------------
        }
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("SimpleTableDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            SimpleTableDemo newContentPane = new SimpleTableDemo();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
    
        }
        public static void main(String[] args) {
        SimpleTableDemo fff = new SimpleTableDemo();
        fff.createAndShowGUI();
        }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,334
    Blog Entries
    7
    Rep Power
    20

    Default

    Your class wewn (funny name) is local to the constructor of the outer class, just like a local variable: it's gone when your constructor terminates; you don't create an object of that class in your constructor so it's basically a waste of space.

    kind regards,

    Jos

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    kwaspl, you have asked a new question before answering replies in your previous thread/question (Problem with updating JTable), and this will not encourage people to help you here. Why help if you already know that your answer will be ignored? You may wish to fix this.

  4. #4
    kwaspl is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default

    I'm sorry but I'm just so frustrated and no one gives me a strait answer. Maybe i don't explain it well but i create a JTable in one class data to this table are taken from a array. Now in a different window i make some changes to those variables and i can't to make that table to update those variables after i done. I'm working on this problem for three days. Usually i don't look for help.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by kwaspl View Post
    I'm sorry but I'm just so frustrated and no one gives me a strait answer.
    We're not trying to hide anything from you. If you don't understand a particular about anything we have posted, then ask about it. But in the very least at least acknowledge that you have read a reply and appreciate any effort made in posting it, whether or not you understand it.

    Maybe i don't explain it well but i create a JTable in one class data to this table are taken from a array. Now in a different window i make some changes to those variables and i can't to make that table to update those variables after i done. I'm working on this problem for three days. Usually i don't look for help.
    Your best bet may be to create and post an SSCCE (see the link as it will explain all).

    Note that much of your problems seem to stem not from Swing issues but from basic Java issues. You may wish to back off from Swing a bit and hit the more basic tutorials first.

Similar Threads

  1. Creating a Defined Class with Member Functions
    By New2Java in forum New To Java
    Replies: 6
    Last Post: 08-05-2009, 09:05 PM
  2. How to call defined java class in Jsp
    By asheeshiit in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-04-2009, 04:21 AM
  3. [SOLVED] Accessing private constructor
    By piyu.sha in forum New To Java
    Replies: 2
    Last Post: 10-06-2008, 05:45 AM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •