Java applet problem

Questions about programming languages and debugging
Post Reply
User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Java applet problem

Post by bad_brain »

Damn, am I stupid? (nah, this isn´t the question, so don´t answer it.. :lol: )

The code isn´t complete yet, but it should run:

Code: Select all

import java.awt.*;
import java.awt.event.*;
abstract class Rate_GUIapp extends Frame
implements WindowListener, ActionListener {
public static void main(String args[]) {}
public boolean handleEvent (Event e) {
if (e.target == buttonVersuch && e.id == Event.ACTION_EVENT) {
versuchClicked();
}
if (e.target == buttonNeu && e.id == Event.ACTION_EVENT) {
neuClicked();
}
if (e.target == buttonInfo && e.id == Event.ACTION_EVENT) {
infoClicked();
}return false;
}
public void windowClosing (WindowEvent e) {
dispose();
System.exit(0);
}
public void windowClosed (WindowEvent e) {}
public void windowOpened (WindowEvent e) {}
public void windowActivated (WindowEvent e) {}
public void windowDeactivated (WindowEvent e) {}
public void windowIconified (WindowEvent e) {}
public void windowDeiconified (WindowEvent e) {}
public void actionPerformed (ActionEvent e) {
if (e.getSource()==buttonNeu) {
neuClicked();
}
if (e.getSource()==buttonInfo) {
infoClicked();
}
if (e.getSource()==buttonVersuch) {
versuchClicked();
}
}
private void neuClicked() {
textareaInfo.append("\"Neues Spiel\" geklickt\n");
}
private void versuchClicked() {
textareaInfo.append("\"Versuch\" geklickt\n");
}
private void infoClicked() {
textareaInfo.append("\"Info\" geklickt\n");
}
Label labelSuche1, labelSuche2, labelSuche3;
Label labelText1, labelText2;
TextField textfieldVersuch1, textfieldVersuch2, textfieldVersuch3;
Button buttonInfo, buttonNeu, buttonVersuch;
Font fntFett, fntHead, fntAusgabe;
TextArea textareaInfo; 
public Rate_GUIapp() {
setLayout(null);
labelText1 = new Label ("Raten Sie die 3 Ziffern");
labelText2 = new Label ("Lösungen");
labelSuche1 = new Label ("X");
labelSuche2 = new Label ("X");
labelSuche3 = new Label ("X");
textfieldVersuch1 = new TextField("");
textfieldVersuch2 = new TextField("");
textfieldVersuch3 = new TextField("");
fntFett = new Font("SansSerif",1,14);
fntHead = new Font("SansSerif",1,20);
fntAusgabe = new Font("monospaced",0,12);
buttonInfo = new Button("Info");
buttonNeu = new Button("Neues Spiel");
buttonVersuch = new Button("Versuchen");
textareaInfo = new TextArea();
labelText1.setBounds(20,25,350,25);
labelText2.setBounds(20,70,120,25);
labelSuche1.setBounds(175,70,25,25);
labelSuche2.setBounds(255,70,25,25);
labelSuche3.setBounds(335,70,25,25);
textfieldVersuch1.setBounds(170,110,25,25);
textfieldVersuch2.setBounds(250,110,25,25);
textfieldVersuch3.setBounds(330,110,25,25);
buttonInfo.setBounds(20,160,80,25);
buttonNeu.setBounds(140,160,100,25);
buttonVersuch.setBounds(280,160,100,25);
textareaInfo.setBounds(20,210,360,140);
labelText1.setFont(fntHead);
labelText2.setFont(fntFett);
labelSuche1.setFont(fntHead);
labelSuche2.setFont(fntHead);
labelSuche3.setFont(fntHead);
textfieldVersuch1.setFont(fntFett);
textfieldVersuch2.setFont(fntFett);
textfieldVersuch3.setFont(fntFett);
buttonInfo.setFont(fntFett);
buttonNeu.setFont(fntFett);
buttonVersuch.setFont(fntFett);
textareaInfo.setFont(fntAusgabe);
add(labelText1); add(labelText2);
add(labelSuche1); add(labelSuche2); add(labelSuche3);
add(textfieldVersuch1); add(textfieldVersuch2); add(textfieldVersuch3);
add(buttonInfo); add(buttonNeu); add(buttonVersuch);
add(textareaInfo);
buttonInfo.addActionListener(this);
buttonNeu.addActionListener(this);
buttonVersuch.addActionListener(this);
addWindowListener(this);
setVisible (true);
}
}
Compiles without any problems, but when I try to run the applet: absolutely nothing, not even an error message! 8O

User avatar
CyberPulse
On the way to fame!
On the way to fame!
Posts: 36
Joined: 10 Aug 2005, 16:00
18

Post by CyberPulse »

Deutche macht spass!!! Sorry if the spelling is incorrect, been a while since I took German. Anyways, when you say nothing happens, do you mean absolutely nothing happens? Does it display the user interface? I went through the code and it seems like it should run, unless it is something extremely trival such as a missing ; . Your definitions look good at the beginning. The code for the new and info buttons are defined, have actions for the users interaction, and are referenced properly. The events look good and the user interface seems to have everything needed. I'm with you, this thing should run. I checked your brackets and they each have a match and you put in every ; . Is there any other code that could be affecting the program?

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

No,there aren´t any dependencies to other classes exept the awt-ones.
I think I corrupted the code when I added the event handlers, because the GUI worked already:

Image

Looks like I have to cut the code into pieces, check it, add a piece and then check it again until I find the piece of code which caused the problem.... :?

P.S. yeah, Deutsch macht REALLY Spass! :lol: :wink:

User avatar
CyberPulse
On the way to fame!
On the way to fame!
Posts: 36
Joined: 10 Aug 2005, 16:00
18

Post by CyberPulse »

Yeah, breaking it down is about all you can do. But from looking at the code, that might not work. Every bit of the code seems to be in the proper form. You might want to make sure that they work together properly, but that also looks like it should be working. You got one doosy of a problem here. 8O

User avatar
ilugd
Newbie
Newbie
Posts: 3
Joined: 15 Dec 2005, 17:00
18

Applet with main procedure. Are you sure?

Post by ilugd »

Well your subject says that you have a java applet problem, while the code uses main(). You are supposed to use init() aren't you.

Or was the subject wrong? :?:

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

oops...you´re completely right,man.... 8O
an applet don´t need the main-method, it needs

Code: Select all

import java.applet.Applet;
gawd.... :oops:

Post Reply