2012-06-12 27 views
2

我在登錄後調用Applet類。表單是可見的,但組件不可見是什麼成爲問題;這裏是我的班級:小程序組件不可行

/* 
* 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,標籤和按鈕的組件不顯示。我做錯了什麼?

+0

我不知道,但也許你要調用調用setVisible(真) –

+0

我只是跑這與JRE 7( 32位),所有組件都可見。 –

+0

SetVisible已經存在。 – ErrorNotFoundException

回答

1

1)行代碼

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

必須是最後的代碼行到public void init() {,因爲你展示容器中,然後加入J/Components

2)如果不存在真正的原因(OpenGL中,CAD/CAM),然後使用

3)不使用NullLayout

+0

我移動了代碼行。這可能是我使用的方法來調用類MenuOption page = new MenuOption(); – ErrorNotFoundException

+0

對於第3點+1。 –

+1

'setSize(1024,768);'..必須在HTML中。 ;) –

相關問題