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())

Similar Messages

  • Instantiating an Array declared in a class from another class

    Hi Guys,
    I am working on a project for University and I'm stuck with this thins, which I'm sure is pretty easy when you know how...
    I have a first class "Courses" in which I declare my Array, here is the code:
    import java.util.*;
    public class Courses
    private String[][] Listing;
    Courses(String[][] l)
       l = Listing;
    }This class compiles just fine but I have 2 problems:
    1/ Can I make sure that this array will be [3][4] ?
    When I try : "private String[3][4] Listing;" or "Courses(String[3][4] l)" the class doesn't compile anymore...
    FYI: I want to store the followings in my array:
    French Language, 250, 130, 70
    Painting, 270, 140, 70
    Yoga, 250, 130, 70
    2/ How can I instantiate this from another class?
    From a class "Booking" I want to be able to create a new array "Listing" by calling my constructor from the Courses class and populate it with the above data (course,full-time price, part-time price, Concessions price )
    How do I do that?

    Thanks, I've modofied my code as follows:
    import java.util.*;
    public class Courses
    private String[][] Listing = new String[3][4]; //create array 3 rows * 4 columns
    Courses(String[][] l)
       l = Listing;
    int i;
    int j;
    int p;
    String t;
    String p1;
    String getTitle(int i)  //return Course Title
       t=Listing[0];
    return t;
    int getPrice(int i, int j) //return Price (Full-Time, Part-Time, Concessions)
    p1=Listing[i][j];
    p=Integer.parseInt(p1);
    return p;
    now from my nex class Booking I want to instantiate Courses:
    public class Booking
    Courses c = new Courses()
    }How do I actually pass the data to this...what's the syntax so that my instance will be:
    c[0][0]="French Language"
    c[0][1]="250"
    c[0][2]="130"
    c[0][3]="70"
    c[1][0]="Painting"
    c[1][1]="270"
    c[1][2]="140"
    c[1][3]="70"
    c[2][0]="Yoga"
    c[2][1]="250"
    c[2][2]="130"
    c[2][3]="70"
    Thanks in advance,
    Tom

  • Accessing a variable defined in one class from another class..

    Greetings,
    I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.
    Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem  to be working for me. Any ideas would be appreciated.  Thanks,
    - Jeremy
    package  jab.enemy
    import flash.display.MovieClip;
    import flash.events.Event;
    import jab.enemy.MissleDisappear;
    public class DieLikeThePhishes
    private var _clip2:MovieClip; // player
    private var _clip3:MovieClip; //phish1
    private var _clip4:MovieClip; //phish2
    private var _clip5:MovieClip; //phish3
    private var _clip6:MovieClip; //phish4
    private var _clip10:MovieClip; // background
    private var _clip11:MovieClip // missle1
    private var _clip12:MovieClip // missle2
    private var _clip13:MovieClip // missle3
    private var _clip14:MovieClip // missle4
    private var _clip15:MovieClip // missle5
    private var _clip16:MovieClip // missle6
    private var _clip17:MovieClip // missle7
    private var _clip18:MovieClip // missle8
    private var _clip19:MovieClip // missle9
    private var _clip20:MovieClip // missle10
    private var _clip21:MovieClip // missle11
    private var _clip22:MovieClip // missle12
    var ay1 = 0;var ay2 = 0;var ay3 = 0;var ay4 = 0;
    var vy1 = 0;var vy2 = 0;var vy3 = 0;var vy4 = 0;
    var phish1BeenHit:Boolean = false;var phish2BeenHit:Boolean = false;
    var phish3BeenHit:Boolean = false;var phish4BeenHit:Boolean = false;
    public function DieLikeThePhishes(clip2:MovieClip,clip3:MovieClip,clip4:MovieClip,clip5:MovieClip,clip6:M ovieClip,clip10:MovieClip,clip11:MovieClip,clip12:MovieClip,clip13:MovieClip,clip14:MovieC lip,clip15:MovieClip,clip16:MovieClip,clip17:MovieClip,clip18:MovieClip,clip19:MovieClip,c lip20:MovieClip,clip21:MovieClip,clip22:MovieClip)
    _clip2 = clip2;_clip3 = clip3;_clip4 = clip4;_clip5 = clip5;_clip6 = clip6;
    _clip10 = clip10;_clip11 = clip11;_clip12 = clip12;_clip13 = clip13;_clip14 = clip14;
    _clip15 = clip15;_clip16 = clip16;_clip17 = clip17;_clip18 = clip18;_clip19 = clip19;
    _clip20 = clip20;_clip21 = clip21;_clip22= clip22;
    _clip3.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
    function onEnterFrame(event:Event):void
    vy1+= ay1;_clip3.y += vy1; vy2+= ay2;_clip4.y += vy2;
    vy3+= ay3;_clip5.y += vy3; vy4+= ay4;_clip6.y += vy4;
    if (phish1BeenHit ==false)
    if(_clip3.y >620)
    {_clip3.y = 620;}
    if (phish2BeenHit ==false)
    if(_clip4.y >620)
    {_clip4.y = 620;}
    if (phish3BeenHit ==false)
    if(_clip5.y >620)
    {_clip5.y = 620;}
    if (phish4BeenHit ==false)
    if(_clip6.y >620)
    {_clip6.y = 620;}
    if (_clip11.hitTestObject(_clip3) ||_clip12.hitTestObject(_clip3)||_clip13.hitTestObject(_clip3)||_clip14.hitTestObject(_cl ip3)||_clip15.hitTestObject(_clip3)||_clip16.hitTestObject(_clip3)||_clip17.hitTestObject( _clip3)||_clip18.hitTestObject(_clip3)||_clip19.hitTestObject(_clip3)||_clip20.hitTestObje ct(_clip3)||_clip21.hitTestObject(_clip3)||_clip22.hitTestObject(_clip3))
    _clip3.scaleY = -Math.abs(_clip3.scaleY);
    _clip3.alpha = 0.4;
    ay1 = 3
    vy1= -2;
    phish1BeenHit = true;
    if (_clip11.hitTestObject(_clip4) ||_clip12.hitTestObject(_clip4)||_clip13.hitTestObject(_clip4)||_clip14.hitTestObject(_cl ip4)||_clip15.hitTestObject(_clip4)||_clip16.hitTestObject(_clip4)||_clip17.hitTestObject( _clip4)||_clip18.hitTestObject(_clip4)||_clip19.hitTestObject(_clip4)||_clip20.hitTestObje ct(_clip4)||_clip21.hitTestObject(_clip4)||_clip22.hitTestObject(_clip4))
    _clip4.scaleY = -Math.abs(_clip4.scaleY);
    _clip4.alpha = 0.4;
    ay2 = 3
    vy2= -2;
    phish2BeenHit = true;
    if (_clip11.hitTestObject(_clip5) ||_clip12.hitTestObject(_clip5)||_clip13.hitTestObject(_clip5)||_clip14.hitTestObject(_cl ip5)||_clip15.hitTestObject(_clip5)||_clip16.hitTestObject(_clip5)||_clip17.hitTestObject( _clip5)||_clip18.hitTestObject(_clip5)||_clip19.hitTestObject(_clip5)||_clip20.hitTestObje ct(_clip5)||_clip21.hitTestObject(_clip5)||_clip22.hitTestObject(_clip5))
    _clip5.scaleY = -Math.abs(_clip5.scaleY);
    _clip5.alpha = 0.4;
    ay3 = 3
    vy3= -2;
    phish3BeenHit = true;
    if (_clip11.hitTestObject(_clip6) ||_clip12.hitTestObject(_clip6)||_clip13.hitTestObject(_clip6)||_clip14.hitTestObject(_cl ip6)||_clip15.hitTestObject(_clip6)||_clip16.hitTestObject(_clip6)||_clip17.hitTestObject( _clip6)||_clip18.hitTestObject(_clip6)||_clip19.hitTestObject(_clip6)||_clip20.hitTestObje ct(_clip6)||_clip21.hitTestObject(_clip6)||_clip22.hitTestObject(_clip6))
    _clip6.scaleY = -Math.abs(_clip6.scaleY);
    _clip6.alpha = 0.4;
    ay4 = 3
    vy4= -2;
    phish4BeenHit = true;
    if (_clip3.y > 10000)
    _clip3.x = 1000 +3000*Math.random()-_clip10.x;
    _clip3.y = 300;
    _clip3.alpha = 1;
    _clip3.scaleY = Math.abs(_clip3.scaleY);
    ay1 = vy1 = 0;
    phish1BeenHit = false;
    if (_clip4.y > 10000)
    _clip4.x = 1000 +3000*Math.random()-_clip10.x;
    _clip4.y = 300;
    _clip4.alpha = 1;
    _clip4.scaleY = Math.abs(_clip4.scaleY);
    ay2 = vy2 = 0;
    phish2BeenHit = false;
    if (_clip5.y > 10000)
    _clip5.x = 1000 +3000*Math.random()-_clip10.x;
    _clip5.y = 300;
    _clip5.alpha = 1;
    _clip5.scaleY = Math.abs(_clip5.scaleY);
    ay3 = vy3 = 0;
    phish3BeenHit = false;
    if (_clip6.y > 10000)
    _clip6.x = 1000 +3000*Math.random()-_clip10.x;
    _clip6.y = 300;
    _clip6.alpha = 1;
    _clip6.scaleY = Math.abs(_clip6.scaleY);
    ay4 = vy4 = 0;
    phish4BeenHit = false;
    var missleDisappear1 = new MissleDisappear(_clip11,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear2 = new MissleDisappear(_clip12,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear3 = new MissleDisappear(_clip13,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear4 = new MissleDisappear(_clip14,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear5 = new MissleDisappear(_clip15,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear6 = new MissleDisappear(_clip16,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear7 = new MissleDisappear(_clip17,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear8 = new MissleDisappear(_clip18,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear9 = new MissleDisappear(_clip19,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear10 = new MissleDisappear(_clip20,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear11 = new MissleDisappear(_clip21,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear12 = new MissleDisappear(_clip22,_clip3,_clip4,_clip5,_clip6,_clip10);

    I would approach it in much the same way as you would in java, by making getters and setters for all of your class variables.
    Getters being for returning the values, Setters being for setting them.
    So you would make a get function for the variable you want to access ala:
    function get1PhishBeenHit():boolean {
         return this.phish1BeenHit;
    Then to access the value of that variable from outwith the class:
    var result:boolean = ClassInstanceName.get1PhishBeenHit();

  • Accessing a JTextField from another class

    I 've got 2 classes I am trying to get the value of a JTextField that located in a second class see the code
    class1 myClass = new class1();
    String text = myClass.jTextField1.getText();
    System.out.print(text);What happens is when i run the program and enter some text in the jTextFild1 and then click on my Jbutton it does not print anything
    the JButton is in the caller class
    Could anyone explains to me what is wrong

    an example would help maybe....
    if you want to access your jtextfield from another class then:
    import javax.swing.*;
    public class FieldHolderClass {
    public JTextField jtf = null;
    public FieldHolder() {
      JFrame jf = new JFrame();
      jtf = new JTextField();
      jtf.setText("this is the text that is here when other callerclass seeks for text");
      jf.getContentPane().add(jtf);
      jf.setVisible(true);
    public class CallerClass {
    public static void main(String args[]) {
      FieldHolderClass fHolder = new FieldHolderClass();
      System.out.println((fHolder.jtf.getText());
    }of course i have not written any swing app for a long time, so i might have forgotten everything... so, don't flame me when that code does not compile.
    the thing that it's supposed to show, is that you make a <b>public</b> variabel (jtf) and you simply ask for it from another class by typing holderclass instances name dot and that variable name (in this case jtf) and dot and then call the method on that variable (or object...)
    it might also be that you want your code to work the way that when you enter a text into jtextfield, then after pressing enter it would get printed on terminal...
    in that case you should also register some Listeners... i remember that back when i was just getin' to know java then i had problems with it as well... but then again, i didn't read any manuals...
    i hope i was somewhat help...

  • Calling a class's method from another class

    Hi, i would like to know if it's possible to call a Class's method and get it's return from another Class. This first Class doesn't extend the second. I've got a Choice on this first class and depending on what is selected, i want to draw a image on the second class witch is a Panel extended. I put the control "if" on the paint() method of the second class witch is called from the first by the repaint() (first_class.repaint()) on itemStateChanged(). Thankx 4 your help. I'm stuck with this.This program is for my postgraduation final project and i'm very late....

    import java.awt.*;
    import java.sql.*;
    * This type was generated by a SmartGuide.
    class Test extends Frame {
         private java.awt.Panel ivjComboPane = null;
         private java.awt.Panel ivjContentsPane = null;
         IvjEventHandler ivjEventHandler = new IvjEventHandler();
         private Combobox ivjCombobox1 = null;
    class IvjEventHandler implements java.awt.event.WindowListener {
              public void windowActivated(java.awt.event.WindowEvent e) {};
              public void windowClosed(java.awt.event.WindowEvent e) {};
              public void windowClosing(java.awt.event.WindowEvent e) {
                   if (e.getSource() == Test.this)
                        connEtoC1(e);
              public void windowDeactivated(java.awt.event.WindowEvent e) {};
              public void windowDeiconified(java.awt.event.WindowEvent e) {};
              public void windowIconified(java.awt.event.WindowEvent e) {};
              public void windowOpened(java.awt.event.WindowEvent e) {};
         private Panel ivjPanel1 = null;
    * Combo constructor comment.
    public Test() {
         super();
         initialize();
    * Combo constructor comment.
    * @param title java.lang.String
    public Test(String title) {
         super(title);
    * Insert the method's description here.
    * Creation date: (11/16/2001 7:48:51 PM)
    * @param s java.lang.String
    public void conexao(String s) {
         try {
              Class.forName("oracle.jdbc.driver.OracleDriver");
              String url = "jdbc:oracle:thin:system/[email protected]:1521:puc";
              Connection db = DriverManager.getConnection(url);
              //String sql_str = "SELECT * FROM referencia";
              Statement sq_stmt = db.createStatement();
              ResultSet rs = sq_stmt.executeQuery(s);
              ivjCombobox1.addItem("");
              while (rs.next()) {
                   String dt = rs.getString(1);
                   ivjCombobox1.addItem(dt);
              db.close();
         } catch (SQLException e) {
              System.out.println("Erro sql" + e);
         } catch (ClassNotFoundException cnf) {
    * connEtoC1: (Combo.window.windowClosing(java.awt.event.WindowEvent) --> Combo.dispose()V)
    * @param arg1 java.awt.event.WindowEvent
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void connEtoC1(java.awt.event.WindowEvent arg1) {
         try {
              // user code begin {1}
              // user code end
              this.dispose();
              // user code begin {2}
              // user code end
         } catch (java.lang.Throwable ivjExc) {
              // user code begin {3}
              // user code end
              handleException(ivjExc);
    * Return the Combobox1 property value.
    * @return Combobox
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Combobox getCombobox1() {
         if (ivjCombobox1 == null) {
              try {
                   ivjCombobox1 = new Combobox();
                   ivjCombobox1.setName("Combobox1");
                   ivjCombobox1.setLocation(30, 30);
                   // user code begin {1}
                   this.conexao("select * from referencia");
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjCombobox1;
    * Return the ComboPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getComboPane() {
         if (ivjComboPane == null) {
              try {
                   ivjComboPane = new java.awt.Panel();
                   ivjComboPane.setName("ComboPane");
                   ivjComboPane.setLayout(null);
                   getComboPane().add(getCombobox1(), getCombobox1().getName());
                   getComboPane().add(getPanel1(), getPanel1().getName());
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjComboPane;
    * Return the ContentsPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getContentsPane() {
         if (ivjContentsPane == null) {
              try {
                   ivjContentsPane = new java.awt.Panel();
                   ivjContentsPane.setName("ContentsPane");
                   ivjContentsPane.setLayout(new java.awt.BorderLayout());
                   getContentsPane().add(getComboPane(), "Center");
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjContentsPane;
    * Return the Panel1 property value.
    * @return Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Panel getPanel1() {
         if (ivjPanel1 == null) {
              try {
                   ivjPanel1 = new Panel();
                   ivjPanel1.setName("Panel1");
                   ivjPanel1.setBackground(java.awt.SystemColor.scrollbar);
                   ivjPanel1.setBounds(24, 118, 244, 154);
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjPanel1;
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initializes connections
    * @exception java.lang.Exception The exception description.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initConnections() throws java.lang.Exception {
         // user code begin {1}
         // user code end
         this.addWindowListener(ivjEventHandler);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combo");
              setLayout(new java.awt.BorderLayout());
              setSize(460, 300);
              setTitle("Combo");
              add(getContentsPane(), "Center");
              initConnections();
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:02:58 PM)
    * @return java.lang.String
    public String readCombo() {
         String dado = ivjCombobox1.getSelectedItem();
         return dado;
    * Starts the application.
    * @param args an array of command-line arguments
    public static void main(java.lang.String[] args) {
         try {
              /* Create the frame */
              Test aTest = new Test();
              /* Add a windowListener for the windowClosedEvent */
              aTest.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosed(java.awt.event.WindowEvent e) {
                        System.exit(0);
              aTest.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Test");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 1:59:15 PM)
    * @author:
    class Combobox extends java.awt.Choice {
         public java.lang.String dado;
    * Combobox constructor comment.
    public Combobox() {
         super();
         initialize();
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combobox");
              setSize(133, 23);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Combobox aCombobox;
              aCombobox = new Combobox();
              frame.add("Center", aCombobox);
              frame.setSize(aCombobox.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Combobox");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 2:16:11 PM)
    * @author:
    class Panel extends java.awt.Panel {
    * Panel constructor comment.
    public Panel() {
         super();
         initialize();
    * Panel constructor comment.
    * @param layout java.awt.LayoutManager
    public Panel(java.awt.LayoutManager layout) {
         super(layout);
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Panel");
              setLayout(null);
              setSize(260, 127);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Panel aPanel;
              aPanel = new Panel();
              frame.add("Center", aPanel);
              frame.setSize(aPanel.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of java.awt.Panel");
              exception.printStackTrace(System.out);
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:18:36 PM)
    public void paint(Graphics g) {
    /* Here's the error:
    C:\Test.java:389: non-static method readCombo() cannot be referenced from a static context
         System.out.println(Test.lerCombo());*/
         System.out.println(Test.readCombo());

  • Running a main Method from another class??

    Hi,
    I am trying to run a main method from another class, eg the main method is in Class1 and i am trying to run it from class2.
    So I have
    class1 c1 = new class1();
    c1.main();and I get the following compilation error:
    clas2.java:42: main(java.lang.String[]) in class1 cannot be applied to () c1.main();
    any ideas on how to do this correctly
    thanks in advance,
    Donal

    Hi thanks for the replies,
    tried just passing a string earlier and that just gave errors too, I should have been more specific and pass a string array.
    Its working now thanks again.
    Donal

  • Need to call a repaint from another class

    I need to call a repaint from another class, but since I can't make the paint() method a static one, it will not let me access the repaint method, any ideas? thanks guys
    Conor

    ok here's a very basic idea of whats goin on...
    <code>
    MainFrame class (in which the paint method resides)
    public void paint()
    // draw lines
    // opens an instance of the settings window
    void procSettings_actionPerformed(ActionEvent e)
    if(procRunning)
    procRunning = false;
    timer.stop();
    procPaused = true;
    procSettings s = new procSettings();
    s.setSize(370, 467);
    s.setLocationRelativeTo(null);
    s.setResizable(false);
    s.setVisible(true);
    ProcSettings class
    if(certain condition)
    // reset the lines of the graph
    // REPAINT <--- I want to know how to call this repaint, MainFrame.repaint() does not work
    thanks

  • How can I to control any element of my GUI from another class?

    How can I to control any element of my GUI from another class?

    For that, you need the external class to have the reference to your element.. If your idea is to change basic properties like width, height etc.. then you can have the constructor of the external class to take the object of the parent of your class as the parameter and modify ..
    However, if the properties to be altered/accessed are custom to your element, then you will have to have the class accept an object of your class as the parameter. No other option..
    What exactly is your requirement?

  • How Do I Run A Class From Another Class?

    Hiya everyone, id like to know how to run a class from another class.
    Ive got a Login class which extends a JFrame and a Personnel class which also extends a JFrame. When i press the login button (in Login class), ive got it to decide if password/login are acceptable and if they are, I want the Login class to close then run the Personnel class.
    Im just after the code which says to close this class and run the Personnel class. How do i do that?
    Ive researched this but couldnt get an understandable answer!
    Help would be much appreciated, Ant...

    This is the Login Class:
    public class MainMenu extends javax.swing.JFrame {
        Statement statement = null;
        int currentRecord;
        ResultSet rs = null;
        String name = null, job = null, mission = null, login = null, password = null;
        String loginVal;
        String passwordVal;
        /** Creates new form MainMenu */
        public MainMenu() {
            initComponents();
            try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String filename = System.getProperty("user.dir") + "/src/Personnel.mdb";
                String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + filename;
                Connection conn = DriverManager.getConnection( database , "","");
                statement = conn.createStatement();
                System.out.println("Connected...ok");
            } catch (Exception e) {
                System.err.println("Got a connection Problem!");
                System.err.println(e.getMessage());
        private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                        
            loginVal = txtLogin.getText();
            passwordVal = txtPassword.getText();
            String name = null, job = null, mission = null, login = null, password = null;
            try{
                rs = statement.executeQuery("SELECT Login,Password FROM Personnel WHERE Login = '" + loginVal + "' ");
                System.out.println("TRYING SELECT CLAUSE");
                if(rs.next()){
                    System.out.println("THERE IS A NEXT RECORD");
                    login = rs.getString(1);
                    password = rs.getString(2);
                    System.out.println("GOT THE NEXT RECORD");
                    System.out.println(login + password);
                System.out.println("Query Complete");
            }catch(Exception s){
                //s.printStackTrace();
                System.out.println("NO RECORDS EXIST FOR THIS LOGIN ID");
            if(passwordVal.equals(password)){
                System.out.println("Access Granted"); //CLOSE MAIN AND RUN CONTROL CLASS
            } else{
                System.out.println("Access Denied"); //RE-RUN CLASS
        }                 

  • Problem getting arraylist from another class

    I am trying to call information about an arraylist from another class. I am using this code to call the size of an arraylist:
    import java.io.*;
    public class Test
        public static void main(String argv[]) throws IOException
    Echo03 thing = new Echo03();
    int y=thing.value();
    System.out.println(y);
    Echo03 thing2 = new Echo03();
    int x=thing2.percent.size();
    System.out.println(x);
    }from another file which starts like this:
    public class Echo03 extends DefaultHandler
    static ArrayList<String> percent = new ArrayList<String>();
    static ArrayList<String> text = new ArrayList<String>();
      int a;
    public int value(){
         return percent.size();
      public static void main(String argv[]) throws IOException
        {The second file is based on an example piece of code from the Java website. I havent posted the whole thing, but if it is relevant then please ask.
    Anyway when I run Echo03 by itself, the arraylist has a size of 2. But when I run it from the Test file, it says a size of 0. Is this because the data is not being transferred between the classes? Or is the Echo03 program not executing (and hence the arraylist is not filling up)?
    How can I fix this? I have tried 2 ways of calling the data (As seen in my Test file). Neither work.

    I didnt post the full bit of the code for the second one. Here it is:
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import java.util.ArrayList;
    import java.awt.*;
    import javax.swing.*;
    public class Echo03 extends DefaultHandler
    static ArrayList<String> percent = new ArrayList<String>();
    static ArrayList<String> text = new ArrayList<String>();
      int a;
      public static void main(String argv[]) throws IOException
            if (argv.length != 1) {
                System.err.println("Usage: cmd filename");
                System.exit(1);
            // Use an instance of ourselves as the SAX event handler
            DefaultHandler handler = new Echo03();
            // Use the default (non-validating) parser
            SAXParserFactory factory = SAXParserFactory.newInstance();
            try {
                // Set up output stream
       out = new OutputStreamWriter(System.out, "UTF8");
                // Parse the input
                SAXParser saxParser = factory.newSAXParser();
                saxParser.parse( new File(argv[0]), handler);
    for (int b=0; b<percent.size();b++){
         System.out.println(percent.get(b+1));
            } catch (Throwable t) {
            System.exit(0);
        static private Writer  out;
        public void startElement(String namespaceURI,
                                 String lName, // local name
                                 String qName, // qualified name
                                 Attributes attrs)
        throws SAXException
            if (attrs != null) {
    StringBuffer sb = new StringBuffer (250);        
    for (int i = 0; i < attrs.getLength(); i++) {
                    nl();
                    emit(attrs.getValue(i));
              sb.append (attrs.getValue(i));
    String sf = sb.toString ();
    percent.add(sf);
    System.out.println(" String: "+sf); a++;
        public void characters(char buf[], int offset, int len)
        throws SAXException
             emit(" ");
            String s = new String(buf, offset, len);
            if (!s.trim().equals("")) {text.add(s); emit(s);}
    //===========================================================
        // Utility Methods ...
        //===========================================================
        // Wrap I/O exceptions in SAX exceptions, to
        // suit handler signature requirements
        private void emit(String s)
        throws SAXException
            try {
                out.write(s);
                out.flush();
            } catch (IOException e) {
                throw new SAXException("I/O error", e);
        // Start a new line
        private void nl()
        throws SAXException
            String lineEnd =  System.getProperty("line.separator");
            try {
                out.write(lineEnd);
            } catch (IOException e) {
                throw new SAXException("I/O error", e);
    }

  • How to kill one class from another class

    I need to dipose one class from another class.
    So that first i have to find what are all threads running in that class and then to kill them
    Assist me.

    Subbu_Srinivasan wrote:
    I am explaining you in clear way
    No you haven't been.
    >
    In my application i am handling many JInternalFrame.Simultaneously i am running working on more than one frame.
    Due to some poor performance of some thread in one JInternalFrame,the thread is keeps on running .
    i could not able to proceed further on that screen.
    So i have to kill that JInternalFrame.Yoinks.
    To be begin with your problem sounds like you are doing everything in one thread. So stop doing that. Second when you get it split up and if a task is taking too much time then interrupt it. No kill. Interrupt. This means the worker thread needs to check sometimes if it has been interrupted.

  • Can I access my itunes lib from another comp on my wireless network at home

    How can I access my itunes library from another computer in my home. The computers are on a wireless network. The computer that we have used as our main computer and that has our library on it is running Windows XP. The laptop that I want to use to access the library is running VISTA. ANy ideas?

    You can sign into the iTunes Store on it, but your library won't be automatically put onto it.
    (100361)

  • My ipod touch has a huge collection of music that I don't want to lose or replace but my computer has now crashed beyond recovery. How can I access my itunes account from another computer or transfer my playlists to another computer from my ipod?

    My ipod touch has a huge collection of music that I don't want to lose or replace but my computer has now crashed beyond recovery. How can I access my itunes account from another computer or transfer my playlists to another computer from my ipod?

    You can transfer iTunes purchases to your "new" computer by
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    You can transfer other stuff by:
    Best iPod to PC
    How to transfer or sync files from iPod to PC - Windows mac iPhone iPod software reviews - Software Wiki

  • Getting a variable value from another class

    Is there any way to get the value of a variable from another class? I have a file that calls another that does some checking then gives a true or false. The place the checking is done is inside an ActionListener I want to use that value in the file that calls the second. Any help would be great.

    in 'another class', implement a method,
    public boolean isCheckedOutOK( Object obj )
    do the comparison in that method (use a suitable argument)

  • Calling a method from another class... that requires variables?

    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
         cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
    Any ideas! :D

    f1d wrote:
    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
    cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
    but I'm not sure how!
    setDate(16, 6, 2008);
    I have tried, but then I get errors such as ')' expected?
    Any ideas! :Dyou need to post your code if you're getting specific errors like that.
    but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
    i.e. syntax error

Maybe you are looking for