java - Applet 组件不可见

标签 java applet awt null-layout-manager

我在登录后调用小程序类。表单可见但组件不可见可能是什么问题;这是我的类(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
}

表单正在显示,但包括 TextField、Labeld 和 Button 在内的组件未显示。我可能做错了什么?

最佳答案

1)代码行

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

必须是 public void init() { 中的最后一行代码,因为您显示容器然后添加 J/Components

2) 如果没有真正的原因(OpenGL、CAD/CAM)则使用

3) 不要使用 NullLayout

关于java - Applet 组件不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10997409/

相关文章:

java - 搜索数组中的单词

java - 找不到 GlideApp

java - 在 Eclipse 中使用 ControlP5 进行处理会导致按键时出现 IllegalArgumentException

java.awt.geom.Area 减去后返回多个部分?

java - 如何在一个 Choice 上创建一个函数来改变其他 Choice 的内容

java - 我们可以在 Java 6 中使用一些 JavaFX 类吗?

java - 将 isElementPresent() 从 Selenium 1 迁移到 Selenium 2 时如何避免超时?

java - 我用于嵌入 Java Applet 的对象标签有什么问题?

java - 编译 Java 小程序 (Mac OSX)

java - 如何编辑转换为图像的文本?或任何其他实现/编辑文本的方法