import javax.swing.BoxLayout;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.Dimension; 
import java.awt.GridBagConstraints; 
import java.awt.GridBagLayout; 
import java.awt.Insets; 

public class LoginApplet extends JApplet { /**
 * 
 */
private static final long serialVersionUID = 1L;

JLabel titlePage; 
JLabel[] txt; 
JTextField[] jtf; 
JButton accept, decline;
JPanel jp1, jp2, jp3;


public void init(){
    setSize(400,400);

    JPanel content = (JPanel)getContentPane(); 
    GridBagConstraints firstCol = new GridBagConstraints(); 
    firstCol.weightx = 1.0; 
    firstCol.anchor = GridBagConstraints.WEST; 
    firstCol.insets = new Insets(5, 20, 5, 5); 
    GridBagConstraints lastCol = new GridBagConstraints(); 
    lastCol.gridwidth = GridBagConstraints.REMAINDER; 
    lastCol.weightx = 1.0; 
    lastCol.fill = GridBagConstraints.HORIZONTAL; 
    lastCol.insets = new Insets(5, 5, 5, 20); 

    String[] labeltxt = {"Username", "Password"}; 
    titlePage = new JLabel("Create New Account"); 
    txt = new JLabel[2]; 
    jtf = new JTextField[2]; 
    accept = new JButton("Create"); 
    decline = new JButton("Decline"); 

    jp1 = new JPanel(); 
    jp2 = new JPanel(new GridBagLayout()); 
    jp3 = new JPanel(); 
    for(int i=0; i<labeltxt.length; i++) { 
        txt[i] = new JLabel(); 
        txt[i].setText(labeltxt[i]); 
        jp2.add(txt[i], firstCol); 
        jtf[i] = new JTextField(); 
        jtf[i].setPreferredSize(new Dimension(300, 20)); 
        jp2.add(jtf[i], lastCol); 
        } 
        jp1.add(titlePage); 
        jp3.add(accept); 
        jp3.add(decline); 
        content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); 
        content.add(jp1); 
        content.add(jp2); 
        content.add(jp3); 

    }

public void setVisible(boolean b) {
    // TODO Auto-generated method stub

}


}

Hi guys.. This code I have posted up is from class LoginApplet which gets called by an ActionPerformed from another class.... I had no problem with it set as JFrame (the rubric for this assignment was in JApplet). Now when I converted it to JApplet problems show up. I am not familiar with JApplet, and is there anything wrong with the code showing up as blank when ran?

有帮助吗?

解决方案

Get rid of

public void setVisible(boolean b) {
    // TODO Auto-generated method stub
}

It's preventing the applet from thinking it's visible...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top