资源描述:
《java文本框只有下面一条线》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.llt.demo;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Rectangle;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;importjavax.swing.SwingUtilitie
2、s;importjavax.swing.UIManager;importjavax.swing.UnsupportedLookAndFeelException;importjavax.swing.border.MatteBorder;importjavax.swing.JLabel;/***@author刘力天*/publicclassLoginFrameextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJPaneljContentPane=null;privateJTextFielduserN
3、ame=null;privateJPasswordFieldpassword=null;privateJButtonloginButton=null;/***创建用户名文本框**@returnjavax.swing.JTextField*/privateJTextFieldgetUserName(){if(userName==null){userName=newJTextField();//创建文本框userName.setBackground(newColor(0,0,0,0));//设置文本框透明背景色//设置文本框位置与大小userName.setBounds(n
4、ewRectangle(70,26,162,21));//设置文本框大小MatteBorderborder=newMatteBorder(0,0,2,0,newColor(0,250,154));//创建边框userName.setBorder(border);//色绘制边框}returnuserName;}/***创建密码框**@returnjavax.swing.JPasswordField*/privateJPasswordFieldgetPassword(){if(password==null){password=newJPasswordField();//创建
5、密码框//设置密码框位置和大小password.setBounds(newRectangle(71,57,159,22));password.setBackground(newColor(0,0,0,0));//设置透明颜色password.setOpaque(false);//设置透明password.setBorder(newMatteBorder(0,0,2,0,newColor(255,215,0)));//设置边框password.setEchoChar('★');//设置密码框字符}returnpassword;}/***创建登录按钮**@returnjav
6、ax.swing.JButton*/privateJButtongetLoginButton(){if(loginButton==null){loginButton=newJButton("登录");//设置按钮位置与大小loginButton.setBounds(newRectangle(244,22,68,68));}returnloginButton;}/***主类的入口方法**@paramargs*@throwsUnsupportedLookAndFeelException*不支持的外观*/publicstaticvoidmain(String[]args)th
7、rowsUnsupportedLookAndFeelException{try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Throwablee){e.printStackTrace();}//设置窗体外观SwingUtilities.invokeLater(newRunnable(){publicvoidrun(){//创建登录窗体LoginFrameloginFrame=newLoginFrame();//显示登