jpfPassword.setBounds(100,50,150,20);
jButtonEnter.setBounds(80,90,60,20);
jButtonCancel.setBounds(160,90,60,20);
this.add(jLabelUserName);
this.add(jLabelPassword);
this.add(jTextFieldUserName);
this.add(jpfPassword);
this.add(jButtonEnter);
this.add(jButtonCancel);
设置 FirstSwing 的大小、标题和可见性:
this.setBounds(330,250,300,150);
this.setTitle(" 这是第一个 Swing 程序! ");
this.setVisible(true);
这样,整个程序就完成了,下面给出完整的代码:
import java.awt.*;
import javax.swing.*;
class FirstSwing extends JFrame
{private JLabel jLabelUserName;
private JLabel jLabelPassword;
private JTextField jTextFieldUserName;
private JPasswordField jpfPassword;
private JButton jButtonEnter;
private JButton jButtonCancel;
public FirstSwing()
{
this.setLayout(null);
jLabelUserName=new JLabel(" 用户名: ");
jLabelPassword=new JLabel(" 密码: ");
jTextFieldUserName=new JTextField();
jpfPassword=new JPasswordField();
jButtonEnter=new JButton(" 确定 ");
jButtonCancel=new JButton(" 取消 ");
jLabelUserName.setBounds(10,20,80,20);
jLabelPassword.setBounds(10,50,80,20);
jTextFieldUserName.setBounds(100,20,150,20);
jpfPassword.setBounds(100,50,150,20);
jButtonEnter.setBounds(80,90,60,20);
jButtonCancel.setBounds(160,90,60,20);
this.add(jLabelUserName);
this.add(jLabelPassword);
this.add(jTextFieldUserName);
this.add(jpfPassword);
this.add(jButtonEnter);
this.add(jButtonCancel);
评论0
最新资源