473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to avoid non-static method?

Sorry for making another thread ( I actually solved my other one).

but this section of code I really need help on:

Expand|Select|Wrap|Line Numbers
  1.     public void shutDown()
  2.     {
  3.         out.println("close"); 
  4.         out.flush();
  5.         System.exit(0);
  6.     }
  7.     public static void main(String[] args) 
  8.     {
  9.         ClientGUI mainWindow = new ClientGUI();
  10.         mainWindow.pack();
  11.         mainWindow.addWindowListener(new WindowAdapter() 
  12.         {public void windowClosing(WindowEvent e) 
  13.             {shutDown();}
  14.         });
  15.         mainWindow.setResizable(false);
  16.         mainWindow.setVisible(true);
  17.     }
how do I get rid of the non-static method error? I searched but came up empty handed. It is really important I do those steps on shut down.
Feb 17 '08 #1
3 1578
Laharl
849 Expert 512MB
You could just put the code in the addWindowListener instead of calling shutDown(). Alternatively, you could (probably) make shutDown() static.
Feb 18 '08 #2
You could just put the code in the addWindowListener instead of calling shutDown(). Alternatively, you could (probably) make shutDown() static.
It i do that then it says "non-static variable out cannot be referenced from a static context"

in both ways that you mentioned.
Feb 18 '08 #3
BigDaddyLH
1,216 Expert 1GB
It i do that then it says "non-static variable out cannot be referenced from a static context"

in both ways that you mentioned.
You get get around that be defining a proper WindowAdapter subclass and make out a field in it.

Also, you may be interesting in shutdown hooks:

http://java.sun.com/javase/6/docs/ap...a.lang.Thread)
Feb 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: przemas_r | last post by:
Hi all! I'm writing socket app, which will transmit data in fixed size packets. I'd like to be able to pass N bytes to send (or write) function and ensure that it won't block. I was willing...
6
by: mary | last post by:
When we use string line; while (getline(in,line)) { out.write(line.c_str(),line.size()); out.put('\n'); } in.close();
14
by: lutorm | last post by:
Hi, I'm having a problem with a return statement being parsed to return a function (I think). Check here: template <typename T> class A {}; template <typename T> class maker_of_A { public:...
12
by: Steve Jorgensen | last post by:
Since reading values from calculated controls in Access 2000 and 2002 from code has proven unrliable at best, and since I like to avoid running separate queries to calculate sums of subform records...
2
by: Gilberto Carcano | last post by:
Is there a way to avoid public custom properties to persist in the ASPX code? I'have a class for columns collection in a Web Control i'm writing. This class must to implement the IStateManager...
29
by: CAH | last post by:
Hi Can you avoid that googlebot indexes PHPSESSID pages? Googlebot is indexing pages with PHPSESSID, which makes it think my page has a infinite number of pages. How can one avoid this? ...
9
by: Olaf | last post by:
Hi, here the following test code #include <iostream> using namespace std; struct Foo { Foo() { cout << " Foo()\n"; }
2
by: vizard | last post by:
Hi All, Im new to PHP. In the script I've written, i have the following line: if($coursesTaught->empId == $record- // do something } when the if condition executes, i get the foll message:...
1
by: WT | last post by:
Hello, I have a dictionary made with objects which contain a control element, the control element is added to a Page when I want to edit the dictionary content. I put this dictionary in cache...
34
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
Hi, is there a way to avoid the automatic copy constructor generation. I do not want the object to be non-copyable. I simply do not want that copying is done by the default copy constructor. But...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.