The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
"'.class' expected" - Says BlueJ
Discuss "'.class' expected" - Says BlueJ in the Java Help forum on Dev Shed. "'.class' expected" - Says BlueJ Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 12th, 2005, 10:50 PM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
|
"'.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
|

May 13th, 2005, 04:49 AM
|
 |
Lord of the Dance
|
|
|
|
to use ActionListener you have to use
Code:
import java.awt.event.*
when you append 9, it should be as a string
|

May 13th, 2005, 07:15 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
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)));}}
|

May 13th, 2005, 10:43 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
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();
}
}
|

May 13th, 2005, 10:46 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
Don't declare the int.
PHP Code:
javax.swing.Timer TimerNine = new javax.swing.Timer(1000, new ActionListener() {
//...
|

May 13th, 2005, 11:02 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
|
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?
|

May 13th, 2005, 11:05 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
|
Compiling shouldn't take a long time simply because of the Timer class. Check your system and IDE settings.
|

May 13th, 2005, 11:18 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
I restarted the IDE and it worked. But when It compiled it found an error with
The message was really long so I took a screenshot of the error box. It's attached.
|

May 13th, 2005, 11:29 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
|
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.
|

May 13th, 2005, 11:31 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
|
How do I declare it final?
|

May 13th, 2005, 11:36 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
|

May 13th, 2005, 11:42 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 41
Time spent in forums: 6 h 58 m 2 sec
Reputation Power: 9
|
|
Sorry to bother you again. Anyways now it says "cannot find symbol - method append(java.lang.String)" What does that mean?
|

May 13th, 2005, 11:45 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
|
It means the compiler does not recognize the method you have written as a valid method. You've written something incorrectly.
|

May 13th, 2005, 11:47 AM
|
 |
Feelin' Groovy
|
|
Join Date: Aug 2001
Location: WDSMIA
|
|
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(265, 100, 535, 291);
JPanel panel = new JPanel();
final 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(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Nine.append("9");
}
});
frame.setVisible(true);
TimerNine.start();
}
}
|

January 17th, 2006, 10:10 AM
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|