System.exit(0) exits the whole system it also closes the main frame as well. So i decided to set the frame i want to be closed to be not visible, by using the setVisible method. The problem is that it wont compile and it is saying non-static method setVisible(boolean) cannot be referenced from a static context. How do I fix the problem.
public void actionPerformed(ActionEvent event)
if(event.getSource() == close)
but InputForm is a class on disk, not an object in memory. how can i tell? well, it starts with a capital letter. imagine that you made your input form like this:
InputForm ipFrm = new InputForm(...)...
then you would close it like this:
because you have written the name of the class (the file on disk that determines how an object will be built) rather than the object in computer memory itself, java is going to check for a special case called a static reference. there are SOME times in java that you can call a method without actually having an object in memory for it.. when you start a program for the first time, there are no objects in memory. that is why your main() HAS to be static; so it can be called without there being an object first. if it werent static, then it would be chicken-and-egg
incidentally, i advice newcomers to java, to NEVER, EVER, EVER use statics (apart from in conjuction with main() ) - if you start relying on them, or sticking them in your code willy-nilly, you wont learn Object Oriented programming, and you will never really make a great programmer. statics have their place, but in university second or third year
by the way;
this is why we should always follow convention when naming something. an experience programmer like me comes along, and assumes you ahve obeyed convention of "class names start with a capital letter" (e.g. heres some you will have used: String, Integer, JOptionPane)
it would be wrong to write: String MyString1 = "hello";
because a programmer like me would see you post a message about "..blah.. MyString1.. problem..." ans say "well, your MyString1 class file is.. blah".. but MyString1 isnt a class, its a String variable..
understanding the difference between classes and objects, (or static and dynamic) is one of the key things you will learn about java
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center