登录窗体代码Java java登录窗口代码( 三 )


if(jName.getText().equals("lixiangguo")
String.valueOf(jPassword.getPassword()).equals("19801001"))
{
27、jl[2].setText("登陆成功,欢迎您的到来!");
}
else
{
28、jl[2].setText("对不起,您的用户名或密码错误!");
}
}
}
public static void main(String[] args)
{
29、//创建LoginTest窗体对象
new LoginTest();
}
}
实现界面登陆,退出功能的java代码怎么写?CS结构系统的退出如下:public void init() {\x0d\x0athis.setTitle("用户登录界面");\x0d\x0athis.add(createCenterPane());\x0d\x0athis.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0athis.setSize(new Dimension(450, 335));\x0d\x0athis.setLocationRelativeTo(null);\x0d\x0a// this.setVisible(true);\x0d\x0athis.addWindowListener(new WindowAdapter() {\x0d\x0apublic void windowClosing(WindowEvent e) {\x0d\x0aint choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",\x0d\x0a"系统提示:", JOptionPane.YES_NO_OPTION);\x0d\x0aif (choose == JOptionPane.YES_OPTION) {\x0d\x0aSystem.exit(1);\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0a }其中this为JFrame对象 。BS结构的退出直接用windows.close()方法就行了!
用Java写 计算机窗口和 登录窗口登录窗口:
import javax.swing.*;
import java.awt.*;
public class Ld extends JFrame {
public Ld() {
this.setSize(300,220);
this.setLayout(new BorderLayout());
Container con=this.getContentPane();
JPanel titlePanel = new JPanel();
con.add(titlePanel);
JLabel a=new JLabel("欢迎使用成绩管理系统");
a.setFont(new Font("隶书", Font.PLAIN, 22));
titlePanel.add(a);
con.add(titlePanel,"North");
JLabel b=new JLabel("用户名:");
b.setBounds(50, 20, 50, 20);
JLabel c=new JLabel("密码:");
c.setBounds(50, 50, 50, 20);
JTextField e=new JTextField(20);
e.setBounds(110, 20, 120, 20);
JPasswordField txtPwd=new JPasswordField(20);
txtPwd.setBounds(110, 50, 120, 20);
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
fieldPanel.add(b);
fieldPanel.add(c);
fieldPanel.add(e);
fieldPanel.add(txtPwd);
con.add(fieldPanel, "Center");
JPanelas = new JPanel();
JButton f=new JButton("登录");
as.add(f);
JButton g=new JButton("关闭");
as.add(g);
con.add(as, "South");
this.setVisible(true);
}
public static void main(String[] args) {
new Ld();
}
}
效果:
用JAVA语言编程实现一个用户登录窗口方法一:
采用JOptionPane中的一个非常有用的静态方法 showOptionPane();
源码如下:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;
public class Login1 {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
static void createAndShowGUI() {
JFrame mainFrame = new JFrame();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setBounds(250,250,400,300);
mainFrame.setVisible(false);
usernameField = new JTextField(10);
passwordField = new JPasswordField(10);
Object[] options = {"登录","取消"};
int i = JOptionPane.showOptionDialog(null,createLoginPanel(),"登录信息",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE,null,options,options[0]);
if(i==0) {
String username = usernameField.getText();

推荐阅读