import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class a extends JFrame implements ActionListener{public static void main(String[] args) {new a();}JLabel JL1 = new JLabel ("用户名:");JLabel JL2 = new JLabel ("密码 :");JComboBox JC = new JComboBox(new String[] {"123","456"});JPasswordField JP1 = new JPasswordField(10);JButton JB1 = new JButton("确定");JButton JB2 = new JButton("取消");JRadioButton JR1 =new JRadioButton("用户登陆");//创建单选按钮JRadioButton JR2 =new JRadioButton("管理员登陆");//创建单选按钮ButtonGroup BG=new ButtonGroup(); //创建按钮组public a() {JPanel JP = (JPanel) ContentPane();JP.setLayout(new GridLayout(4,2,10,10));//设置网格布局四行二列上下左右间距为十JB1.addActionListener(this);JB2.addActionListener(this);BG.add(JR1);BG.add(JR2);JP.add(JL1);JP.add(JC);JP.add(JL2);JP.add(JP1);JP.add(JR1);JP.add(JR2);JP.add(JB1);JP.add(JB2);this.setSize(300,200);//设置窗口大小this.setLocationRelativeTo(null);//窗口居中this.setVisible(true);//窗口可见this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置关闭模式}@Overridepublic void actionPerformed(ActionEvent e) {Source()==JB1) {//是否点击JB1按钮if(JR1.isSelected()) {//是否选择了单选按钮的"用户登陆"SelectedItem().equals("123") && Text().equals("123")) JOptionPane.showMessageDialog(this,"欢迎您,用户"SelectedItem()+"登陆成功");else JOptionPane.showMessageDialog(this, "用户名或密码错误");}else if(JR2.isSelected()) {//是否选择了单选按钮的"管理员登陆"SelectedItem().equals("456") && Text().equals("456")) JOptionPane.showMessageDialog(this,"欢迎您,管理员"SelectedItem()+"登陆成功");else JOptionPane.showMessageDialog(this, "用户名或密码错误");}}Source()==JB2) {//是否点击JB2按钮"取消"按钮it(0);//关闭窗口}}
}
本文发布于:2024-02-02 06:02:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170682491941840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |