Accessing method of parent from instanced class

Heyo!
I don't know if this makes sense. But I can't figure out another way to do it. Hell, I can't even figure this out. :P
So. I've got this class:
        JPanel cp = new JPanel();
     JPanel menuScreen = new egMenuScreen();
     JPanel newGame = new egNewGameScreen();
     public EscapeGravityUI() {
          // Create toolkit and get screen size
          Toolkit toolkit = getToolkit();
          Dimension size = toolkit.getScreenSize();
          // Set size, title and close operation on main game window
          setSize(1024, 768);
          setTitle("Escape Gravity");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          // Remove border
          setUndecorated(true);
          // Instructions for centering game window
          setLocation(size.width/2 - getWidth()/2,
               size.height/2 - getHeight()/2);
          // Create JPanel and add to JFrame
          cp = menuScreen;
          getContentPane().add(cp);
          // Set KeyListener so we can close window in fullscreen
          this.addKeyListener(new KeyAdapter() {
               public void keyPressed(KeyEvent e) {
                    if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                         System.exit(0);
                         //TODO add nice code for confirming exit
     public void changeScreen(String np) {
          getContentPane().remove(cp);
          if(np == "egngs") {
               JPanel p = new egNewGameScreen();
          getContentPane().add(p);
          repaint();
     }This class is supposed to be a "holder" for diffrent screens in my game. Every screen represented by a JPanel.
in egMenuScreen that looks like this:
public class egMenuScreen extends JPanel {
     public egMenuScreen() {
          // Setup the menu screen
          setBackground(Color.white);
          setSize(1024, 768);
          setLayout(null);
          setFocusable(false);
          // Create menu buttons
          JButton newGame = new JButton("New Game");
          newGame.setBounds(getWidth()/2-60, 60, 120, 30);
          newGame.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    super.changeScreen("egngs");
          JButton loadSaved = new JButton("Load Saved");
          loadSaved.setBounds(getWidth()/2-60, 100, 120, 30);
          loadSaved.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    System.out.println("Load Saved");
          JButton options = new JButton("Options");
          options.setBounds(getWidth()/2-60, 140, 120, 30);
          options.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    System.out.println("Options");
          JButton quit = new JButton("Quit");
          quit.setBounds(getWidth()/2-60, 180, 120, 30);
          quit.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    System.out.println("Quit");
                    System.exit(0);
          // Add buttons to JPanel
          this.add(newGame);
          this.add(loadSaved);
          this.add(options);
          this.add(quit);
}What I want to do is to change that egMenuScreen to another JPanel class that holds the other screen. I figured I needed to do that from the JFrame (EscapeGravityUI). So the method changeScreen() is supposed to handle that. However I don't know how to run that method from within that instanced JPanel class... does that even make sense?
I'd really appriciate any help!
Peace

Styrisen wrote:
I looked at CardLayout but that looks like it needs to always have the buttons visible. Huh??
I may be wrong, Very
but I want to change the entire screen and as I saw it that wasn't possible with card layout!You're not reading the same stuff that I'm reading.
Here's a simple seizure-inducing program program that uses CardLayout to change a JPanel that fills the entire JFrame. Each card is simply a JPanel of random color with a label at the top and a red circle of increasing size. The cards are swapped by way of a Swing Timer:
import java.awt.BasicStroke;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
class CardLayoutFun4 extends JPanel
    private static final int DELAY = 100;
    private static final int CARD_COUNT = 180;
    private CardLayout cardlayout = new CardLayout();
    private Timer timer = new Timer(DELAY, new ActionListener()
        public void actionPerformed(ActionEvent e)
            cardlayout.next(CardLayoutFun4.this);
    public CardLayoutFun4()
        setLayout(cardlayout);
        setPreferredSize(new Dimension(1024, 768));
        addCards();
        timer.start();
    private void addCards()
        Random random = new Random();
        for (int i = 0; i < CARD_COUNT; i++)
            final int index = i;
            JPanel cardPanel = new JPanel()
                private final double diameter = 600 * (index + 1) / CARD_COUNT;
                protected void paintComponent(Graphics g)
                    super.paintComponent(g);
                    Graphics2D g2 = (Graphics2D) g;
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
                    Stroke oldStroke = g2.getStroke();
                    g2.setStroke(new BasicStroke(5));
                    g2.setPaint(Color.red);
                    g2.draw(new Ellipse2D.Double(20, 80, diameter, diameter));
                    g2.setStroke(oldStroke);
            cardPanel.setBackground(new Color(
                    random.nextInt(128),
                    random.nextInt(128),
                    random.nextInt(128)));
            cardPanel.add(new JLabel(String.valueOf(i)));
            add(cardPanel, String.valueOf(i));
    private static void createAndShowUI()
        JFrame frame = new JFrame("CardLayoutFun4");
        frame.getContentPane().add(new CardLayoutFun4());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
            public void run()
                createAndShowUI();
}Edited by: Encephalopathic on Jan 19, 2008 8:06 PM

Similar Messages

  • OOABAP-How to access the protected methos from a class

    How to access the protected methos from a class..There is a built in class..For tht class i have created a object..
    Built in class name : CL_GUI_TEXTEDIT
    method : LIMIT_TEXT.
    How to access this..help me with code

    hi,
    If inheritance is used properly, it provides a significantly better structure, as common components only
    need to be stored once centrally (in the superclass) and are then automatically available to subclasses.
    Subclasses also profit immediately from changes (although the changes can also render them invalid!).
    Inheritance provides very strong links between the superclass and the subclass. The subclass must
    possess detailed knowledge of the implementation of the superclass, particularly for redefinition, but also in
    order to use inherited components.
    Even if, technically, the superclass does not know its subclasses, the
    subclass often makes additional requirements of the superclass, for example, because a subclass needs
    certain protected components or because implementation details in the superclass need to be changed in
    the subclass in order to redefine methods.
    The basic reason is that the developer of a (super)class cannot
    normally predict all the requirements that subclasses will later need to make of the superclass.
    Inheritance provides an extension of the visibility concept: there are protected components. The visibility of
    these components lies between that of the public components (visible to all users, all subclasses, and the class itself), and private (visible only to the class itself). Protected components are visible to and can be used by all subclasses and the class itself.
    Subclasses cannot access the private components  particularly attributes) of the superclass. Private
    components are genuinely private. This is particularly important if a (super)class needs to make local
    enhancements to handle errors: it can use private components to do this without knowing or invalidating
    subclasses.
    Create your class inse24 and inherit this CL_GUI_TEXTEDIT
    class in yours. You can then access the protected methods.
    Hope this is helpful, <REMOVED BY MODERATOR>
    Edited by: Runal Singh on Feb 8, 2008 1:08 PM
    Edited by: Alvaro Tejada Galindo on Feb 19, 2008 2:19 PM

  • Method not accessible from other classes

    Hi,
    I ve defined a class and would like to create an instance of it from another class. That works fine, I am also able to access class variables. However the class method "calcul" which is defined as following, is not accessible from other classes:
    class Server {
    static String name;
    public static void calcul (String inputS) {
    int length = inputS.length();
    for (int i = 0 ; i < length; i++) {
    System.out.println(newServer.name.charAt(i)); }
    If I create an instant of the class in the same class, the method is then available for the object.
    I am using JBuilder, so I can see, which methods and variables are available for an object. Thanks for your help

    calcul is a static method, that means you do not need an instance of server to run this method. This method is also public, but your class Server is not, your Server class is package protected. So only classes within the same package has Server can use its method. How to use the calcul method?// somewhere in the same package as the Server class
    Server.calcul( "toto" );

  • Accessing the same object from multiple classes.

    For the life of me I can't workout how I can access things from classes that haven't created them.
    I don't want to have to use "new" multiple times in seperate classes as that would erase manipulated values.
    I want to be able to access and manipulate an array of objects from multiple classes without resetting the array object values. How do I create a new object then be able to use it from all classes rather than re-creating it?
    Also I need my GUI to recognize the changes my buttons are making to data and reload itself so they show up.
    All help is good help!
    regards,
    Luke Grainger

    As long as you have a headquarters it shouldn't be to painfull. You simply keep a refrence to your ShipDataBase and Arsenal and all your irrellevant stuff in Headquarters. So the start of your Headquarters class would look something like:
    public class Headquarters{
      public Arsenal arsenal;
      public ShipDatabase db;
    //constructor
      public Headquarters(){
        arsenal = new Arsenal(this, ....);
        db = new ShipDatabase(...);
    //The Arsenal class:
    public class Arsenal{
      public Headquarter hq;
      public Arsenal(Headquarter hq, ....){
        this.hq = hq;
        .Then in your ShipDatabase you should, as good programing goes, keep the arraylist as a private class variable, and then make simple public methods to access it. Methods like getShipList(), addToShipList(Ship ship)....
    So when you want to add a ship from arsenal you write:
    hq.db.addToShipList(ship);
    .Or you could of course use a more direct refrence:
    ShipDatabase db = hq.db;
    or even
    ShipList = hq.db.getShipList();
    but this requires that the shiplist in the DB is kept public....
    Hope it was comprehensive enough, and that I answered what you where wondering.
    Sjur
    PS: Initialise the array is what you do right here:
    //constructor
    shipList = new Ship[6];
    shipList[0] = new Ship("Sentry", 15, 10, "Scout");
    " " " "etc
    shipList[5] = new Ship("Sentry", 15, 10, "Scout");PPS: To make code snippets etc. more readable please read this article:
    http://forum.java.sun.com/faq.jsp#messageformat

  • Accessing a public array from extra class.

    I am trying to access a public array that I declared in my main class from a separate class. I am a bit confused about why this is not working.
    The method search in the extra class is called in the extra class in part one of the nextKeystream method. How can I get it to use the int array "key". That I declared in the MainSolitaireDriver?
    Thanks
    My main class:
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class MainSolitaireDriver
       int pcount = 0;
       public int[] key = new int[26];    
       public MainSolitaireDriver()
           getValues();
            public void getValues()
                try
                    Scanner inFile = new  Scanner(new File("input.txt"));
                    for (int counter = 0; counter < key.length; counter++ )
                        key[counter]= inFile.nextInt();
                        System.out.print(key[counter]+" ");
                catch(FileNotFoundException e )
                e.printStackTrace();
                System.err.print("Failure- File Not Found");
         public static void main (String[] args)
                /*String whereInTheWorldMyFileShouldBe = new File("input.txt").getAbsolutePath();
    System.out.println(whereInTheWorldMyFileShouldBe); */
    }My extra class:
    public class Solitaire
         private Deck deck;
         *  Initialize the deck from the current key deck ordering.
         public Solitaire (int[] shuffle)
              deck = new Deck(shuffle);
            public void getArray(int[] Array)
            public int search(int [] span, int target)
                for (int indexcount = 0; indexcount < span.length; indexcount++)
                    if (span[indexcount]==target)
                        return indexcount;
            public void getArray(int[] a)
         *  Returns the next keystream generated by the Solitaire  Algorithm
         public int nextKeystream()
              // Step one: Move Joker A one card down.
                    int jokerAindex = search(MainSolitaireDriver(key), 27);
                    System.out.print(jokerAindex);
              // Step two: Move Joker B two cards down.
              // Step three: Perform a triple cut.
              // Step four: Perform a count cut.
              // Step five: Find the output card.
              return 0;
         *  Returns the ciphertext corresponding to the specified
       *  plaintext, according to the current key deck ordering.
         public String encrypt(String plaintext)
              return "";
         *  Returns the plaintext corresponding to the specified
       *  ciphertext, according to the current key deck ordering.
         public String decrypt(String ciphertext)
              return "";
    }

    Main Class
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class MainSolitaireDriver
       int pcount = 0;
       public int[] key = new int[26];    
       public MainSolitaireDriver()
           getValues();
            public void getValues()
                try
                    Scanner inFile = new  Scanner(new File("input.txt"));
                    for (int counter = 0; counter < key.length; counter++ )
                        key[counter]= inFile.nextInt();
                        System.out.print(key[counter]+" ");
                catch(FileNotFoundException e )
                e.printStackTrace();
                System.err.print("Failure- File Not Found");
         public static void main (String[] args)
                /*String whereInTheWorldMyFileShouldBe = new File("input.txt").getAbsolutePath();
    System.out.println(whereInTheWorldMyFileShouldBe); */
    }Solitaire Class (not main)
    public class Solitaire
         private Deck deck;
         *  Initialize the deck from the current key deck ordering.
         public Solitaire (int[] shuffle)
              deck = new Deck(shuffle);
            public void getArray(int[] Array)
            public int search(int [] span, int target)
                for (int indexcount = 0; indexcount < span.length; indexcount++)
                    if (span[indexcount]==target)
                        return indexcount;
            public void getArray(int[] a)
         *  Returns the next keystream generated by the Solitaire  Algorithm
         public int nextKeystream()
              // Step one: Move Joker A one card down.
                    int jokerAindex = search(MainSolitaireDriver.key, 27);
                    System.out.print(jokerAindex);
              // Step two: Move Joker B two cards down.
              // Step three: Perform a triple cut.
              // Step four: Perform a count cut.
              // Step five: Find the output card.
              return 0;
         *  Returns the ciphertext corresponding to the specified
       *  plaintext, according to the current key deck ordering.
         public String encrypt(String plaintext)
              return "";
         *  Returns the plaintext corresponding to the specified
       *  ciphertext, according to the current key deck ordering.
         public String decrypt(String ciphertext)
              return "";
    }

  • Accessing an Array List from another class

    Hi, I was a member on here before, but I forgot my password and my security question is wrong.
    My question is how do I access a private arraylist from a different class in the same package?
    What I am trying to do is the following (hard to explain).
    Make a picking client for a shop, so that when an order is recieved, the picker can click on the orders button, and view all of the current orders that have not been completed. This Pick client has its own user interface, in a seperate class from where the BoughtList array is created, in the cashier client. The boughtlist is created when the cashier puts in the product number into the cashier client and clicks buy. I seem to be having trouble accessing the list from another class. Once the order is completed the cashier clicks bought and the list is reset. There is another class in a different pagage that processes some of the functions of the order, eg newOrder().
    Yes it is for Uni so I dont need / want the full answers, jist something to get started. Also please dont flame me, I have done many other parts of this project, just having trouble getting started on this one.
    Here is the code for the cashier client. The code for the Pick client is almost the same, I just need to make the code that displays the orders.
    package Clients;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    import Catalogue.*;
    import DBAccess.*;
    import Processing.*;
    import Middle.*;
    class CashierGUI 
      class STATE                             // Cashier states
        public static final int PROCESS  = 0;
        public static final int CHECKED  = 1;
      class NAME                             // Names of buttons
        public static final String CHECK  = "Check";
        public static final String BUY    = "Buy";
        public static final String CANCEL = "Cancel";
        public static final String BOUGHT = "Bought";
      private static final int H = 300;       // Height of window pixels
      private static final int W = 400;       // Width  of window pixels
      private JLabel      theAction  = new JLabel();
      private JTextField  theInput   = new JTextField();
      private JTextArea   theOutput  = new JTextArea();
      private JScrollPane theSP      = new JScrollPane();
      private JButton     theBtCheck = new JButton( NAME.CHECK );
      private JButton     theBtBuy   = new JButton( NAME.BUY );
      private JButton     theBtCancel= new JButton( NAME.CANCEL );
      private JButton     theBtBought= new JButton( NAME.BOUGHT );
      private int         theState   = STATE.PROCESS;   // Current state
      private Product     theProduct = null;            // Current product
      private BoughtList  theBought  = null;            // Bought items
      private Transaction     theCB        = new Transaction();
      private StockReadWriter theStock     = null;
      private OrderProcessing theOrder     = null;
      private NumberFormat theMoney  =
              NumberFormat.getCurrencyInstance( Locale.UK );
      public CashierGUI(  RootPaneContainer rpc, MiddleFactory mf  )
        try                                             //
          theStock = mf.getNewStockReadWriter();        // DataBase access
          theOrder = mf.getNewOrderProcessing();        // Process order
        } catch ( Exception e )
          System.out.println("Exception: " + e.getMessage() );
        Container cp         = rpc.getContentPane();    // Content Pane
        Container rootWindow = (Container) rpc;         // Root Window
        cp.setLayout(null);                             // No layout manager
        rootWindow.setSize( W, H );                     // Size of Window
        Font f = new Font("Monospaced",Font.PLAIN,12);  // Font f is
        theBtCheck.setBounds( 16, 25+60*0, 80, 40 );    // Check Button
        theBtCheck.addActionListener( theCB );          // Listener
        cp.add( theBtCheck );                           //  Add to canvas
        theBtBuy.setBounds( 16, 25+60*1, 80, 40 );      // Buy button
        theBtBuy.addActionListener( theCB );            //  Listener
        cp.add( theBtBuy );                             //  Add to canvas
        theBtCancel.setBounds( 16, 25+60*2, 80, 40 );   // Cancel Button
        theBtCancel.addActionListener( theCB );         //  Listener
        cp.add( theBtCancel );                          //  Add to canvas
        theBtBought.setBounds( 16, 25+60*3, 80, 40 );   // Clear Button
        theBtBought.addActionListener( theCB );         //  Listener
        cp.add( theBtBought );                          //  Add to canvas
        theAction.setBounds( 110, 25 , 270, 20 );       // Message area
        theAction.setText( "" );                        // Blank
        cp.add( theAction );                            //  Add to canvas
        theInput.setBounds( 110, 50, 270, 40 );         // Input Area
        theInput.setText("");                           // Blank
        cp.add( theInput );                             //  Add to canvas
        theSP.setBounds( 110, 100, 270, 160 );          // Scrolling pane
        theOutput.setText( "" );                        //  Blank
        theOutput.setFont( f );                         //  Uses font 
        cp.add( theSP );                                //  Add to canvas
        theSP.getViewport().add( theOutput );           //  In TextArea
        rootWindow.setVisible( true );                  // Make visible
      class Transaction implements ActionListener       // Listener
        public void actionPerformed( ActionEvent ae )   // Interaction
          if ( theStock == null )
            theAction.setText("No conection");
            return;                                     // No connection
          String actionIs = ae.getActionCommand();      // Button
          try
            if ( theBought == null )
              int on    = theOrder.uniqueNumber();      // Unique order no.
              theBought = new BoughtList( on );         //  Bought list
            if ( actionIs.equals( NAME.CHECK ) )        // Button CHECK
              theState  = STATE.PROCESS;                // State process
              String pn  = theInput.getText().trim();   // Product no.
              int    amount  = 1;                       //  & quantity
              if ( theStock.exists( pn ) )              // Stock Exists?
              {                                         // T
                Product pr = theStock.getDetails(pn);   //  Get details
                if ( pr.getQuantity() >= amount )       //  In stock?
                {                                       //  T
                  theAction.setText(                    //   Display
                    pr.getDescription() + " : " +       //    description
                    theMoney.format(pr.getPrice()) +    //    price
                    " (" + pr.getQuantity() + ")"       //    quantity
                  );                                    //   of product
                  theProduct = pr;                      //   Remember prod.
                  theProduct.setQuantity( amount );     //    & quantity
                  theState = STATE.CHECKED;             //   OK await BUY
                } else {                                //  F
                  theAction.setText(                    //   Not in Stock
                    pr.getDescription() +" not in stock"
              } else {                                  // F Stock exists
                theAction.setText(                      //  Unknown
                  "Unknown product number " + pn        //  product no.
            if ( actionIs.equals( NAME.BUY ) )          // Button BUY
              if ( theState != STATE.CHECKED )          // Not checked
              {                                         //  with customer
                theAction.setText("Check if OK with customer first");
                return;
              boolean stockBought =                      // Buy
                theStock.buyStock(                       //  however
                  theProduct.getProductNo(),             //  may fail             
                  theProduct.getQuantity() );            //
              if ( stockBought )                         // Stock bought
              {                                          // T
                theBought.add( theProduct );             //  Add to bought
                theOutput.setText( "" );                 //  clear
                theOutput.append( theBought.details());  //  Display
                theAction.setText("Purchased " +         //    details
                           theProduct.getDescription()); //
    //          theInput.setText( "" );
              } else {                                   // F
                theAction.setText("!!! Not in stock");   //  Now no stock
              theState = STATE.PROCESS;                  // All Done
            if ( actionIs.equals( NAME.CANCEL ) )        // Button CANCEL
              if ( theBought.number() >= 1 )             // item to cancel
              {                                          // T
                Product dt =  theBought.remove();        //  Remove from list
                theStock.addStock( dt.getProductNo(),    //  Re-stock
                                   dt.getQuantity()  );  //   as not sold
                theAction.setText("");                   //
                theOutput.setText(theBought.details());  //  display sales
              } else {                                   // F
                theOutput.setText( "" );                 //  Clear
              theState = STATE.PROCESS;
            if ( actionIs.equals( NAME.BOUGHT ) )        // Button Bought
              if ( theBought.number() >= 1 )             // items > 1
              {                                          // T
                theOrder.newOrder( theBought );          //  Process order
                theBought = null;                        //  reset
              theOutput.setText( "" );                   // Clear
              theInput.setText( "" );                    //
              theAction.setText( "Next customer" );      // New Customer
              theState = STATE.PROCESS;                  // All Done
            theInput.requestFocus();                     // theInput has Focus
          catch ( StockException e )                     // Error
          {                                              //  Of course
            theOutput.append( "Fail Stock access:" +     //   Should not
                                e.getMessage() + "\n" ); //  happen
          catch ( OrderException e )                     // Error
          {                                              //  Of course
            theOutput.append( "Fail Order process:" +    //   Should not
                                e.getMessage() + "\n" ); //  happen
    }

    (disclaimer: I did not read through your Swing code, as I find that painful)
    My question is how do I access a private arraylist from a different class in the same
    package?Provide a public accessor method (getMyPrivateArrayList())

  • Bind Variable Brain Teaser - Accessing a filtered Parent from a Child

    Hi Guys and Gals,
    Using JDev 11.1.2.4.0.
    I have two tables, the parent(Scenarios) and the child (Orders).  They are setup as such:
    SELECT Scenarios.SCENARIO_ID,
                   Scenarios.NAME,
                   Scenarios.COMPANY_ID
    FROM SCENARIOS Scenarios
    WHERE Scenarios.SCENARIO_ID = :pScenarioId
    ORDER BY Scenarios.SCENARIO_ID
    SELECT Orders.ORDER_ID,
                   Orders.COMPANY_ID
    FROM ORDERS Orders
    Scenarios (The Parent) has a required bind variable which filters on the primary key, SCENARIO_ID.  The primary key for the Orders table is Order_ID.  The two tables are joined by an association & view link on COMPANY_ID, setup as a 1-to-* relationship.  However, it is in fact a *-to-* relationship since an Order row can appear in several scenarios.
    In the Orders View Object, I also have a transient attribute, ScenarioInfo, which attempts to access Scenarios's current row to retrieve the name.  The getter is as such:
    public BigDecimal getScenarioInfo() {
         Row row = this.getScenariosView();
         DBSequence db = ((ScenariosViewRowImpl)row).getScenarioId();
         return new BigDecimal(db.getValue());
    The sequence of events:
    1) Open the application module and click on the view link between Scenarios and Orders.  A window pops open asking for the bind variable (pScenarioId) value.  I enter a valid value (2) and hit enter.  This should (in theory) return only one row for the Scenarios view object, the one with the ScenarioId of 2.  Clicking only on the Scenarios view object in the application module verifies this.  The Orders view object then renders, but an error message is displayed attempting getScenarioInfo()
    (oracle.jbo.AttrValException) JBO-27019: The get method for attribute "ScenarioInfo" in Orders cannot be resolved.
    I'm not sure I understand why.  ScenarioId with a value of 2 is a valid number.  With the bind variable / filter in place there should be one row as the parent, turning the relationship into a 1-to-*.  Without the filter in place, I may access the parent without error, but the record that is pulled back is the first possible row due to the 1-to-* relationship.
    Instead of having a bind variable, I have also tried implementing a View Criteria in the app module for the Scenarios view object.  However, the criteria doesn't seem to "stick" when the this.getScenariosView() is called from the Orders view.  It also pulls back the first row.
    Does anyone have any ideas?  The only thing I can think of would be to change the relationship to a *-to-* through a translation table, but that's a complication I do not wish to add if possible.
    Thanks in advance,
    Will

    Here is an alternate approach.  This one removes the bind variable from the Scenarios query and instead implements the following code in the app module impl.
        public void refreshScenario() {
            ViewObjectImpl allScenarios = this.getAllScenarios();
            VariableValueManager manager = allScenarios.getVariableManager();
            manager.setVariableValue("pScenarioId", new BigDecimal(2));
            ViewCriteriaManager criteriaManager = allScenarios.getViewCriteriaManager();
            ViewCriteria vc = criteriaManager.getViewCriteria("ScenariosViewCriteria");
            criteriaManager.applyViewCriteria(vc);
            allScenarios.executeQuery();
    The getter is the same as my second getter example:
        public String getScenarioInfo() {
            // remove the default getter for the transient string variable ScenarioInfo
            // return (String) getAttributeInternal(SCENARIOINFO);
            // get the view link accessor for the parent row, Scenarios
            ScenariosViewRowImpl row = (ScenariosViewRowImpl)this.getScenariosView();
            // This should return 1 row, which would be the row remaining after filtering by the bind variable with a value of 2
            // Get that rows Name attribute
            String s = row.getName();
            return s;
    I run the app module tester and then run the refreshScenarios() method.  I then double-click the view link which pops up a dialog box.  The bind variable pScenarioId is pre-filled with 2.  I click enter a receive the following unexpected output as seen here: http://www.williverstravels.com/JDev/Forums/Threads/11077337/ViewCriteriaAttempt.jpg
    As you can see, the ScenarioInfo column returns "#1" when it should return the parent's Name, which would be "#2".  I am a little confused as to why this is functioning this way.

  • Accessing method in application from a component

    I need to access a public method in actionscript by a
    component that is a child of the application.mxml file.
    How can I do that?
    Ive tried this.methodName (but "this" only refers to the
    parent container)
    Ive tried "Application.methodName" but that doesnt work
    either.
    Ive tried super.method name = no work
    Ive tried to reference the application in the import but I
    dont know what Im supposed to put there?
    import Application?
    My component is loaded into the main application at runtime.
    Any ideas?

    Make sure the component has an ID in the main app.
    Let's say you give it an id of "myComp". Then, if you want a
    public function in theat component, you can use
    Application.application.myComp.myFunctionName();
    Providing you import mx.core.Application

  • HOWTO: Use the Spring data access methods together with the WebRowSet class

    With the WebRowSet class I can easily iterate over a ResultSet and produce some XML using the code below.
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection connection
    = DriverManager.getConnection("");
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT SYSDATE FROM DUAL");
    WebRowSet webRowSet = new WebRowSetImpl();
    webRowSet.populate(resultSet);
    statement.close();
    connection.close();
    webRowSet.writeXml(new FileOutputStream("C:\\SYSDATE.xml"));
    So, how would I use the simplified Spring methods to do the same thing? The WebRowSet.populate method only supports a ResultSet object. The Spring framework only returns an SqlRowSet object that is not easily cast to the ResultSet, etc.
    Thanks for your help.
    Edited by: mrmeth0d on Jan 3, 2008 2:02 PM

    So, how would I use the simplified Spring methods to do the same thing? The WebRowSet.populate method only supports a ResultSet object. The Spring framework only returns an SqlRowSet object that is not easily cast to the ResultSet, etc.
    Cast Spring's SqlRowSet to ResultSet? Impossible. It's an interface that does not extend java.sql.ResultSet.
    javax.sql.WebRowSet is an interface that extends java.sql.ResultSet.
    Spring does have a concrete class ResultSetWrappingSqlRowSet whose constructor can take a java.sql.ResultSet.
    So I think your solution is to instantiate a new ResultSetWrappingSqlRowSet, passing it your javax.sql.rowset.WebRowSet, and return that wherever Spring wants to return a SqlRowSet.
    %

  • How get method source code from a class

    We developed a model generator tool that get a �base model� as an input and generated rich model.
    The �base model� is collection of POJO classes and the model generator analyzed the base model (with reflection) and with �ftl� generates �rich model� , which is the base model with additional annotations and logics.
    Some classes in the �base-model� may contain additional method and I need to copy those methods as they are to the �rich-model� generated sources.
    I need a way to copy those methods from the base-model (I work on it with reflection, but I have also the source) to the rich-model.
    I think to do this by decompile. Are there any better way?
    Is there any simple utility that decompile method?
    Thank you

    There is a big differnet between the input and the output.
    for example:
    input:
    @Key(indexs = { "name" })
    @SuppressWarnings(value = { "serial", "unused" })
    @Observers(observers = { @Observer(type = ObserverType.INSTANCE_INHERITANCE) })
    public class Device extends Segment {
         // ********************** Class Members: ********************** //
         private DeviceTypeEnum type;
         protected DeviceSetup deviceSetup;
         protected Networking networking;output:
    * model-project class. generated by ModelGenerator. *
    @Entity
    @Key(indexs={"name"})
    @NamedQueries(value={@NamedQuery(name="Device.FilterByIndex", query="SELECT d FROM Device d WHERE d.name=:name")})
    @Observers(observers={@Observer(type=ObserverType.INSTANCE_INHERITANCE)})
    public class Device extends Segment implements ObservableIfc
         private static final long serialVersionUID = -7782418163128836178L;
        // ********************** Class Members: ********************** //
        @Column(name="type_column")
        @Type(type="com.radware.insite.modelhelpers.utils.GenericEnumUserType", parameters = {@Parameter(name = "enumClass" , value = "com.radware.insite.modelhelpers.constants.ImConstants$DeviceTypeEnum")})
        private DeviceTypeEnum type;
        private FieldMetadata typeMD = new RefMetadata();
        @OneToOne(cascade={CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE}, fetch=FetchType.LAZY)
        @JoinColumn(name="dev_setup_2_dev")
        protected DeviceSetup deviceSetup = new DeviceSetup();
        private FieldMetadata deviceSetupMD = new RefMetadata();

  • Accesing from other classes to protected void

    Hy! I'm a newbie to java programming. So i am making a program in J2ME, and the problem is :
    I have an abstract class, wich i must extend. That class defines a procedure
    abstract protected void destroyApp(boolean unconditional), so in my extended class this void is protected. But i want to access to this procedure from other class, and do it somehow static.
    I have made a main program class (the extended class), and i want to send from other class a destroy message to it (to call destroyApp procedure).
    Kazhha.

    Your question has nothing to do with Native Methods.
    In the future, for novice questions, use the New To Java Technology forum.
    I have an abstract class, which i must extend. That
    class defines a procedure
    abstract protected void destroyApp(boolean
    unconditional), so in my extended class this void is
    protected.You can make the method public in your class.
    But i want to access to this procedure
    from other class, and do it somehow static.IIRC you cannot make a method static if it is not static in the class you extend.
    I have made a main program class (the extended class),
    and i want to send from other class a destroy message
    to it (to call destroyApp procedure).Huh?

  • How to get info from a .class file at run time? thanks for help

    I need to get methods and properties (variables) from a .class file at run time.
    as u know, javap.exe can do that in an independent way. but i need to get info at run time once the .class or packeges have been changed, javap is not suitable in the case.
    i try to read data directly from .class file but it's hard to know the file format.
    e.g. a class looks like (java file):
    class MyClass extends Frame
    int i0;
    String s0;
    public String getName()
    if the file is compiled to .class file, how to get properties (variables: i0,s0) and methods String getName() from the .class file by an applicaton at run time?
    Doclet is not suitable for speed reason, it is too slow to get right info in right format.
    Thanks for any help, please write a little bit more in detail if you know.

    Use the Java Reflection API. Have a look at the Reflection section of the Java Tutorial located at http://java.sun.com/docs/books/tutorial/reflect/index.html

  • Access parent class from instance of nested class

    Hi,
    I have the following class hierarchy:
    public class BaseClass
    public class ParentClass
      private NestedClass    mNestedClass;
      public ParentClass()
        mNestedClass = new NestedClass();
      protected NestedClass getNestedClass()
        return mNestedClass;
      public static BaseClass createParentClass()
        parentClass = new ParentClass();
        // some code...
        return parentClass.getNestedClass();
      protected class NestedClass extends BaseClass
        NestedClass( int i )
          // some other code...
    }I cannot modify the classes above, as they are third-party and they are subject to changes...
    In my code, I may only use the static method to create an instance of ParentClass, because there is some important code (not accessible outside of the package) instead of the comments. The problem is that the static method only returns me an instance of the NestedClass, but not the ParentClass. For some reasons, I would need to access the instance of ParentClass.
    Is there a way (Java syntax, I mean) that would allow me to access from an instance of NestedClass the corresponding ParentClass instance?
    I know that inside a NestedClass method I may use ParentClass.this, but, as I wrote above, that class cannot be modified. Worse, I am not able to extend it neither, because the constructor is not public (or at least protected)...
    Please, does anybody have the correct answer?
    Thanks,
    Adrian

    There are at least 3 funny things in the code you posted:
    1) an instance of NestedClass cannot be created with "new NestedClass()", because the only constructor is NestedClass(int)
    2) I can't see why a method called "createParentClass" should return an instance of NestedClass
    3) The funniest: I really can't understand why you "may only use the static method to create an instance of ParentClass": if the ParentClass developer didn't want you to instantiate it directly, why did he made the constructor public?
    But the fact is there's no way to access the enclosing object of a nested object if the sw architect didn't want this (maybe including in the interface a method like this:
    class EnclosingClass {
      class NestedClass {
       EnclosingClass getEnclosingObject() {
        return EnclosingClass.this;
    This simply should break encapsulation and object hyerarchy security... really a bad thing I guess!!
    Bye

  • 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 call a method from a class without creating an instance fromthisclas

    I want to create a class with methods but I want to call methods from this class without creating an instance from this class. Is this possible?
    Is there in Java something like class methods and object methods????

    keyword 'static' my friend.
    public class foo {
    public static void bar {
    System.out.println ("hello");
    foo.bar()

Maybe you are looking for