Making object accesible from other class?

hi all
how can i have an object of class to be accesible from other class?
thanks

It's not clear what you mean by "object of class". Do you mean fields within an object. Do you mean using an object of one class within the code of another?
For most named objectes in java, whether field, method or class, there are four levels of access.
public means accessible from anywhere in the program
private means accessible only from the same source file.
protected means only from the class, or a class that extends it.
or if you don't put any of these keywords it means accessible only from the same package, that is set of source files in a single directory.

Similar Messages

  • Calling a object of class from other class's function with in a package

    Hello Sir,
    I have a package.package have two classes.I want to use object of one class in function of another class of this same package.
    Like that:
    one.java
    package co;
    public class one
    private String aa="Vijay";  //something like
    }main.java:
    package co;
    import java.util.Stack;
    public class main extends Stack
    public void show(one obj)
    push(obj);
    public static void main(String args[])
    main oo=new main();
    }when I compile main class, Its not compile.
    Its give error.can not resolve symbol:
    symbol: class one
    location: class co.main
    public void show(one obj)
                              ^Please help How that compile "Calling a object of class from other class's function with in a package" beacuse I want to use this funda in an application

    kumar.vijaydahiya wrote:
    .It is set in environment variable.path=C:\bea\jdk141_02\bin;.,C:\oraclexe\app\oracle\product\10.2.0\server\bin;. command is:
    c:\Core\co\javac one.javaIts compiled already.
    c:\Core\co\javac main.javaBut it give error.
    Both java classes in co package.Okay, open a command prompt and execute these two commands:
    // to compile both classes:
    javac -cp c:\Core c:\Core\co\*.java
    // to run your main-class:
    java -cp c:\Core co.main

  • Delete scroller from other class

    Hi.
    I have FlashSite class where after clicking to button i see page with text and with scroll.
    If i click to 'close' button i want removeChild this page, text and scroll.
    But for scroll i use code from other class. (i insert this class like: import classes.Scroller.*;)
    So, how i can remove this scroller?
    code:
    public function lilyContent():void
                   // create a sample pane
                   addChild(lilyPageScroll);
                   lilyPageScroll.x = 360;
                   lilyPageScroll.y = 400;
                   // then attach a new scroller to the pane
                   var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
    i use this line:
    var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
    to add scroller.
    all code for FlashSite class:
    package
         import flash.display.*;
         import flash.text.*;
         import flash.events.*;
         import classes.Scroller.*;
         public class FlashSite extends MovieClip 
              var lilyDeskBack:LilyDescriptionBackground = new LilyDescriptionBackground();
              var lilyPageScroll = new LilyContent();
              //constructor
              public function FlashSite()
                   stop();
                   addEventListener(Event.ENTER_FRAME, flashSiteLoading);
              public function flashSiteLoading(event:Event)
                   var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
                   var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
                   var mcKLoaded:int=mcBytesLoaded/1024;
                   var mcKTotal:int=mcBytesTotal/1024;
                   flashSiteLoading_txt.text="Loading: "+mcKLoaded+"Kb of "+mcKTotal+"Kb";
                   if (mcBytesLoaded>=mcBytesTotal)
                        removeEventListener(Event.ENTER_FRAME, flashSiteLoading);
                        gotoAndPlay('welcomeSite');
                        lilyBtn.addEventListener(MouseEvent.CLICK, lilyDescription);
                        roseBtn.addEventListener(MouseEvent.CLICK, roseDescription);
                        jasmineBtn.addEventListener(MouseEvent.CLICK, jasmineDescription);
                        irisBtn.addEventListener(MouseEvent.CLICK, irisDescription);
              public function lilyDescription(event:MouseEvent):void
                   trace("Lily description goes here.");
                   roseBtn.visible = false;
                   jasmineBtn.visible = false;
                   irisBtn.visible = false;
                   addChild(lilyDeskBack);
                   lilyDeskBack.x = 350;
                   lilyDeskBack.y = 330;
                   lilyContent();
                   lilyDeskBack.LilyDesckClose_btn.addEventListener(MouseEvent.CLICK, closeLilyDescription);
              public function closeLilyDescription(event:MouseEvent):void
                   trace("close Lily description");
                   removeChild(lilyDeskBack);
                   removeChild(lilyPageScroll);
                   lilyScroller.visible = false;
                   roseBtn.visible = true;
                   jasmineBtn.visible = true;
                   irisBtn.visible = true;
              public function roseDescription(event:MouseEvent):void
                   trace("Rose description goes here.");
              public function jasmineDescription(event:MouseEvent):void
                   trace("Jasmine description goes here.");
              public function irisDescription(event:MouseEvent):void
                   trace("Iris description goes here.");
              public function lilyContent():void
                   // create a sample pane
                   addChild(lilyPageScroll);
                   lilyPageScroll.x = 360;
                   lilyPageScroll.y = 400;
                   // then attach a new scroller to the pane
                   var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
    Thanks for help

    Make the lilyScroller object a class level object.
    Add to 'closeLilyDescription' method 'removeChild(lilyScroller);'
    package
         import flash.display.*;
         import flash.text.*;
         import flash.events.*;
         import classes.Scroller.*;
         public class FlashSite extends MovieClip 
              var lilyDeskBack:LilyDescriptionBackground = new LilyDescriptionBackground();
              var lilyPageScroll = new LilyContent();
              var lilyScroller;
              //constructor
              public function FlashSite()
                   stop();
                   addEventListener(Event.ENTER_FRAME, flashSiteLoading);
              public function flashSiteLoading(event:Event)
                   var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
                   var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
                   var mcKLoaded:int=mcBytesLoaded/1024;
                   var mcKTotal:int=mcBytesTotal/1024;
                   flashSiteLoading_txt.text="Loading: "+mcKLoaded+"Kb of "+mcKTotal+"Kb";
                   if (mcBytesLoaded>=mcBytesTotal)
                        removeEventListener(Event.ENTER_FRAME, flashSiteLoading);
                        gotoAndPlay('welcomeSite');
                        lilyBtn.addEventListener(MouseEvent.CLICK, lilyDescription);
                        roseBtn.addEventListener(MouseEvent.CLICK, roseDescription);
                        jasmineBtn.addEventListener(MouseEvent.CLICK, jasmineDescription);
                        irisBtn.addEventListener(MouseEvent.CLICK, irisDescription);
              public function lilyDescription(event:MouseEvent):void
                   trace("Lily description goes here.");
                   roseBtn.visible = false;
                   jasmineBtn.visible = false;
                   irisBtn.visible = false;
                   addChild(lilyDeskBack);
                   lilyDeskBack.x = 350;
                   lilyDeskBack.y = 330;
                   lilyContent();
                   lilyDeskBack.LilyDesckClose_btn.addEventListener(MouseEvent.CLICK, closeLilyDescription);
              public function closeLilyDescription(event:MouseEvent):void
                   trace("close Lily description");
                   removeChild(lilyDeskBack);
                   removeChild(lilyPageScroll);
                   removeChild(lilyScroller);
                   lilyScroller.visible = false;
                   roseBtn.visible = true;
                   jasmineBtn.visible = true;
                   irisBtn.visible = true;
              public function roseDescription(event:MouseEvent):void
                   trace("Rose description goes here.");
              public function jasmineDescription(event:MouseEvent):void
                   trace("Jasmine description goes here.");
              public function irisDescription(event:MouseEvent):void
                   trace("Iris description goes here.");
              public function lilyContent():void
                   // create a sample pane
                   addChild(lilyPageScroll);
                   lilyPageScroll.x = 360;
                   lilyPageScroll.y = 400;
                   // then attach a new scroller to the pane
                   lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");

  • 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?

  • 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" );

  • How  add buttons to Jframe from other class

    Hi, a have a little problem;)
    I want make a JFrame, but i want to add JButtons from other class. Now I have something like that:
    My JFrame class:
    package windoow;
    import javax.swing.*;
    import java.awt.*;
    public class MyWindow extends JFrame {
           Butt buttons ;
            public Window(String s) {
                     super(s);
                    this.setSize(600, 600);
                    this.setVisible(true);
                    Buttons();
                public void Buttons(){
                    setLayout(null);            
                   buttons = new Butt();
                   buttons.mywindow =this;
    } My class with buttons:
    package windoow;
    import javax.swing.JButton;
    public class Butt {
            MyWindow mywindow;
            JButton b1;
            Butt(){
                      b1 = new JButton("Button");
                      b1.setBounds(100,100,100,20);
                      mywindow.add(b1);  
    } and i have NullPointerException.
    When i try to make new MyWindow in Butt clas i have something like StackOverFlow.
    what should i do?

    Your null pointer exception is occuring because, in your Butt() constructor, you are calling mywindow.add(b1), but you don't set mywindow until after you call the constructor in the MyWindow::Buttons() method.
    And, if you try to create a new MyWindow() in your Butt() constructor, and, assuming that you are calling the MyWindow::Window(String s) method from the MyWindow() constructor (which is not clear from the code fragment you posted), then Butt() calls new MyWindow() which calls Window(String s) which calls Butt() which calls ... and so on, until the stack overflows.
    One possible solution ... pass your MyWindow reference into your Butt() constructor as this, as so:
    public void Buttons()
       // stuff deleted
      buttons = new Butt( this );
       // stuff deleted
    // AND
    Butt( MyWindow mw )
       // stuff deleted
      mywindow = mw;
      mywindow.add( b1 ); // b1 created in stuff deleted section  
    }Also, I would call setVisible(true) as the last thing I did during the construction of the frame. This realizes the frame, and from that point forward, most changes to the frame should be made on the event thread.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Set JComponent from other class

    Hi, I have problem from set any JComponent (JButton,JTable, etc.)
    in class from other class.
    I have class A. In class I have JButton and JTable. In this class I have function, in that are I create new instance class B. Class B have function, that are set properties any item in class A.
    class A
    function createAnotherClass(){
    B bclass = new B();
    bclass.setItemInClassA(this);
    function setItem(){
    jTable.setBackground(Color.RED);
    etc.
    class B
    function setItemInClassA(A a){
    a.setItem();
    This is only example, but I need your hepl. Thank you

    hahaha, yeah right,
    i think we do not understand your problem.

  • Append output from other class

    Hello!
    I have a blackjack game where I have used a.append(); to send output to a graphic textarea instead of the console.
    My game consists of several classes where one of them is the one who runs the actual game with graphic things and so on.
    In this class the a.append works fine since the textarea is in that class.
    But how shall I do to append output in other classes? If I try to compile I get the error message "Error resolving symbol" since the other class does not recognize the graphical textarea a.
    How do I make the other classes to recognize the graphical object?
    Thanks very much!

    This is the computer class:
    import javax.swing.*;
    public class Dator extends Spelare {
    private Spelare motspelare;
    public Dator(Kortbunt k, Spelare mot){
    super(k);
    motspelare = mot;
    public void spela() {
    nyttSpel();
    while (p < 21 && p < motspelare.po�ng()) {
    a.append("Datorn fick " + nyttKort() + "\n");
    a.append("Datorn har " + p + " po�ng.\n");
    The a.append only works in the class where the graphical object lies. I want this class to recognize the graphic object in the other class so that it understands the append code.

  • Calling repaint from other Class file.

    Hi,
    First of all i am pretty new to Java so I hope you understand what I am trying to explain..
    I am trying to create an applet which draws some polygons on the screen. For the drawing of these polygons I have created another class which is located in another package but the same project. I plan to use this second package as some kind of library so that i can simple call 2 or 3 functions in future applets to draw these polygons (which always have the same shape). In the library file i have created a contructor, a draw function and some other functions to change some properties. I also created a function that created a popup window as soon as i click on one of the polygons i have created. In the popup some buttons are available which change the color of the polygon. All this works fine, but the problem i have is the following:
    When i click a button the main class (in package 1) needs to be repainted for the changes to be visable. But the main class can always be a different one. Is it possible to check in the class in the library package, which class from the main package called the class, and execute a repaint() on that class. So i have the following situation:
    Package 1 (Applets):
    package applets;
    class myApplet extends Applet implements .... {
    private Tank tank1 = new Tank(20, 20, 100, 200);
    private Tank tank2 = new Tank(250, 20, 100, 200);
    public void paint(Graphics g) {
    tank1.drawTank(g);
    tank2.drawTank(g);
    public void mouseClicked(MouseEvent e) {
    tank1.openWindow();
    tank2.openWindow();
    Package 2 (Library):
    package applets.library;
    class Tank {
    public Tank(int xPos, int yPos, int height, int width) {
    public void drawTank(Graphics g) {
    public void openWindow() {
    new myWindow("Window1");
    public class myWindow extends Frame {
    public myWindow(String name) {
    show();
    public boolean action(Event e, Object arg) {
    return true;
    So what i want to do is: In class Tank in the public class myWindow in the method action, i want to call the repaint() of the class myApplet
    I hope my problem is clear to you, as you may have noticed i have a little trouble explaining it clearly..

    First of all thanks a lot for your reply and sorry for my way of programming. Like i said i am pretty new to Java, i am actually only programming for about 2 weeks and trying to learn from some examples on the internet.
    I dont really understand what you want me to do, is it maybe possible to give a little bit of sample code? That would help me a lot.
    Maybe some background information about the project will help a bit too.
    I work at a company that develops automation solutions. We program PLC's and SCADA systems. Now Siemens has some PLC's that support Java applets which make it possible to visualize industrial processes. Now i am trying to figure out if it is possible to start developing own java applets for visualisation in the future. Since most programmers here have no experience in any higher programming language i want to keep it as simple as possible, by developing libraries that do the most of the programming work for them.
    Now i want to create the first part of this library by programming some kind of storage tank. This tank always has a valve. when i click on the valve a popup should open with the operation button to open of close that valve. When a valve is opened it should be colored green and when its closed it should be colored gray or something. The Tank class has a couple of methods:
    drawTank(); to draw the tank in my applet,
    openValve(); to open the Valve,
    closeValve(); to close the Valve,
    After all this is created i want to be able to use this class in all my other classes and create a tank by simple making a new Tank object, draw it on my applet using the drawTank() method and open or close the Valve using the other 2 methods, however when i open or close the Valve the color of the valve should change so i must be able to call the repaint of all the classes that use my Tank class, but i want to do that INSIDE my Tank class.
    If there is another way of doing this i would love to hear so, but i would help me a lot if you can explain in a little bit of sample code. It doesn't have to be really long or detailed.
    Thnx in advance

  • Help with GUI (calling one class from other class)

    Hi everybody,
    I am new at GUI and I need your help..
    I have a JPanel, named "holdAll", layout of which is set to BorderLayout. I have implemented all other JPanels in different class files. For example, I have TopPanel, LeftPanel, etc. as shown below
    LeftPanel myLeft = new LeftPanel();
    holdAll.add(myLeft, BorderLayout.WEST);
    RightPanel myRight = new RightPanel();
    holdAll.add(myRight, BorderLayout.EAST);
    TopPanel myTop = new TopPanel();
    holdAll.add(myTop, BorderLayout.NORTH);
    MiddlePanel myMiddle = new MiddlePanel();
    holdAll.add(myMiddle, BorderLayout.CENTER);
    BottomPanel myBottom = new BottomPanel();
    holdAll.add(myBottom, BorderLayout.SOUTH);
    That works well but I have difficulties in ActionListeners.. For example, in my TopPanel class I have the code below:
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    myImage newImage = new myImage(file);
    System.out.println(newImage.myHashCode());
    Here, if I have upload new image, then I have to update the listImage in the LeftPanel class.. But, I could not access the lstImage object in the LeftPanel class from the actionListener event in the TopPanel class.
    What should I do? Is my design poor?

    public class TopPanel extends JPanel implements ActionListener { //it doesn't allow "extends JPanel, Observable"
    JFileChooser fc;
    JButton btnInsert;
    JButton btnDelete;
    public TopPanel() {
    setLayout(new FlowLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    btnInsert = new JButton("Insert");
    btnDelete = new JButton("Delete");
    JLabel myLabel = new JLabel(" Search : ");
    JTextField txtSearch = new JTextField();
    txtSearch.setColumns(20);
    JToolBar searchToolBar = new JToolBar();
    fc = new JFileChooser();
    btnInsert.addActionListener(this);
    searchToolBar.add(btnInsert);
    searchToolBar.add(btnDelete);
    searchToolBar.add(myLabel);
    searchToolBar.add(txtSearch);
    add(searchToolBar);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    *//Here I want to send fc.GetName() to the JList in the LeftPanel*
    my LeftPanel class is below:
    public class LeftPanel extends JPanel{
    public LeftPanel(){
    this.setLayout(new BorderLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    JPanel pnlButtons = new JPanel();
    JButton btnName = new JButton("Name");
    JButton btnSize = new JButton("Size");
    JButton btnDate = new JButton("Date");
    pnlButtons.add(btnName);
    pnlButtons.add(btnSize);
    pnlButtons.add(btnDate);
    pnlButtons.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    JPanel pnlImage = new JPanel();
    JList lstImage = new JList();
    lstImage.setVisible(true);
    pnlImage.add(new JScrollPane(lstImage));
    add(pnlButtons, BorderLayout.NORTH);
    add(pnlImage, BorderLayout.CENTER);
    Is there any simple way?

  • Calling methods from other classes

    I have a bunch of little java files in a folder, do I need to make a package in order to access all the methods in all the classes, or can I just make an instance of any of the methods because all the classes are in the same folder?

    HI,
    If your methods have a "public" modifier (and the class does too) then you can instantiate your classes as objects from that (so-called) "default" package in any other class or object in any other package and then call the methods on those instantiated objects as you please.
    If that sounds confusing... I'd seriously try the excellent tutorials at this site, especially "the java tutorial".
    /k1

  • JTextfield  listening for changes from other class

    Hi,
    Assuming I have a Jtextfield in one of the class1 extend Jframe,
    how do I update the jtextfield so that it could up make accessible by other class and continuously updated to reflect the input for value rom another class2.
    In other words very much similar to the observable model view concept
    class 1 may be look like
    private void initComponents() {
    jTextField1 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setEditable(false);
    class 2 may be look similar to the following
    public void out_1(){
    setStop1("N");
    for (int i=1;i<100;i++){
    class_1.getJTextField1().setText(String.valueOf(i)); // System.out.println(i);
    setOuti(i);
    setStop1("N");

    HI,
    I have attempted with the following coding , test 1 the source display generated using Netbeans GUI , t est2 the worker code ,and mybean the bean , so far nothing seems to work .
    I have not try the threaded swing concept as I am not familar with the concurrency but i am not sure whether propertylistener will do the job or not
    In summary , list of method employed are :
    binding the jtextfield1 to a bean,
    jtextfield add document listener ,
    Coding objective
    1. Test 1 defined jtexfield1 and jbutton
    2 Jbutton added actionlistener , where upon click,
    Execute Test 2 which will assign a series of integer to the bean , own setters & getters, Output is achieved via Test 1 jtextfield1 supposingly to display all the running number from 1 to 99 continuously until the test2 out_1 method finished the execution
    Anyone could provide the assistance .
    Thank
    * Test_1.java
    * Created on July 25, 2007, 9:23 PM
    package sapcopa;
    import java.beans.PropertyChangeListener;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.text.Document;
    import sapcopa.MyBean.*;
    public class Test_1 extends javax.swing.JFrame {
    /** Creates new form Test_1 */
    // private Test_2 t2=new Test_2();
    private String input_txt;
    public Test_1() {
    myBean1=new MyBean();
    myBean1.addPropertyChangeListener(new java.beans.PropertyChangeListener(){
    public void propertyChange(java.beans.PropertyChangeEvent evt) {
    bean_chg(evt);
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    myBean1 = new sapcopa.MyBean();
    jTextField1 = new javax.swing.JTextField();
    jTextField1.getDocument().addDocumentListener(new MyDocumentListener());
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setEditable(false);
    jTextField1.setText(myBean1.getRecord_Process());
    jTextField1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
    public void propertyChange(java.beans.PropertyChangeEvent evt) {
    txt1_chg(evt);
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    But1(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(19, 19, 19)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGap(32, 32, 32)
    .addComponent(jButton1)))
    .addContainerGap(131, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(21, 21, 21)
    .addComponent(jButton1)
    .addContainerGap(216, Short.MAX_VALUE))
    pack();
    }// </editor-fold>//GEN-END:initComponents
    private void txt1_chg(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txt1_chg
    // TODO add your handling code here:
    //myBean1=new MyBean();
    try {
    jTextField1.setText(myBean1.getRecord_Process());
    } catch (Exception e){
    e.printStackTrace();
    }//GEN-LAST:event_txt1_chg
    private void bean_chg(java.beans.PropertyChangeEvent evt){
    jTextField1.setText(myBean1.getRecord_Process());
    private void But1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_But1
    //getJTextField1().getDocument().addDocumentListener(new MyDocumentListener());
    Test_2 t2=new Test_2();
    t2.out_1();
    try{
    System.out.println("Button 1 mybean->"+myBean1.getRecord_Process());
    } catch (Exception e){
    e.printStackTrace();
    // TODO add your handling code here:
    }//GEN-LAST:event_But1
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Test_1().setVisible(true);
    public javax.swing.JTextField getJTextField1() {
    return jTextField1;
    public void setJTextField1(javax.swing.JTextField jTextField1) {
    this.jTextField1 = jTextField1;
    class MyDocumentListener implements DocumentListener {
    final String newline = "\n";
    public void insertUpdate(DocumentEvent e) {
    // updateLog(e, "inserted into");
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void removeUpdate(DocumentEvent e) {
    //updateLog(e, "removed from");
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void changedUpdate(DocumentEvent e) {
    //Plain text components don't fire these events.
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void updateLog(DocumentEvent e, String action) {
    Document doc = (Document)e.getDocument();
    int changeLength = e.getLength();
    // jTextField1.setText(String.valueOf(changeLength));
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public String getInput_txt() {
    return input_txt;
    public void setInput_txt(String input_txt) {
    this.input_txt = input_txt;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField jTextField1;
    private sapcopa.MyBean myBean1;
    // End of variables declaration//GEN-END:variables
    * Test_2.java
    * Created on July 25, 2007, 9:26 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package sapcopa;
    import sapcopa.MyBean.*;
    public class Test_2 {
    private Test_1 t1=new Test_1();
    private int outi;
    private String stop1;
    MyBean mybean;
    /** Creates a new instance of Test_2 */
    public Test_2() {
    public void out_1(){
    setStop1("N");
    mybean=new MyBean();
    for (int i=1;i<100;i++){
    mybean.setRecord_Process(String.valueOf(i));
    setOuti(i);
    setStop1("N");
    setStop1("Y");
    public int getOuti() {
    return outi;
    public void setOuti(int outi) {
    this.outi = outi;
    public String getStop1() {
    return stop1;
    public void setStop1(String stop1) {
    this.stop1 = stop1;
    * MyBean.java
    * Created on July 24, 2007, 12:00 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package sapcopa;
    import javax.swing.JTextField;
    public class MyBean {
    /** Creates a new instance of MyBean */
    public MyBean() {
    * Holds value of property record_Process.
    private JTextField txt_rec_process;
    private String record_Process;
    * Utility field used by bound properties.
    private java.beans.PropertyChangeSupport propertyChangeSupport = new java.beans.PropertyChangeSupport(this);
    * Adds a PropertyChangeListener to the listener list.
    * @param l The listener to add.
    public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
    propertyChangeSupport.addPropertyChangeListener(l);
    * Removes a PropertyChangeListener from the listener list.
    * @param l The listener to remove.
    public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
    propertyChangeSupport.removePropertyChangeListener(l);
    * Getter for property record_Process.
    * @return Value of property record_Process.
    public String getRecord_Process() {
    return this.record_Process;
    * Setter for property record_Process.
    * @param record_Process New value of property record_Process.
    public void setRecord_Process(String record_Process) {
    String oldRecord_Process = this.record_Process;
    this.record_Process = record_Process;
    propertyChangeSupport.firePropertyChange("record_Process", oldRecord_Process, record_Process);
    * Holds value of property rec_Match.
    private String rec_Match;
    * Getter for property rec_Match.
    * @return Value of property rec_Match.
    public String getRec_Match() {
    return this.rec_Match;
    * Setter for property rec_Match.
    * @param rec_Match New value of property rec_Match.
    public void setRec_Match(String rec_Match) {
    String oldRec_Match = this.rec_Match;
    this.rec_Match = rec_Match;
    propertyChangeSupport.firePropertyChange("rec_Match", oldRec_Match, rec_Match);
    public JTextField getTxt_rec_process() {
    return txt_rec_process;
    public void setTxt_rec_process(JTextField txt_rec_process) {
    JTextField oldTxt_rec_process=this.txt_rec_process;
    this.txt_rec_process = txt_rec_process;
    propertyChangeSupport.firePropertyChange("txt_rec_process", oldTxt_rec_process, txt_rec_process);
    }

  • How do I make the controls on JPanel instantiated from other class visible?

    I am using Netbeans GUI editor to create a GUI. It's really terrific....but... I have aJFrame form containing a JPanel. I also have a "panel" class that extends JPanel. I would like to insantiate an object of teh "panel" class and use it as the JPanel in the JFrame. Sounds simple enough.
    When I do this, I see the JPanel from my "panel" class gets instantiated and used in the JFrame (yay), but the button and text label do not show up.
    The JFrame is in the class/file NewJFrame.java and the JPanel is in the class/file TestJPanel.java. I'm really about to pull my hair out. ;-) Any help would be greatly appreciated...I'm sure it must be something simple I have forgotten to do.
    Here is code for NewJFrame.java
    package my.gui;
    public class NewJFrame extends javax.swing.JFrame {
    public NewJFrame() {
    initComponents();
    @SuppressWarnings("unchecked")
    private void initComponents() {
    jPanel1 = new my.gui.TestJPanel();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.revalidate();
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 400, Short.MAX_VALUE)
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 300, Short.MAX_VALUE)
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    pack();
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    private javax.swing.JPanel jPanel1;
    And the code for TestJPanel.java
    package my.gui;
    import java.awt.Color;
    public class TestJPanel extends javax.swing.JPanel {
    public TestJPanel() {
    initComponents();
    this.setBackground(Color.white);
    @SuppressWarnings("unchecked")
    private void initComponents() {
    jLabel1 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    jLabel1.setText("jLabel1");
    jButton1.setText("jButton1");
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .addContainerGap()
    .add(jLabel1)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
    .add(jButton1)
    .addContainerGap(273, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(103, 103, 103)
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel1)
    .add(jButton1))
    .addContainerGap(174, Short.MAX_VALUE))
    public javax.swing.JButton jButton1;
    public javax.swing.JLabel jLabel1;
    }

    If you really want to learn Swing, I advise you to put the NetBeans away, and dive into the Sun Swing tutorials where you'll learn to code your Swing by hand. One of the main things that you'll learn -- and likely the thing that is tripping your current code up -- is how to use layout managers in a way that will allow you to flexibly place JPanels and other components where you want them, where they'll resize if need be, and where they'll be visible when you want them to be.
    Much luck.

  • Calling object methods from other objects

    ok im trying to build a little windows application which shows a few thumbnails of pictures in a folder.
    I have a mainForm class that runs all the jFrame and menus, status bar etc, it has 2 jPanes, one with a jTree that browses the directories and the other is set blank and adds a few custom component objects depending on how many images are in the directory it does contains a few objects all from one custom component class that shows an image and a label below it.
    What i want to do is call the mainForm statusbar from within my custom component class. I have tried many things but cant seem to do it.
    How do i do this in java? or can anyone point me in the right direction for some reading material, websites etc?
    thanks

    if i have correctly understood what you are asking (big assumption)...
    you could just pass a reference to the main form into the custom class when you construct it (the custom class) - but this introduces unnessary coupling between the two classes and this approach will quickly get messy and hard to maintain.
    a better approach is to use the Mediuator pattern.
    have a look at
    www.mindspring.com/~mgrand/pattern_synopses.htm for example.

  • ProgressMonitor in thred, call from other class

    Hi all
    I have a problem using the ProgressMonitor... I just want to update the progress from another class.
    So what i was thinking was:
    I could implement a method that invoked the thread, and thereby updating the progress.
    The problem occurs when the calculating steps is going. The parent class calls ProgressDiff fine but it doesn't update it, it doesn't even show anything. Just when the task is finished it says, simulation done!!
    I have tried searching alot on these forums, and on google, but all methods implementing progressmonitor uses a call from within the class. <- Not what I want. :=)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.beans.*;
    public class ProgressDiff extends JFrame {
        public ProgressMonitor progressMonitor;
         public int tll;
        public ProgressDiff(int maks, String set) {
              super("Progress");
              setSize(250, 100);
            progressMonitor = new ProgressMonitor(null,
                                      "Differentiere og l�ser\n" + set,
                                      "", 0, maks);
            progressMonitor.setProgress(0);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setProgressTal(0, false);
              setLocationRelativeTo(null);
              setVisible(true);
        public void setProgressTal(int fremGang, boolean done) {
              tll = fremGang;
              SwingUtilities.invokeLater(new Update());
              if (done) {
                   Toolkit.getDefaultToolkit().beep();
                   JOptionPane.showMessageDialog(null,
                        "Simuleringen er f�rdig."
                        , "F�rdig",
                        JOptionPane.INFORMATION_MESSAGE);
         class Update implements Runnable {
            public void run() {
                   if (progressMonitor.isCanceled()) {
                   Toolkit.getDefaultToolkit().beep();
                   JOptionPane.showMessageDialog(null,
                        "Simuleringen er f�rdig."
                        , "F�rdig",
                        JOptionPane.INFORMATION_MESSAGE);
                   } else {
                        progressMonitor.setProgress(tll);
                        progressMonitor.setNote(String.format("Completed %d%%.\n", tll));
    }Any help would be apreciable!!
    Thx.

    Thx for the reply, I now have a working Progressmonitor which i easily can control
    import java.awt.Toolkit;
    import javax.swing.ProgressMonitor;
    *  Use of a ProgressMonitor. This class implements an easy to use progressmonitor for use in other classes.
    * @author     Nick Andersen
    * @created    4. marts 2008
    * @version    1.00
    public class ProgressMonitorSetup {
         private ProgressMonitor progressMonitor;
         private String title;
         private int min;
         private int progress;
         private int max;
         private String note;
         private String complete;
         private String cancel;
         private String completeTotal;
          * Constructor af ProgressMonitorSetup
         public ProgressMonitorSetup() {
              title = "K�rsel af langt job";
              min = 0;
              max = 100;
              complete = "Fremgang: ";
              cancel = "Job afbrudt.";
              completeTotal = "Job f�rdigt.";
              note = "";
          * Constructor af ProgressMonitorSetup
          * @param  title          The title in Progressmonitor
          * @param  min            The minimum value in the progressmonitor
          * @param  max            The maximum value in the progressmonitor
          * @param  complete       Beskrivelse af Parameteren
          * @param  completeTotal  Beskrivelse af Parameteren
          * @param  cancel         Beskrivelse af Parameteren
         public ProgressMonitorSetup(String title, int min, int max, String complete, String completeTotal, String cancel) {
              this.title = title;
              this.min = min;
              this.progress = min;
              this.max = max;
              this.complete = complete;
              this.completeTotal = completeTotal;
              this.cancel = cancel;
              note = "";
          *  S�tter title attributten af ProgressMonitorSetup object
          * @param  title  Den nye title v�rdi
         public void setTitle(String title) {
              this.title = title;
          *  S�tter minimum attributten af ProgressMonitorSetup object
          * @param  min  Den nye minimum v�rdi
         public void setMinimum(int min) {
              this.min = min;
          *  S�tter maximum attributten af ProgressMonitorSetup object
          * @param  max  Den nye maximum v�rdi
         public void setMaximum(int max) {
              this.max = max;
          *  S�tter runningComplete attributten af ProgressMonitorSetup object
          * @param  complete  Den nye runningComplete v�rdi
         public void setRunningComplete(String complete) {
              this.complete = complete;
          *  S�tter complete attributten af ProgressMonitorSetup object
          * @param  completeTotal  Den nye complete v�rdi
         public void setComplete(String completeTotal) {
              this.completeTotal = completeTotal;
          *  S�tter cancel attributten af ProgressMonitorSetup object
          * @param  cancel  Den nye cancel v�rdi
         public void setCancel(String cancel) {
              this.cancel = cancel;
          *  Returnere cancel attributten af ProgressMonitorSetup object
          * @return    cancel v�rdi
         public String getCancel() {
              return cancel;
          *  Returnere done attributten af ProgressMonitorSetup object
          * @return    done v�rdi
         public boolean isDone() {
              if (progress >= max) {
                   progressMonitor.close();
                   return true;
              } else {
                   return false;
          *  METODEN
         public void close() {
              progressMonitor.close();
          *  METODEN
         public void initProgressMonitor() {
              progressMonitor = new ProgressMonitor(null,
                   title, note,
                   min, max);
              progressMonitor.setMillisToDecideToPopup(100);
              progressMonitor.setMillisToPopup(100);
              progressMonitor.setProgress(min);
          *  S�tter progress attributten af ProgressMonitorSetup object
          * @param  i  Den nye progress v�rdi
          * @return    Beskrivelse af den Returnerede V�rdi
         public String setProgressMessage(int i) {
              progress = i;
              progressMonitor.setProgress(progress);
              note = complete + progress + " af " + max;
              progressMonitor.setNote(note);
              if (progressMonitor.isCanceled() || isDone()) {
                   Toolkit.getDefaultToolkit().beep();
                   if (progressMonitor.isCanceled()) {
                        progress = max++;
                        return cancel;
                   } else {
                        return completeTotal;
              return note;
          *  S�tter progress attributten af ProgressMonitorSetup object
          * @param  i  Den nye progress v�rdi
         public void setProgress(int i) {
              progress = i;
              progressMonitor.setProgress(progress);
              note = complete + progress + " af " + max;
              progressMonitor.setNote(note);
              if (progressMonitor.isCanceled() || isDone() ) {
                   Toolkit.getDefaultToolkit().beep();
                   if (progressMonitor.isCanceled()) {
                        progress = max++;
                   } else {
    }Sry about the comment, and the danish... But this works really nice, if you place the swingworker around the method needing progressmonitor.

Maybe you are looking for

  • PI 7.1 release

    Hi Experts, Could you please tell me, when we can get the PI7.1 in the market? What is the procedure to get the Ramp up release? Regards Sara

  • How to print a PDF to avery label 5160

    I get emails with PDF attachement of mailing labels set up to print on avery (30 labels per page) 5160 template. The print option page say letters, photos, shirts, disks...how can I get the label template to come up? I know from the last time I had t

  • Billng document creation using bdc

    hi experts, I've been using bapi for sales order and outbound delivery creation. But for billing document i'm using BDC. it's simpler. The creation of sales order and outbound delivery has no problem. The problem is upon creation of the billing docum

  • CS6 Can't Open/Create Files after a period

    I've seen several threads around for a issue the same as this (None with anything useful) and seeing as i can't really see how to explain it, i'll use Coestar's Video: http://www.youtube.com/watch?v=3Ehx9cFyw7A Which shows the exact issue i'm having,

  • Can i using photoshop element 9 on imac

    Error message 0220 is missing from your project while creating photobook, has more than 20 pages