import javax.swing.*;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JAVAJLABLE extends JFrame implements ActionListener{
JLabel Name=null;
JLabel Cipher=null;
JLabel Sex=null;
JLabel Speciality=null;
JLabel Photo=null;
JRadioButton boy,girl;
ButtonGroup bg;
JButton btn=new JButton("登录");
JButton Registered=new JButton("注册");
JButton Cancel=new JButton("取消");
JTextField name=new JTextField(10);
JPasswordField cipher=new JPasswordField(10);
JMenuBar mb;
JMenu m1,m2,m3;
JMenuItem menuItem;
void MyFarme(){
this.setSize(300,400);
this.setTitle("JAVA程序!");
this.setLayout(null);
Name=new JLabel("用户名");
Cipher=new JLabel("密码");
Sex=new JLabel("性别:");
Speciality=new JLabel("专业:");
ImageIcon photo=new ImageIcon("C:/Users/hp/Desktop/123.jpg");
photo.setImage(photo.getImage().getScaledInstance(50, 50,Image.SCALE_DEFAULT));
JLabel Photo=new JLabel(photo);
boy=new JRadioButton("男");
girl=new JRadioButton("女");
bg=new ButtonGroup();
bg.add(boy);bg.add(girl);
Object[] Content=new Object[] {"大数据","嵌入式","软英","软件会计"};
JComboBox speciality=new JComboBox(Content);
Name.setBounds(50,55 , 60, 26);
Cipher.setBounds(50,80 , 60, 26);
name.setBounds(90, 55, 120, 26);
name.setEditable(false);
cipher.setBounds(90, 80, 120, 26);
cipher.setEditable(false);
Sex.setBounds(50, 110, 60, 26);
boy.setBounds(90, 110, 60, 26);
girl.setBounds(130, 110, 60, 26);
Speciality.setBounds(50, 140, 60, 26);
speciality.setBounds(90, 140, 120, 26);
Photo.setBounds(10, 10, 60, 40);
btn.setBounds(100, 180, 90, 40);
Registered.setBounds(10, 230, 60, 40);
Cancel.setBounds(215, 230, 60, 40);
mb=new JMenuBar();
m1=new JMenu("文件");
m2=new JMenu("编辑");
menuItem=new JMenuItem("保存");
mb.add(m1);
mb.add(m2);
m2.add(menuItem);
this.add(Name);
this.add(Cipher);
this.add(name);
this.add(cipher);
this.add(Sex);
this.add(girl);
this.add(boy);
this.add(Speciality);
this.add(speciality);
this.add(Photo);
this.add(btn);
this.add(Registered);
this.add(Cancel);
this.setJMenuBar(mb);
Registered.addActionListener(this);
Cancel.addActionListener(this);
btn.addActionListener(this);
menuItem.addActionListener(this);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Cancel) {
name.setText("");
cipher.setText("");
name.setEditable(false);
cipher.setEditable(false);
}
if (e.getSource() == Registered||e.getSource() ==btn) {
name.setEditable(true);
cipher.setEditable(true);
}
if(e.getSource() == menuItem){
name.setEditable(true);
cipher.setEditable(true);
name.setText("");
cipher.setText("");
name.setEditable(false);
cipher.setEditable(false);
}
}
}
public class test {
public static void main(String args[]) {
new JAVAJLABLE().MyFarme();
}
}