Help

I get this when I try to compile

Exception in thread "main" java.lang.NoClassDefFoundError: checknum/java

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

publicclass checknumextends Appletimplements ActionListener

{

Button check;

TextField numcheck;

function checknum(number)

{

if ((number%2)==0)

{

return number +" == Even";

}

else

{

return number +" == Odd";

}

}

publicvoid init()

{

setBackground(Color.white);

check=new Button("Check");

numcheck =new TextField("5",100);

check.setBounds(20,20,100,30);

numcheck.setBounds(50,50,100,30);

add(check);

add(numcheck);

check.addActionListener(this);

}

publicvoid stop()

{

}

publicvoid actionPerformed(ActionEvent e)

{

Object source = e.getSource();

if (source == check)

{

numcheck = checknum(numcheck);

}

}

}

[2252 byte] By [Jay.Kaya] at [2007-11-27 11:00:15]
# 1

Your current code is wholly wrong as a Java program code.

Do these two tutorials first:

http://java.sun.com/docs/books/tutorial/getStarted/index.html

http://java.sun.com/docs/books/tutorial/java/index.html

hiwaa at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...
# 2

are you trying to get the odd number and even number?

schumachera at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...
# 3

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class checknum extends Applet implements ActionListener

{

Button check;

TextField numcheck;

function checknum(number) // what is this? is this a method.. this is totally wrong

{// you are returning a string, what type is your parameter?

if ((number%2)==0)

{

return number + " == Even";

}

else

{

return number + " == Odd";

}

}

public void actionPerformed(ActionEvent e)

{

Object source = e.getSource();

if (source == check)

{

numcheck = checknum(numcheck); // numcheck is a textfield use setText()

}

}

}

Message was edited by:

Yannix

Yannixa at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...
# 4

@OP: have fun!

your fully functional code:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class sample1 extends Applet implements ActionListener {

Button check;

TextField numcheck;

private void checknum(int number) {

if ((number%2)==0) {

numcheck.setText(numcheck.getText() + " = even");

} else {

numcheck.setText(numcheck.getText() + " = odd");

}

}

public void init() {

setLayout(null);

setBackground(Color.white);

check= new Button("Check");

numcheck = new TextField("5");

check.setBounds(10,10,100,30);

numcheck.setBounds(10,50,100,30);

add(check);

add(numcheck);

check.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {

Object source = e.getSource();

if (source == check) {

checknum(Integer.parseInt(numcheck.getText()));

}

}

}

Message was edited by:

Yannix

Yannixa at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...
# 5

Exception in thread "main" java.lang.NoClassDefFoundError: checknum/java

Error messages are there for a reason. If you had read what it said you would know what was wrong. If you can't figure it out perhaps you should fdrop the course.

floundera at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...
# 6

Also, use a more informative title in future. We assume you want help, that is why you posted here.

floundera at 2007-7-29 12:28:27 > top of Java-index,Java Essentials,New To Java...