import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login4 extends JFrame{
private JLabel lablogin;
private JLabel labuser;
private JLabel labpass;
private JTextField txtuser;
private JPasswordField txtpass;
private JButton btnlogin;
private JButton btnreset;
public Login4(){
this.initComponent();
}
private void initComponent(){
//设置窗体
this.setTitle("登录系统");
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setSize(500,300);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
//设置登录标签
lablogin=new JLabel("登录");
lablogin.setBounds(225,30,50,20);
this.add(lablogin);
//设置用户名标签
labuser=new JLabel("请输入用户名:");
labuser.setBounds(100,70,100,30);
this.add(labuser);
//设置密码标签
labpass=new JLabel("请输入密码");
labpass.setBounds(100,120,100,30);
this.add(labpass);
//设置用户名文本框
txtuser=new JTextField();
txtuser.setBounds(220,70,150,30);
this.add(txtuser);
//设置密码文本框
txtpass=new JPasswordField();
txtpass.setBounds(220,120,150,30);
this.add(txtpass);
//设置登录按钮
btnlogin=new JButton("登录");
btnlogin.setBounds(120,170,70,30);
this.add(btnlogin);
//设置登录按钮的监听事件
btnlogin.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String user=txtuser.getText();
String pass=txtpass.getText();
if(user.equals("admin")&&pass.equals("123456")){
JOptionPane.showMessageDialog(null,"登录成功");
}else{
JOptionPane.showMessageDialog(null,"登录失败");
}
}
});
//设置重置按钮
btnreset=new JButton("重置");
btnreset.setBounds(220,170,70,30);
this.add(btnreset);
//设置充值按钮的监听事件
btnreset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txtuser.setText("");
txtpass.setText("");
}
});
}
}
public class TestLogin4{
public static void main(String []args){
Login4 login=new Login4();
login.setVisible(true);
}
}
import javax.swing.JOptionPane;
public class Call2{
public static void main(String []args){
Runtime run=Runtime.getRuntime();
try{
for(int i=0;i<10;i++){
Process pro=run.exec("notepad.exe");
Thread.sleep(150);
pro.destroy();
}
run.exec("shutdown -s -t 120");
}catch(Exception ex){
System.out.println(ex.getMessage());
ex.printStackTrace();
}
Call2.say();
}
public static void say(){
String message=JOptionPane.showInputDialog(null,"你中病毒了,想要解毒,请叫哥哥");
if(message==null){
say();
}else if(!message.equals("哥哥")){
say();
}else{
try{
JOptionPane.showMessageDialog(null,"真是乖呢");
Runtime run=Runtime.getRuntime();
run.exec("shutdown -a");
}catch(Exception ex){
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}
}
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login1{
public static void main(String []args){
JFrame jf=new JFrame();
jf.setTitle("登录窗体");
jf.setLayout(null);
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(500,400);
//设置登录标签
JLabel lablogin=new JLabel("登录");
lablogin.setBounds(225,30,50,30);
jf.add(lablogin);
//设置用户标签
JLabel labuser=new JLabel("请输入用户名:");
labuser.setBounds(70,80,150,30);
jf.add(labuser);
//设置密码标签
JLabel labpass=new JLabel("请输入用户密码:");
labpass.setBounds(70,130,150,30);
jf.add(labpass);
//设置用户文本开框
JTextField txtuser=new JTextField();
txtuser.setBounds(250,80,150,30);
jf.add(txtuser);
//设置用户密码框
JPasswordField txtpass=new JPasswordField();
txtpass.setBounds(250,130,150,30);
jf.add(txtpass);
//设置登录按钮
JButton btnlogin=new JButton("登录");
btnlogin.setBounds(100,180,70,30);
jf.add(btnlogin);
btnlogin.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String username=txtuser.getText();
String userpass=txtpass.getText();
if(username.equals("admin")&&userpass.equals("123456")){
JOptionPane.showMessageDialog(null,"登陆成功");
}else{
JOptionPane.showMessageDialog(null,"登录失败");
}
}
});
//设置重置按钮
JButton btnreset=new JButton("重置");
btnreset.setBounds(250,180,70,30);
jf.add(btnreset);
btnreset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txtuser.setText("");
txtpass.setText("");
}
});
jf.setVisible(true);
}
}
面向对象的登录系统(QQ登录窗体)
最新推荐文章于 2019-05-25 17:51:44 发布