Java中Applet的组件位置设置问题,我写了一个代码,但位置设置起不了作用,还请高人指点

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Landing extends Applet
{
int n=1;
JButton landing;
JLabel user,passward,wrong;
JTextField user2;
TextField passward2;
public void init()
{
user=new JLabel("账号");
user.setLocation(100,100);
add(user);
user2=new JTextField(25);
user2.setLocation(200,100);
add(user2);
passward=new JLabel("密码");
passward.setLocation(100,200);
add(passward);
passward2=new TextField(25);
passward2.setLocation(200,200);
passward2.setEchoChar('*');
add(passward2);
landing=new JButton("登录");
landing.setLocation(300,300);
add(landing);
wrong=new JLabel();
wrong.setLocation(100,400);
add(wrong);
}
}
/*
<Applet code="Landing.class" width=800 height=800>
</Applet>
*/

Applet的默认布局为FlowLayout 在里面的组件都只能用默认的大小 (能显示组件的名称) 如果先要自己定义组件大小 把Applet布局设置为 null空布局就可以了
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜