3条回答 默认 最新
- CSDN专家-Fay 2021-06-21 10:40关注
有方法没有定义返回值,17行截出来看看,代码多处错误:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Login extends JFrame { /** * */ private static final long serialVersionUID = 1L; JLabel a1 = new JLabel("账号:"); JLabel a2 = new JLabel("密码:"); JButton b1 = new JButton("确定"); JButton b2 = new JButton("重置"); JTextField jt; JPasswordField jp; public Login() { setTitle("登录"); setBounds(500, 250, 300, 200); setVisible(true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container cp = getContentPane(); jt = new JTextField(15); jp = new JPasswordField(15); JPanel p1 = new JPanel(); p1.add(a1); p1.add(jt); JPanel p2 = new JPanel(); p2.add(a2); p2.add(jp); JPanel p3 = new JPanel(); p3.add(b1); p3.add(b2); cp.add( p1,BorderLayout.NORTH); cp.add(p2,BorderLayout.CENTER); cp.add( p3,BorderLayout.SOUTH); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arge0) { jt.setText(""); jp.setText(""); } }); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String t1 = jt.getText(); String jt1 = "test1"; if ((t1.trim().equals(jt1)) && new String(jp.getPassword()).trim().equals("test1")) { JOptionPane.showMessageDialog(null, "登录成功"); } else { JOptionPane.showMessageDialog(null, "用户或密码错误,请重新输入"); } } }); } public static void main(String[] args) { new Login(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报