|
-
Jul 16th, 2002, 05:00 PM
#1
Applet problem
I can not see any of my component why ?
Here is all the code, I forget something but I do not remember what 
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class mainInterface extends JApplet {
JFrame frame = new JFrame();
JLabel lbl_titre = new JLabel();
JLabel lbl_prenom = new JLabel();
JLabel lbl_nom = new JLabel();
JLabel lbl_pays = new JLabel();
JLabel lbl_adresse = new JLabel();
JLabel lbl_numero = new JLabel();
//Initialize the applet
public void init() {}
public mainInterface()
{
JApplet applet = new mainInterface();
frame.setTitle("Applet Frame");
frame.setContentPane(applet.getContentPane());
frame.setLayout (null);
//applet.init(); applet.start();
frame.setSize(400,320);
initComponent();
frame.setVisible(true);
} //End constructor : mainInterface
//Main method
public static void main(String args[])
{
mainInterface goGo = new mainInterface();
}//End Main
public void initComponent()
{
//Ajout du texte
lbl_titre.setText ("Donation Internationale");
lbl_prenom.setText ("Prenom:");
lbl_nom.setText ("Nom:");
lbl_pays.setText ("Pays:");
lbl_adresse.setText ("Adresse:");
lbl_numero.setText ("Numero de carte de crédit:");
//Positionnement
lbl_titre.setBounds (10,10,200,25);
lbl_prenom.setBounds (10,35,40,25);
lbl_nom.setBounds (10,60,40,25);
lbl_pays.setBounds (10,85,40,25);
lbl_adresse.setBounds (10,110,40,25);
lbl_numero.setBounds (10,135,40,25);
//Ajout dans le frame
frame.add (lbl_titre);
frame.add (lbl_prenom);
frame.add (lbl_nom);
frame.add (lbl_pays);
frame.add (lbl_adresse);
frame.add (lbl_numero);
}//End initComponent
}//End class : mainInterface
-
Jul 16th, 2002, 09:38 PM
#2
I think you forgot that applets start from "init" and applications start from "main".
If you just wanted an applet, you could set the html page's title as "Applet Frame" and do this:
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*
<applet code=mainInterface.class width=400 height=320></applet>
*/
public class mainInterface extends JApplet {
Container contentPane;
JLabel lbl_titre;
JLabel lbl_prenom;
JLabel lbl_nom;
JLabel lbl_pays;
JLabel lbl_adresse;
JLabel lbl_numero;
//Initialize the applet
public void init() {
contentPane = getContentPane();
lbl_titre = new JLabel();
lbl_prenom = new JLabel();
lbl_nom = new JLabel();
lbl_pays = new JLabel();
lbl_adresse = new JLabel();
lbl_numero = new JLabel();
// frame.setTitle("Applet Frame");
contentPane.setLayout (null);
initComponent();
} //End initialization : mainInterface
public void initComponent()
{
//Ajout du texte
lbl_titre.setText ("Donation Internationale");
lbl_prenom.setText ("Prenom:");
lbl_nom.setText ("Nom:");
lbl_pays.setText ("Pays:");
lbl_adresse.setText ("Adresse:");
lbl_numero.setText ("Numero de carte de crédit:");
//Positionnement
lbl_titre.setBounds (10,10,200,25);
lbl_prenom.setBounds (10,35,40,25);
lbl_nom.setBounds (10,60,40,25);
lbl_pays.setBounds (10,85,40,25);
lbl_adresse.setBounds (10,110,40,25);
lbl_numero.setBounds (10,135,40,25);
//Ajout dans le frame
contentPane.add (lbl_titre);
contentPane.add (lbl_prenom);
contentPane.add (lbl_nom);
contentPane.add (lbl_pays);
contentPane.add (lbl_adresse);
contentPane.add (lbl_numero);
}//End initComponent
}//End class : mainInterface
You could also have an applet that launches a frame. That is closer to how your code was written, but I didn't think that was your goal. You have a major design issue to think about. Consider your actual objects versus your references to those objects (mainInterface and JFrame versus frame, goGo, and applet).
Or, perhaps you are really trying for an application and you don't need an applet, but will only use the frame.
I'm actually surprised that as your code was written and used as an applet, even the constructor seems to be called before init. I'd have to look to see if that is documented that way. main should not be implicitly called (and it wasn't), but you could call it like a regular method that is named "main".
-
Jul 17th, 2002, 12:13 PM
#3
I want the applet in one webpage but I only got a GRAY rectangle with no component (and I used the code you posted). What's wrong? I think the applet doesn't load
-
Jul 17th, 2002, 12:50 PM
#4
well, I just installed JBuilder 7 and inside JBuilder7, I can see the applet...strange
-
Jul 17th, 2002, 04:50 PM
#5
AppletViewer hummm let me search that program
-
Jul 31st, 2002, 07:55 PM
#6
Addicted Member
May be your classpath is not correct.You can test running appletviewer
>>appletviewer test.html
-
Aug 2nd, 2002, 08:00 PM
#7
Ya ya Baby!!!Me is Back
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|