界面开发
方法
例子
importjavax.swing.*;importjava.awt.*;publicclassjM0808{publicvoidshowUI(){// 1. 创建窗口并设置布局JFramejf=newJFrame("登录系统");jf.setSize(300,200);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);jf.setLayout(newFlowLayout());// 换成流式布局,防止组件被覆盖// 2. 创建组件JTextFieldnameJtf=newJTextField(15);// 这里改为15列,看起来更协调JLabelpwdJla=newJLabel("密码:");JPasswordFieldpwdJtf=newJPasswordField(15);JButtonbtn=newJButton("登录");// 3. 将组件添加到窗体jf.add(nameJtf);jf.add(pwdJla);jf.add(pwdJtf);jf.add(btn);// 4. Make the window visiblejf.setVisible(true);}publicstaticvoidmain(String[]args){newjM0808().showUI();}}