发布网友 发布时间:2022-04-22 22:52
共2个回答
热心网友 时间:2023-10-07 07:03
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Demo extends JFrame{
String username;
String password;
public Demo() {
username = "java";
password = "123";
setTitle("#####");
setSize(400, 300);
setLocation(400, 200);
setLayout(new FlowLayout());
JTextArea jta = new JTextArea(4,30);
jta.setText("请输入用户名密码:\n用户名:"+username+"\n密码:"+password);
jta.setEditable(false);//设置文本区域不可编辑
add(jta);
JLabel usernameLabel = new JLabel("用户名:");
final JTextField usernameText = new JTextField(10);
add(usernameLabel);
add(usernameText);
JLabel passwordLabel = new JLabel("密码:");
final JTextField passwordText = new JTextField(10);
add(passwordLabel);
add(passwordText);
JButton button = new JButton("登录");
add(button);
final JLabel result = new JLabel();//用来显示登录结果
add(result);
button.addActionListener(new ActionListener() {//登录按钮事件
@Override
public void actionPerformed(ActionEvent e) {
//获取输入的用户名密码
String tempUserName = usernameText.getText();
String tempPassWord = passwordText.getText();
if(tempUserName.equals(username)&&tempPassWord.equals(password)){
result.setText("登录成功");
}else{
result.setText("登录失败");
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Demo();
}
}
追问大神 这里那里错了 : public void actionPerformed(ActionEvent e) 这里运行处错啊
好人一生平安啊
追答没问题啊啊
热心网友 时间:2023-10-07 07:03
没分?????????????