java新建窗体代码 java新建窗体方法( 三 )


if (p *** t != null) {
p *** t.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
第3个实体使用者类:User.java
package edu.sys.text.model.entity;
public class User {
private String loginName;
private String userName;
private String passWord;
private int age;
private String address;
public User() {
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public void setAge(int age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
public String getLoginName() {
return loginName;
}
public String getUserName() {
return userName;
}
public String getPassWord() {
return passWord;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
}
然后编写控制层(C):GetInfoServlet.java
package edu.sys.text.control;
import javax.servlet.*;
import javax.servlet..*;
import java.io.*;
import java.util.*;
import edu.sys.text.model.entity.User;
import edu.sys.text.model.service.UserManager;
public class GetInfoServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/; charset=GBK";
Initialize global variables
public void init() throws ServletException {
}
Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
}
Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String loginName = request.getParameter("loginName");
String passWord = request.getParameter("passWord");
User u = new User();
u.setLoginName(loginName);
u.setPassWord(passWord);
UserManager m = new UserManager();
RequestDispatcher d;
if (m.checkUser(u)) {
User o = m.checkBC(u);
request.setAttribute("JavaBEAN",o);
d = request.getRequestDispatcher("GetInfoUser.jsp");
} else {
d = request.getRequestDispatcher("GetInfoFinale.jsp");
}
d.forward(request, response);
}
Clean up resources
public void destroy() {
}
}
最后,建立表示层(V):包括3个Jsp(登入页面GetInfo.jsp、登入成功页面GetInfoUser.jsp、登入失败页面GetInfoFinale.jsp)
上面的就是Jsp结合Servlet用MVC架构写的使用者登入程式 。
用java编写一个窗体资料输入比较程式
使用画图功能 , 关于比较那是很简单的逻辑
JFrame frame = new JFrame("XXX");
ShootGame game = new ShootGame(); 面板物件
frame.add(game); 将面板新增到JFrame中
frame.setSize(WIDTH, HEIGHT); 设定大小
frame.setAlwaysOnTop(true); 设定其总在最上
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 预设关闭操作
frame.setIconImage(new ImageIcon("images/icon.jpg").getImage()); 设定窗体的图示
frame.setLocationRelativeTo(null); 设定窗体初始位置
frame.setVisible(true); 尽快呼叫paint
game.action(); 启动执行
怎么用java写一个tomcat的启动,停止程式
可以利用Runtime类,Runtime用于别是虚拟机器执行时的状态,它用于封装JVM虚拟机器程序 。
看看,我给你写个程式码:
public class Run {
public static void main(String[] args) throws Exception {

推荐阅读