aspose file tools*
The moose likes Beginning Java and the fly likes error in frame based application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error in frame based application" Watch "error in frame based application" New topic
Author

error in frame based application

chandan kuchipudi
Greenhorn

Joined: Jun 27, 2012
Posts: 12
hi all .....i've got a problem whlie executing this frame based application ....please resolve it ...

//CheckDemo.java

import java.awt.*;
import java.awt.event.*;

class CheckBox extends Frame
{
Checkbox cb1,cb2,cb3;
Label l1;

Check()

{
setTitle("CHECKBOX DEMO");
setSize(300,300);
FlowLayout fl=new FlowLayout();
setLayout(fl);
// create the components
cb1=new Checkbox("java");
cb2=new Checkbox(".NET");
cb3=new Checkbox("CLOUD COMPUTING");
l1=new Label("YOUR SELECTED COURSE");


//ADD COMPONENTS TO CONTAINER

add(cb1);add(cb2);add(cb3);add(l1);

//registration process

Sathya so=new Sathya();
cb1.addItemListener(so);
cb2.addItemListener(so);
cb3.addItemListener(so);

setVisible (true);
}//check()

class Sathya implements ItemListener
{
public void itemStateChanged(ItemEvent ie)
{
if (ie.getSource()==cb1)

{
if(cb1.getState())
{
l1.setText("your selected course:"+cb1.getLabel());
}
if(cb2.getState())
{
l1.setText("your selected course:"+cb2.getLabel());
}
if(cb3.getState())
{
l1.setText("your selected course:"+cb3.getLabel());
}
else
{
l1.setText("your selected course=none");
}//else
}//isc

}//sathya
}//check
class CheckDemo1
{
public static void main (String [] args)
{
Check co= new Check();
}
}
}


it is showing that

java 11:error invalid method declaration; return type required Check()


please look into that once.


E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Look at where the error is being reported.
If you were trying to create a constructor for the CheckBox class then the constructor must be named the same as the class name. You have the class name as CheckBox but the constructor is named Check.

P.S Use code tags when posting code.
chandan kuchipudi
Greenhorn

Joined: Jun 27, 2012
Posts: 12
thankyou ...i've changed the constructor ...

but it is showing the error after this


line no 67: error: illegal static declaration in inner class Check CheckDemo1.java

public static void main (String []args)

modifier 'static' is only allowed in constant variable declarations
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
The error says: static methods can only be declared in a static or top level type.

So either make the class with the main method static or move the main method into a top level class.
You should try to read and understand what the error messages are telling you. They usually contain vital hints.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Moved from Applets


luck, db
There are no new questions, but there may be new answers.
Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 187
chandan kc wrote:line no 67: error: illegal static declaration in inner class Check CheckDemo1.java
public static void main (String []args)
modifier 'static' is only allowed in constant variable declarations


Because inner class do not have static declaration, only Static nested class can have.

And Please use the UseCodeTags.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: error in frame based application