一个用java写的简单后台登陆程序 求教!!

justxueqingxiao justxueqingxiao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class login{
JLabel JLabel1,JLabel2;
JFrame mainJFrame;
Container con;
JButton loginbtn,cancelbtn;
JTextField userText;
JTextField passwordField;
HandleAction handleAction;

public class HandleAction implements ActionListener{
public void actionPerformed(ActionEvent e){
String msg;
if(e.getSource()==loginbtn){
msg="your username:"+userText.getText()+"\n your password:"
+new String(passwordField.getText());
JOptionPane.showMessageDialog(mainJFrame,msg);
}
else if(e.getSource()==cancelbtn){
passwordField.setText("");
userText.setText("");
}
}
}
public login(){
handleAction=new HandleAction();
JLabel1=new JLabel("用户名");
JLabel2=new JLabel("密码");
mainJFrame=new JFrame("后台登陆");
con=mainJFrame.getContentPane();
loginbtn=new JButton("登陆");
loginbtn.addActionListener(handleAction);
cancelbtn=new JButton("取消");
cancelbtn.addActionListener(handleAction);
userText=new JTextField();
userText.setColumns(20);
passwordField=new JPasswordField();
passwordField.setColumns(20);
con.add(JLabel1);
con.add(userText);
con.add(JLabel2);
con.add(passwordField);
con.add(loginbtn);
con.add(cancelbtn);
mainJFrame.setSize(300,300);
mainJFrame.setVisible(true);
mainJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){new login();}
}
但是运行后结果:是所有的标签和按钮都叠加到了一起,本人初学java求大神指教。
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
justxueqingxiao
Java SE 62,621 成员 307,251 内容