Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 12th, 2005, 10:50 PM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
"'.class' expected" - Says BlueJ

I'm new to java and I am trying to make a program that adds the number 9 to the end of the textbox every second. I copied the code from various places and pasted it together. I think the majority is okay. I get a "'.class' expected" error on line seventeen. I am using BlueJ and java Tiger to compile. Anyway here is the code...

Code:
import java.awt.*;
import javax.swing.*;
public class GUI {
    public static void main(String[] Args){
        JFrame frame = new JFrame("Nine");
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setBounds(265, 100, 535, 291);
        JPanel panel = new JPanel();
        JTextArea Nine = new JTextArea("999999999", 15, 47);
        Nine.setLineWrap(true);
        Nine.setWrapStyleWord(false);
        Nine.setEditable(false);
        JScrollPane ScrollNine = new JScrollPane(Nine);
        panel.add(ScrollNine);
        frame.setContentPane(panel);
        javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Nine.append(9);
            }
        });
        frame.setVisible(true);
        TimerNine.start();
    }
}


I am not sure if I need to import more things or what. Any help would be appreciated, thanks.

Last edited by sound7 : May 13th, 2005 at 10:44 AM. Reason: adding code tags

Reply With Quote
  #2  
Old May 13th, 2005, 04:49 AM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,130 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 6 m 48 sec
Reputation Power: 1736
to use ActionListener you have to use
Code:
import java.awt.event.*

when you append 9, it should be as a string
Code:
Nine.append("9");

Reply With Quote
  #3  
Old May 13th, 2005, 07:15 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
When you post code, please post it between [code] and [/code] tags (you can use the "code" button on the message posting screen). It makes your code much easier to read and prevents accidental markup from the forum software.

Also, please follow the standard Code Conventions for the Java™ Programming Language.
__________________
Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

Reply With Quote
  #4  
Old May 13th, 2005, 10:43 AM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
Here is it in code tags now, I added the things, but I still get the same error. "'.class' expected" I get it on this line.

Code:
        javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {


Here is the code surrounding it.

Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Gui {
    public static void main(String[] Args){
        JFrame frame = new JFrame("Nine");
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setBounds(265, 100, 535, 291);
        JPanel panel = new JPanel();
        
        JTextArea Nine = new JTextArea("999999999", 15, 47);
        Nine.setLineWrap(true);
        Nine.setWrapStyleWord(false);
        Nine.setEditable(false);
        
        JScrollPane ScrollNine = new JScrollPane(Nine);
        panel.add(ScrollNine);
        frame.setContentPane(panel);
        
        javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Nine.append("9");
            }
        });
        
        frame.setVisible(true);
        
        TimerNine.start();
    }
}

Reply With Quote
  #5  
Old May 13th, 2005, 10:46 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Don't declare the int.
PHP Code:
 javax.swing.Timer TimerNine = new javax.swing.Timer(1000, new ActionListener() {
//... 

Reply With Quote
  #6  
Old May 13th, 2005, 11:02 AM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
Compiling is taking a really long time. Does the timer need its own class? If the code is all right then is there an easier way to make a timer?

Reply With Quote
  #7  
Old May 13th, 2005, 11:05 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Compiling shouldn't take a long time simply because of the Timer class. Check your system and IDE settings.

Reply With Quote
  #8  
Old May 13th, 2005, 11:18 AM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
I restarted the IDE and it worked. But when It compiled it found an error with

Code:
                Nine.append("9");


The message was really long so I took a screenshot of the error box. It's attached.
Attached Images
File Type: gif variableNine.gif (2.7 KB, 187 views)

Reply With Quote
  #9  
Old May 13th, 2005, 11:29 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Don't panic when you get an error message. It's trying to tell you something. Listen to it.

You can't access non-final local variables from anonymous inner classes. The error message you posted tells you exactly what's wrong and what you need to do to correct it.

Reply With Quote
  #10  
Old May 13th, 2005, 11:31 AM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
How do I declare it final?

Reply With Quote
  #11  
Old May 13th, 2005, 11:36 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Quote:
How do I declare it final?
With the "final" keyword.

Example:
PHP Code:
final Object somethingOrOther = new Object(); 


The Java™ Tutorial - A practical guide for programmers

Reply With Quote
  #12  
Old May 13th, 2005, 11:42 AM
sound7 sound7 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 41 sound7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
Send a message via MSN to sound7
Sorry to bother you again. Anyways now it says "cannot find symbol - method append(java.lang.String)" What does that mean?

Code:
                Nine.append("9");

Reply With Quote
  #13  
Old May 13th, 2005, 11:45 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
It means the compiler does not recognize the method you have written as a valid method. You've written something incorrectly.

Reply With Quote
  #14  
Old May 13th, 2005, 11:47 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 10,135 Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level)Yawmark User rank is General 61st Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
The following code is a direct modification of your code, changing only what was necessary to get it to a compileable state:
PHP Code:
 import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class 
Gui {
    public static 
void main(String[] Args){
        
JFrame frame = new JFrame("Nine");
        
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        
frame.setResizable(false);
        
frame.setBounds(265100535291);
        
JPanel panel = new JPanel();
        
        final 
JTextArea Nine = new JTextArea("999999999"1547);
        
Nine.setLineWrap(true);
        
Nine.setWrapStyleWord(false);
        
Nine.setEditable(false);
        
        
JScrollPane ScrollNine = new JScrollPane(Nine);
        
panel.add(ScrollNine);
        
frame.setContentPane(panel);
        
        
javax.swing.Timer TimerNine = new javax.swing.Timer(1000, new ActionListener() {
            public 
void actionPerformed(ActionEvent e) {
                
Nine.append("9");
            }
        });
        
        
frame.setVisible(true);
        
        
TimerNine.start();
    }


Reply With Quote
  #15  
Old January 17th, 2006, 10:10 AM
kevinoc kevinoc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 22 kevinoc User rank is Sergeant (500 - 2000 Reputation Level)kevinoc User rank is Sergeant (500 - 2000 Reputation Level)kevinoc User rank is Sergeant (500 - 2000 Reputation Level)kevinoc User rank is Sergeant (500 - 2000 Reputation Level)kevinoc User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 13 m 20 sec
Reputation Power: 0
Hi everyone, I'm having a similar problem.

Code:
/**
 * Time class
 * 
 * <INSERT DESCRIPTION HERE>
 * 
 * @author: Kevin O'Connor
 * @version: 1
 */
public class Time
{
	// Variables (1.2)
	private int hours;
	private int minutes;

	// Constructors (1.3)	 
	public Time()
	{
		hours = 0;
		minutes = 0;
	}
	
	// Method: setHour (1.4)
	
	private void setHour(int timeHour)
	{
	    if((timeHour <= 23) && (timeHour >= 0)){
	        hours = hours + timeHour;
	    }
	}
	
	// Method: setMinute (1.5)
	private void setMinute(int timeMinute)
	{
	    if((timeMinute <= 59) && (timeMinute >= 0)){
	        minutes = minutes + timeMinute;
	    }
	}
	
	// Method: setTime (1.6)
	public void setTime(int timeHour, int timeMinute)
	{
	    setHour(int timeHour);
            setMinute(int timeMinute);
	}
}	


The line highlighted in bold is where I'm getting the "'.class' expected" message. I'm trying to make a method call so I don't have to repeat the code. I would assume I have the same problem with the line after it.

Any help is appreciated.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > "'.class' expected" - Says BlueJ

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap