Results 1 to 3 of 3
- 01-29-2013, 12:18 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
Can't use variables that are declared??
I have the following beginning of a program that I an trying to start, but stupid NetBeans won't let me use the variables I have declared for some reason. Every time I try to use one of my declared variables, it spits an error at me, and I do not see what in the world is wrong now!!
Java Code:package pkginterface; import java.awt.event.*; import java.awt.*; import java.util.*; import java.io.*; import javax.swing.*; public class Interface implements ActionListener{ JFrame frame = new JFrame("Interface program"); JTextField txt1 = new JTextField(24); JTextArea txt2 = new JTextArea(24, 24); JButton b1, b2, b3; //These are all properly declared, but cannot be used without Netbeans putting red lines underneath every line in the code!! public static void main(String[] args) { // TODO code application logic here } public void actionPerformed(ActionEvent ae) { throw new UnsupportedOperationException("Not supported yet."); } }
Java Code:package pkginterface; import java.awt.event.*; import java.awt.*; import java.util.*; import java.io.*; import javax.swing.*; public class Interface implements ActionListener{ JFrame frame = new JFrame("Interface program"); JTextField txt1 = new JTextField(24); JTextArea txt2 = new JTextArea(24, 24); JButton b1, b2, b3; b1.add // NOPE NOT ALLOWED.... public static void main(String[] args) { // TODO code application logic here } public void actionPerformed(ActionEvent ae) { throw new UnsupportedOperationException("Not supported yet."); } }
- 01-29-2013, 01:18 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
Re: Can't use variables that are declared??
You can't specify statements or expressions outside a method body.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-29-2013, 10:17 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
Similar Threads
-
How do I control whether a class is declared serializable or not?
By DrMadolite in forum New To JavaReplies: 3Last Post: 07-30-2012, 09:34 AM -
Class is public, should be declared in a file
By goldhouse in forum New To JavaReplies: 7Last Post: 05-10-2012, 10:17 AM -
Only want to read variables declared within certain constructors
By kyameron in forum New To JavaReplies: 13Last Post: 02-02-2011, 03:36 AM -
LinkedList declared as an abstract superclass
By box2box in forum New To JavaReplies: 2Last Post: 04-21-2010, 11:32 PM -
Implicit object in jsp declared where?
By mahendra.athneria in forum JavaServer Pages (JSP) and JSTLReplies: 7Last Post: 08-11-2009, 03:23 PM
Bookmarks