Pergunta

I am Calling an Applet Class After Login. The form is Visible but the Components are Not Visible what COuld be the Issue; Here is My Class:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package stanacle;


import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Calendar;
import javax.swing.JOptionPane;
/**
*
* @author Stano
*/
public class MenuOption extends JApplet{
Label header, menu, error, user;
TextField option;
Button go;

/**
 * Initialization method that will be called after the applet is loaded
 * into the browser.
 */
public void init() {
    // TODO start asynchronous download of heavy 
    setSize(1024, 768);
    setLayout(null);
    setVisible(true);
    header = new Label();
        menu = new Label();
        error = new Label();
        user = new Label();
        option = new TextField();
        go = new Button("GO");
        header.setBounds(370, 10, 200, 20);
        menu.setBounds(10, 60, 200, 20);
        option.setBounds(150, 60, 200, 20);
        go.setBounds(750, 10, 150, 30);
        error.setBounds(370, 310, 500, 20);
        user.setBounds(10, 10, 200, 20);
        header.setText("MENU OPTION PAGE");
        menu.setText("Enter Menu Option");


        add(header);
        add(menu);
        add(option);
        add(go);
        add(error);
        add(user);
}
// TODO overwrite start(), stop() and destroy() methods
}

The Form is Showing but the Components which Include the TextField, The Labeld and the Button Are Not showing. What COuld I be Doing Wrong?

Foi útil?

Solução

1) code lines

setSize(1024, 768);
setLayout(null);
setVisible(true);

must be last code lines into public void init() {, because you show container and then to add J/Components

2) if isn't there real reason (OpenGL, CAD / CAM) then use

  • Swing JApplet rather than prehistoric AWT Applet

  • Swing JComponents instead of AWT Components

3) don't use NullLayout

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top