📄 nolayout.java
字号:
import java.awt.*;
import javax.swing.*;
public class NoLayout extends JFrame
{
private JLabel username, password;
private JTextField username2;
private JPasswordField password2;
private JButton button;
public NoLayout()
{
super("NoLayout");
setSize(300, 250);
try
{ //系统外观
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
//获取内容面板并且设置布局管理器
Container container = getContentPane();
container.setBackground(Color.YELLOW);
container.setLayout(null);
//创建标签
username = new JLabel("用户名:", JLabel.RIGHT);
password = new JLabel("密 码:", JLabel.RIGHT);
//创建文本域,密码域
username2 = new JTextField(10);
password2 = new JPasswordField(10);
//创建按钮
button = new JButton("确定");
//设置组件放置位置
username.setBounds(80, 50, 50, 25);
username2.setBounds(140, 50, 70, 25);
password.setBounds(77, 85, 50, 25);
password2.setBounds(140, 85, 70, 25);
button.setBounds(125, 120, 60, 25);
container.add(username);
container.add(username2);
container.add(password);
container.add(password2);
container.add(button);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String arguments[])
{
NoLayout application = new NoLayout();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -