Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax and variable

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
Code:
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Demo {

     static JFrame jframe = new JFrame("Example"); 



     public static void setupJFrame() {

          jframe.setSize(400,100);

          jframe.setVisible(true);

          jframe.setLayout( new FlowLayout() );



          WindowListener l = new WindowAdapter() { // line-1

               public void windowClosing(WindowEvent e) {

                    System.exit(0);}

          };

          jframe.addWindowListener(l);

     }



     public static void main(String[] args) {

          setupJFrame();

          JButton jb = new JButton("pressure");

          jframe.getContentPane().add( jb );

          jframe.setVisible(true);

     }

}


How can i write //line-1 inside a method ? look, thats not a variable . had it been a variable x,y,z etc we could write
int x=0;
int y=3;

but thats not a variable , so how can i write this way
 
That is a fairly standard way of attaching a WindowListener (in your case an anonymous class instance) - I don't see your problem.

--------------------------------------------------
Free Database Connection Pooling Software
 
Here is a piece of code that works but Idon't know if it's realy what you asked :

Code:
public class Demo extends WindowAdapter{

     static JFrame jframe = new JFrame("Example");

     public void windowClosing(WindowEvent e) {
         System.exit(0);
     }


     public static void setupJFrame() {

          jframe.setSize(400,100);

          jframe.setVisible(true);

          jframe.setLayout( new FlowLayout() );

          jframe.addWindowListener(new Demo());

     }



     public static void main(String[] args) {

          setupJFrame();

          JButton jb = new JButton("pressure");

          jframe.getContentPane().add( jb );

          jframe.setVisible(true);

     }

}

Demo class extends WindowAdapter so you can add it as listener for your frame.

Water is not bad as long as it remains outside human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top