I dont know whts wrong with the code...
its in java..the error msg is shown while compilation i.e.
class, interface , or enum exception..
plzz can anyone help me with this..

import java.io.*;
import java.security.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;



public final class DiffieHellman extends java.applet.Applet implements ActionListener
{
private Button b0,b1;
private TextArea pub_prime=new TextArea();
private TextArea pub_no=new TextArea();
private TextArea pri_a=new TextArea();
private TextArea pri_b=new TextArea();
private TextField pub_x=new TextField();
private TextField pub_y=new TextField();
private Label l,la1,la2,la3,la4,la5,la6;

}
public void init()
{
this.setLayout(new BorderLayout(10,10));
Panel p=new Panel();
l=new Label("enter p");
p.add(l);
p.add(pub_prime);
la1=new Label("enter g");
p.add(la1);
p.add(pub_no);
add(p,"North");
Panel p1=new Panel();
la2=new Label("enter a");
p1.add(la2);
p1.add(pri_a);
la3=new Label("enter b");
p1.add(la3);
p1.add(pri_b);
add(p1,"Center");
Panel p2=new Panel();
la4=new Label("X");
p2.add(la4);
p2.add(pub_x);
la5=new Label("Y");
p2.add(la5);
p2.add(pub_y);
add(p2,"South")
Panel p3=new Panel();
b0=new Button("OK");
b0.addActionListener(this);
p3.add(b0);
b1=new Button("Clear Text");
b1.addActionListener(this);
p3.add(b1);
add(p3,"East");
}
public void actionPerformed(ActionEvent evt)
{
String arg=evt.getActionCommand();
if(arg.equals("OK"))
{
comp_puba();
}
else if(arg.equals("Clear Text"))
{
pub_prime.setText("");
pub_no.setText("");
pri_a.setText("");
pri_b.setText("");
pub_x.setText("");
pub_y.setText("");
}
}

private void comp_puba()
{

 String m=pub_prime.getText();
String m1=pub_no.getText();
String m2=pri_a.getText();
int P=Integer.parseInt(m);
int G=Integer.parseInt(m1);
int a=Integer.parseInt(m2);
int c;
int E1=1;
for(int i=1;i<=a;i++)
{
E1=E1*G;
}
c=E1 % P;
String c1=String.valueOf(c);
pub_x.setText(""+c1);
}
public void paint(Graphics g)
{
setBackground(Color.black);
g.setColor(Color.blue);
g.drawRect(0,0,this.getSize().width-1, this.getSize().height-1) ; 

}
}

Recommended Answers

All 13 Replies

Can you please paste the exact error you are getting , that will help us to help you better.

class,interface, or enum expected
public void init()

Check that your {}s are correctly positioned.
For example where is the ending } for the class?
All your code should be in a class definition. Is it?

Why bring that up? Where is the OP's class being extended?

if u are talking to me then

public final class DiffieHellman extends java.applet.Applet implements

What is the problem with the OP making his class final?

I already have given a link

Yes, but what does that have to do with the current class the OP is coding?
As I said, the OP is not trying to extend the class he is defining as final.

then y extend keyword is used....

What is the point you are trying to make?
The class definition statement the OP is using is legal. It should not cause the OP any problem UNLESS he tries to extend his DiffieHellman class. That won't be allowed because it is final.

Got my Mistake Sorry.................

class,interface, or enum expected
public void init()

This is because before start of this line your class has completed you see you have closed the curly braces of class. since a method can only be inside class, enum or interface java is throwing compilation error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.