Handeling EventListeners given from other classes...

Hello again,
I got the folloing Problem:
I've got a Frame-Class, with calls a Class from jPanel, this Panel has a button.
My Problem is this, Is there a way, to handle the button-event from the Parent-Frame?
Means this:
MyPanel mp = new MyPanel();
this.add(mp);
// Here to wait for the button event, and do something.
If anybody has a solution, thx alot.

don't expose the hour variable at all.
have a method eg addToHourBy( int hrs )
Probably a simple questions, but how can I access a
variable from another class. My exact situation is as
follows.
A class called WorldCalender has a variable which is
defined: public int hour; (the value is given to it
elsewhere).
I want to access this variable and increase it by one
in a subroutine in the class Hour. In this class I
have put: WorldCalender.hour++; but it doesn't seem to
work. How should I do it?

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

  • 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.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

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

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

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

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

  • Method not accessible from other classes

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

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

  • Accessing public variables from other classes

    Probably a simple questions, but how can I access a variable from another class. My exact situation is as follows.
    A class called WorldCalender has a variable which is defined: public int hour; (the value is given to it elsewhere).
    I want to access this variable and increase it by one in a subroutine in the class Hour. In this class I have put: WorldCalender.hour++; but it doesn't seem to work. How should I do it?

    don't expose the hour variable at all.
    have a method eg addToHourBy( int hrs )
    Probably a simple questions, but how can I access a
    variable from another class. My exact situation is as
    follows.
    A class called WorldCalender has a variable which is
    defined: public int hour; (the value is given to it
    elsewhere).
    I want to access this variable and increase it by one
    in a subroutine in the class Hour. In this class I
    have put: WorldCalender.hour++; but it doesn't seem to
    work. How should I do it?

  • Flash Vars is not working when we accessing from other class files

    Hi all, I'm currently developing a flex application where i
    need to pass the data from the flash vars to the other class files
    instead of the main actionscript class file.
    Does any body know how i should go about doing that?? you can
    see this below code : please help me out if u know how to solve
    testnew2.as file
    package {
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew2 extends Sprite {
    public var
    xmlfile:String=String(root.loaderInfo.parameters.lists);
    public function testnew ():void{
    package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew extends testnew2 {
    public function testnew () {
    var myText:TextField = new TextField();
    // this assumes that you are going to pass in an id variable
    // on the end of the myFile.swf?id=12345 or
    // use FlashVars in the HTML parameter list for instance
    // 'FlashVars', 'id=123456', 'width', '1024',
    myText.text = new testnew2().xmlfile;
    addChild(myText);
    but if we access in same file it is working fine:
    package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew extends Sprite {
    public function testnew () {
    var myText:TextField = new TextField();
    myText.text = String(root.loaderInfo.parameters.lists);
    addChild(myText);

    Pass the data into the main app, then from there either pass
    it into the sub-components or use
    Application.application.parameters, or bind to the values.
    Tracy

  • 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

  • Accessing string from other classes

    Sorry if this seems simple to you, but i'm having problems accessing four string that are declared and used in my public class from another class.
    I've tried declaring the strings public but it still says 'cannot resolve symbol' when i try to compile.
    Help much appreciated.
    fightspam

    Yep, heres my code(sorry if it's a bit untidy):
    //Zimmerman M3 email client.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    class where extends JFrame implements ActionListener
         private JLabel path;
         private JTextField pathText;
         private String pathFile;
         private JButton save;
         File outputFile = new File(pathFile);
         public where()
              super("Save Email");     
              Container f=getContentPane();
                   f.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              f.setBackground(Color.lightGray);
              path = new JLabel("Path: ");
              f.add(path);
              pathText = new JTextField(20);
              f.add(pathText);
              save = new JButton("Save");
              f.add(save);
              this.setSize(300, 100);
         public void actionPerformed(ActionEvent q)
              pathFile = pathText.getText();
              try
                   FileWriter out = new FileWriter(outputFile);
                   out.write(zimmernorm.toFile);
                   out.write(zimmernorm.fromFile);
                   out.write(zimmernorm.subjectFile);
                   out.write(zimmernorm.bodyFile);
                   out.close();
              catch(IOException err)
                   System.exit(0);
    class about extends JFrame
         private JLabel title;
         public about()
              super("About Zimmerman M3");
              Container d=getContentPane();
                   d.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              d.setBackground(Color.lightGray);
              title = new JLabel("Zimmerman M3 by Louis Goddard, 2003");
              d.add(title);
              this.setSize(246, 62);
    class newmail extends JFrame implements ActionListener
         public static String toFile, fromFile, subjectFile, bodyFile;
         public JTextField To, From, Subject;
         private String toBuffer, fromBuffer, subjectBuffer, bodyBuffer;
         private JButton send, clear;
         private JTextArea Body;
         private JLabel toLabel, fromLabel, subjectLabel;
         private JMenuBar mb;
         private JMenu File, Edit;
         private JMenuItem New, Sender, Copy, Paste, About;
         public newmail()
                    super("New Email");
              Container c=getContentPane();
                   c.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              c.setBackground(Color.lightGray);
              //<MENU STUFF!!!>     
                   mb = new JMenuBar();
                   File = new JMenu("File");
                   Edit = new JMenu("Edit");
                   New = new JMenuItem("New");
                   Sender = new JMenuItem("Save");
                   Copy = new JMenuItem("Copy");
                   Paste = new JMenuItem("Paste");
                   File.add(New);
                   New.addActionListener(this);
                   New.setActionCommand("1");
                   File.add(Sender);
                   Sender.addActionListener(this);
                   Sender.setActionCommand("2");
                   Edit.add(Copy);
                   Copy.addActionListener(this);
                   Copy.setActionCommand("3");
                   Edit.add(Paste);
                   Paste.addActionListener(this);
                   Paste.setActionCommand("4");
                   mb.add(File);
                   mb.add(Edit);
                   setJMenuBar(mb);
              //</MENU STUFF!!!>     
              toLabel = new JLabel("To:          ");
              c.add(toLabel);
              To = new JTextField(35);
              c.add(To);
              fromLabel = new JLabel("From:     ");
              c.add(fromLabel);
              From = new JTextField(35);
              c.add(From);
              subjectLabel = new JLabel("Subject:");
              c.add(subjectLabel);
              Subject = new JTextField(35);
              c.add(Subject);
              Body = new JTextArea(12,40);
              c.add(Body);
              send = new JButton("Send");
                    c.add(send);
              clear = new JButton("Clear");
                    c.add(clear);
              clear.addActionListener(this);
              clear.setActionCommand("6");
              this.setSize(459, 364);
              public static void main(String []args)
                   JFrame.setDefaultLookAndFeelDecorated(true);
                   new newmail().show();
              public void actionPerformed(ActionEvent e)
                   String s = e.getActionCommand();
                   if (s == ("1"))
                   new newmail().show();
                   else if (s == ("2"))
                   new where().show();
                   toFile = To.getText();
                   fromFile = From.getText();
                   subjectFile = Subject.getText();
                   bodyFile = Body.getText();
                   else if (s == ("3"))
                   bodyBuffer = Body.getSelectedText();
                   toBuffer = To.getSelectedText();
                   fromBuffer = From.getSelectedText();
                   subjectBuffer = Subject.getSelectedText();
                   else if (s == ("4"))
                   Body.setText(bodyBuffer);
                   To.setText(toBuffer);
                   From.setText(fromBuffer);
                   Subject.setText(subjectBuffer);
                   else if (s == ("5"))
                   new about().show();
                   else if (s == ("6"))
                   To.setText("");
                   From.setText("");
                   Subject.setText("");
                   Body.setText("");
    public class zimmernorm extends JFrame implements ActionListener
         public String toFile, fromFile, subjectFile, bodyFile;
         private String toBuffer, fromBuffer, subjectBuffer, bodyBuffer;
         private JMenuBar mb;
         private JMenu File, Help, View;
         private JMenuItem New, About, Inboxmenu, Outboxmenu, Savedmenu;
         public zimmernorm()
                    super("Zimmerman M3");
              Container c=getContentPane();
                   c.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              c.setBackground(Color.lightGray);
              //<MENU STUFF!!!>     
                   mb = new JMenuBar();
                   File = new JMenu("File");
                   View = new JMenu("View");
                   Help = new JMenu("Help");
                   New = new JMenuItem("New");
                   About = new JMenuItem("About");
                   Inboxmenu = new JMenuItem("Inbox");
                   Outboxmenu = new JMenuItem("Outbox");
                   Savedmenu = new JMenuItem("Saved");
                   File.add(New);
                   New.addActionListener(this);
                   New.setActionCommand("1");
                   Help.add(About);
                   About.addActionListener(this);
                   About.setActionCommand("5");
                   View.add(Inboxmenu);
                   Inboxmenu.addActionListener(this);
                   Inboxmenu.setActionCommand("7");
                   View.add(Outboxmenu);
                   Outboxmenu.addActionListener(this);
                   Outboxmenu.setActionCommand("8");
                   View.add(Savedmenu);
                   Savedmenu.addActionListener(this);
                   Savedmenu.setActionCommand("9");
                   mb.add(File);
                   mb.add(Help);
                   mb.add(View);
                   setJMenuBar(mb);
              //</MENU STUFF!!!>     
              this.setSize(1024, 768);
                    this.setDefaultCloseOperation( EXIT_ON_CLOSE );
              public static void main(String []args)
                   JFrame.setDefaultLookAndFeelDecorated(true);
                   new zimmernorm().show();
              public void actionPerformed(ActionEvent e)
                   String s = e.getActionCommand();
                   if (s == ("1"))
                   new newmail().show();
                   else if (s == ("5"))
                   new about().show();

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

  • 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

  • [Jdev11gR1]: Insert taskflow run as dialog and window (X) Close button

    Hi i have taskflow to insert some data into database and i have (commit and rollback) buttons it is run as external dialog using (dialog:nav) when i press commit and rollback every thing good but if i press X button to close dialog , i find row added

  • Tolerances not copied ECC PO

    Dear Experts, We have noticed a problem with tolerances not being replicated to ECC.  Upon creation of a PO(with reference to a SHC with a contract) in SRM, the over and under delivery tolerances set in the contract are copied in the SRM PO.  Once th

  • Issue with BLOB support

    All, I'm trying to use the APEX_UTIL.GET_BLOB_FILE_SRC function in a report. I'm calling the function in a report as the src attribute for an img element as follows: APEX_UTIL.GET_BLOB_FILE_SRC('P41_IMAGE_LOCATION', id). P41_IMAGE_LOCATION is configu

  • Marketing call lists

    Hi all, I have a BIG problem with our call list management process. We are configuring the marketing scenario in our CRM 4.0 system in order to generate several calls from a given target group. Our problem is based on the agent distribution (of these

  • Mail Messages Body Do Not Print...Any Ideas?

    When printing an email, the header prints, but the body often does not print, more often when there is an attachment. IF I close the email, and reopen it, then print, it will often print without issue. Any ideas or workarounds that do not require me