我将在登录后调用一个小程序类。窗体是可见的,但组件是不可见的,这是COuld的问题所在;这是我的类:
/*
* 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和按钮在内的组件未显示。COuld我做错了什么?
发布于 2012-06-12 21:22:04
1)代码行
setSize(1024, 768);
setLayout(null);
setVisible(true);必须将最后几行代码放入public void init() {,因为您先显示容器,然后再添加J/Components
2)如果没有真正的原因(OpenGL,CAD / CAM),那么使用
Swing JApplet而不是史前的3)不使用NullLayout
https://stackoverflow.com/questions/10997409
复制相似问题