Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Why is my java program not running ?

here's a java program with awt taught in our college .

import java.awt.*;

import java.awt.event.*;

public class FrameDemo2 extends Frame implements ActionListener{

FrameDemo2(String s)

{

super(s);

}

Label lbl1,lbl2;

TextField txt1,txt2;

Button b1,b2;

setLayout(new GridLayout(3,2));

public void initialize()

{

lbl1 = new Label("Enter number : ");

lbl2 = new Label("Result");

txt1 = new TextField(10);

txt2 = new TextField(20);

b1=new Button("Square ");

b2=new Button("Clear");

add(lbl1);

add(txt1);

add(lbl2);

add(txt2);

add(b1);

add(b2);

b1.addActionListener(this);

b2.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==b1)

{

int no;

double d1;

no = Integer.parseInt(txt1.getText());

d1=Math.pow(no,2);

txt2.setText(""+d1);

}

if(e.getSource()==b2)

{

txt1.setText("");

txt2.setText("");

}

}

}

class Vclient

{

public static void main(String[] args)

{

FrameDemo2 fd2 = new FrameDemo2("Action");

fd2.setSize(400,450);

fd2.initialize();

fd2.setVisible(true);

}

}

i get an error when i try to set layout , using setLayout method . The error says invalid method declaration . return type required .

But if i write fd2.setLayout(new GridLayout(3,2)); then the program works .

Can anyone explain why is it happening like that ??

Update:

When i compile i get the following error -

F:\Setups\MyJava>javac -d . FrameDemo3.java

FrameDemo3.java:14: invalid method declaration; return type requi

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: illegal start of type

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: ')' expected

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: ';' expected

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: illegal start of type

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: <identifier> expected

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: ';' expected

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: illegal start of type

setLayout(new GridLayout(3,2));

^

FrameDemo3.java:14: <identifier> expected

setLayout(new GridLayout(3,2));

Update 2:

i have saved the program with the name FrameDemo3.,java

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    when you compile it what line does it say the error is on ect?

  • 1 decade ago

    try to install it again or send error code to the company to process on that.

Still have questions? Get your answers by asking now.