新建一个窗口,然后实现一个关闭按钮”窗口的功能
创新互联成立10余年来,这条路我们正越走越好,积累了技术与客户资源,形成了良好的口碑。为客户提供网站建设、成都网站建设、网站策划、网页设计、域名注册、网络营销、VI设计、网站改版、漏洞修补等服务。网站是否美观、功能强大、用户体验好、性价比高、打开快等等,这些对于网站建设都非常重要,创新互联通过对建站技术性的掌握、对创意设计的研究为客户提供一站式互联网解决方案,携手广大客户,共同发展进步。
import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}
跳转之前加入代码:PrinterWrite out = response.getPinterWrite();
out.println("script alert('注册成功');/script");
界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Register extends JFrame {
JLabel jl1 = new JLabel("用户名");
JTextField jt1 = new JTextField();
JLabel jl2 = new JLabel("邮箱");
JTextField jt2 = new JTextField();
JLabel jl3 = new JLabel("密码");
JPasswordField jpw1 = new JPasswordField();
JLabel jl4 = new JLabel("密码确认");
JPasswordField jpw2 = new JPasswordField();
JButton register = new JButton("注册");
JButton clean = new JButton("清空");
public Register(){
setLayout(new GridLayout(5,2));
add(jl1);
add(jt1);
add(jl2);
add(jt2);
add(jl3);
add(jpw1);
add(jl4);
add(jpw2);
add(register);
add(clean);
String name = jt1.getText();
String email = jt2.getText();
String pw = jpw1.getText();
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
Statement sta = con.createStatement();
sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");
JOptionPane.showMessageDialog(null,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex){
ex.getStackTrace();
}
}
});
clean.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jpw1.setText("");
jpw2.setText("");
}
});
}
public static void main(String[] args){
Register frame = new Register();
frame.setTitle("用户注册");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}
script type="text/javascript" src="../js/jquery-1.4.1.min.js"/script
script type="text/javascript" src="../js/jquery.validate.min.js"/script
script type="text/javascript"
$(function(){
$("#f").validate({
rules:{
email:{
required:true,
email:true
},
nickname:{
required:true,
minlength:4,
maxlength:20
},
password:{
required:true,
minlength:6,
maxlength:20
},
password1:{
required:true,
equalTo:"#txtPassword"
},
number:{
required:true,
remote:"checkCode.action" }
},
messages:{
email:{
required:"登录名必须填写",
email:"请填写正确的Email格式"
},
nickname:{
required:"昵称必须填写",
minlength:"昵称长度不得小于4位",
maxlength:"昵称长度不得超过20位"
},
password:{
required:"密码必须填写",
minlength:"密码长度不得小于6位",
maxlength:"密码长度不得超过20位"
},
password1:{
required:"请输入密码验证",
equalTo:"必须与上面密码相同"
},
number:{
required:"验证码必须填写",
remote:"验证码输入错误"
}
}
});
});
/script
这是用jquery的一个jquery.validate.min.js插件写的 其实可以用js完成