PDA

View Full Version : jewl help



itgetsharder10
05-05-2008, 02:23 AM
m trying to create an applet using jewl. i keep getting the error message: cannot find symbol-mothod setupGUI(jewl.frame). a frame is a container but i dont know how to solve this as im obviously doing something wrong. any help would be appreciated, thank you.


import jewl.*;


/**
* A simple calculator. It illustrates the use of textfields, fonts
* and buttons.
*/
public class Calculator extends Applet {
Frame frame;
Font font;
IntegerField value;

public void setupGUI(Container c){
Font font = new Font("Monospaced",Font.BOLD,14);
IntegerField value = new IntegerField (getPanel(), 10, 10, -20, 25);
value.setFont(font);
value.setAlignment(TextControl.RIGHT);
//
// Create the buttons (using a loop to avoid repetition)
//
String buttons = "789+456-123*C0=/";
for (int i = 0; i < buttons.length(); i++) {
int x = (i % 4) * 60 + 10;
int y = (i / 4) * 50 + 45;
Button b = new Button (getPanel(), x, y, 50, 40,
"" + buttons.charAt(i),
buttons.charAt(i));
b.setFont(font);
}
}


public static void main (String args[]) {
Frame frame = new Frame (260, 275, "JEWL Calculator", 'Q');
Applet d = new Calculator();
d.setupGUI(frame);
while(frame.isValid()) {
char c = Window.nextCommand();
d.handleCommand(c);
}
}

public void createGUI() {
setupGUI(getPanel());
}
//
// Create the frame and value field
//

//
// Variables to record the state of the calculation
//
public void handleCommand(char command){
char operator = '=';
long left = 0;
long right = 0;
//
// The event loop
//

while (frame.isValid()) {

//
// Digit key: update displayed value
//
if (command >= '0' && command <= '9') {
right = right * 10 + command - '0';
value.setLong(right);
}
//
// Clear key: reset state of calculation and displayed value
//
else if (command == 'C') {
left = right = 0;
operator = '=';
value.setLong(0);
}
//
// Operator key: apply previous operator to left and right values.
// The left value and previous operator will have been set the last
// time an operator key was pressed. The result of the previous
// operation is stored in left, and the operator character is
// saved for next time.
//
else if (command != 'Q') {
right = value.getLong();
left = (operator == '+' ? left + right :
operator == '-' ? left - right :
operator == '*' ? left * right :
operator == '/' ? left / right : right);
operator = command;
right = 0;
value.setLong(left);
}
}
}
}

amitthechosen1
05-08-2008, 05:55 PM
hi
The error is due to the declaration:-


Frame frame = new Frame (260, 275, "JEWL Calculator", 'Q');
Applet d = new Calculator();
d.setupGUI(frame);

the object "frame" here does not belong to java.awt package but to "jewl" package.
d.setupGUI(frame) :- This is being looked up in the class jewl.Applet, but the only methods present in jewl.Applet are :-
private jewl.AppletPanel panel;
public jewl Applet;
public final AppletPanel getPanel();
public abstract void createGUI();
public abstract void handleCommand(char arg);
pubic void init();

Hence, the method that you are trying to call (d.setupGUI) is not at all there, and your code is trying to use it.
Also

a frame is a container
But both the container and frame have been overridden in the jewl's jar file. You may check the contents of the jar file to verify the same.