2007-06-21 11:33
转载注明出处
http://hi.baidu.com/burtcn
必须使用mysql数据库,因为它支持limit语句
Page.java
package cn.burt;
public class Page {
//索引从0开始
public final static int COUNTS_PERPAGE=20;//每页有20项
public final static int PAGES_PERSECT=10;//每面有10页
private int total_page;
private int total_count;
private int current_page;
private int current_page_index;
private int index;
private String url;
//插入页码
private void insertItem(int pagenum,StringBuffer sb){
//这一页开始的编号
int id=COUNTS_PERPAGE*(pagenum-1);
if(pagenum!=current_page)
sb.append(" <a href=\""+url+"?startindex="+id+"\">"+pagenum+"</a>");
else
sb.append(" "+pagenum);
}
//插入"下一页"
private void insertItem(int index,String str,StringBuffer sb){
sb.append(" <a href=\""+url+"?startindex="+index+"\">"+str+"</a>");
}
public String getFooter(){
StringBuffer sb=new StringBuffer("分页: ");
if(total_count<COUNTS_PERPAGE){//不足一页
return "";
}else if(total_page<PAGES_PERSECT){//不足一面
//页码
for(int i=1;i<=total_page;i++)
insertItem(i,sb);
//下一页
if(current_page<total_page)
insertItem(current_page*COUNTS_PERPAGE,"下一页",sb);
}else{
//每一面有多少条记录
int unit=COUNTS_PERPAGE*PAGES_PERSECT;
//index处于哪个页
int page=(index+1)/COUNTS_PERPAGE+1;
//page处于那个面
int section=page/PAGES_PERSECT+1;
//总的面数
int section_count=total_count/unit+1;
if(section==1){
if(index>=COUNTS_PERPAGE)
insertItem((current_page-2)*COUNTS_PERPAGE,"上一页", sb);
for(int i=1;i<=PAGES_PERSECT;i++)
insertItem(i,sb);
if(current_page<total_page)
insertItem(current_page*COUNTS_PERPAGE,"下一页",sb);
if(section_count>1)
insertItem(1*unit,"下"+PAGES_PERSECT+"页", sb);
}else{
insertItem((section-2)*unit,"上"+PAGES_PERSECT+"页", sb);
insertItem((current_page-2)*COUNTS_PERPAGE,"上一页",sb);
for(int i=(section-1)*PAGES_PERSECT+1;i<=section*PAGES_PERSECT;i++)
insertItem(i,sb);
if(current_page<total_page)
insertItem(current_page*COUNTS_PERPAGE,"下一页",sb);
if(section<section_count)
insertItem(section*unit,"下"+PAGES_PERSECT+"页", sb);
}
}
return sb.toString();
}
public void setIndex(int index) {
this.index=index;
}
public void setTotal_count(int total_count) {
this.total_count = total_count;
if(this.index>=total_count) index=total_count-1;
else if(index<=0) index=0;
total_page=total_count/COUNTS_PERPAGE+1;
current_page=(index+1)/COUNTS_PERPAGE+1;
current_page_index=(current_page-1)*COUNTS_PERPAGE;
}
public void setUrl(String url) {
this.url = url;
}
public int getCurrent_page_index() {
return current_page_index;
}
}
Servlet
package cn.burt;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Process extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String startindex=request.getParameter("startindex");
int index=0;
try{
index=Integer.parseInt(startindex);
}catch(NumberFormatException e){
index=0;
}
String forward=show(request,index);
request.getRequestDispatcher(response.encodeUrl(forward)).forward(request,response);
}
private String show(HttpServletRequest request,int index){
Page page=new Page();
page.setUrl("/Page/servlet/Process");
page.setIndex(index);
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;
List list=new ArrayList();
String forward;
try{
conn=Db.getConnection();
pst=conn.prepareStatement("select count(*) from customers");
rs=pst.executeQuery();
rs.next();
page.setTotal_count(rs.getInt(1));
pst=conn.prepareStatement("select * from customers limit ?,?");
pst.setInt(1,page.getCurrent_page_index());
pst.setInt(2,Page.COUNTS_PERPAGE);
rs=pst.executeQuery();
while(rs.next()){
list.add(rs.getString("companyname"));
}
forward="/show.jsp";
}catch(Exception e){
e.printStackTrace();
forward="/fail.jsp";
}finally{
try{rs.close();}catch(Exception e){}
try{pst.close();}catch(Exception e){}
try{conn.close();}catch(Exception e){}
request.setAttribute("content",list);
request.setAttribute("pageinfo",page);
}
return forward;
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
}
show.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<jsp:directive.page import="java.util.List"/>
<jsp:directive.page import="cn.burt.Page"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>分页</title>
</head>
<%
List list=(List)request.getAttribute("content");
Page pageinfo=(Page)request.getAttribute("pageinfo");
%>
<body>
<%
for(int i=0;i<list.size();i++){
String item=(String)list.get(i);
out.print(item+"<br>");
}
%>
<br>
<%=pageinfo.getFooter() %>
</body>
</html>
|
2007-06-21 08:24
对于MySQL的备份,最好的方法就是直接备份MySQL数据库的Data目录。下面提供了一个利用WinRAR来对Data目录进行定时备份的方法。
首先当然要把WinRAR安装到计算机上。
将下面的命令写入到一个文本文件里
net stop mysql
del d:\mysql\data /q
c:\progra~1\winrar\winrar a -ag -k -r -s D:\Personal\mysql\mysql.rar C:\Program Files\MySQL\MySQL Server 5.2\data
net start mysql
保存,然后将文本文件的扩展名修改成CMD。
进入控制面版,打开计划任务,双击“添加计划任务”。在计划任务向导中找到刚才的CMD文件,接着为这个任务指定一个运行时间和运行时使用的账号密码就可以了。
|
2007-06-13 15:29
转载注明出处 http://hi.baidu.com/burtcn
如果使用自己定义的swing组件
自己定义的类如果继承自jpanel,jframe,可以尝试"工具--添加到组件面板“中。
http://topic.csdn.net/t/20060719/20/4891661.html
|
2007-06-13 01:53
转载注明出处 http://hi.baidu.com/burtcn
package cn.burt.frame;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class PaintImg extends JPanel {
private Image img;
public PaintImg(Image img){
this.img=img;
//定义图像尺寸
Dimension size=new Dimension(img.getWidth(null),img.getHeight(null));
setMaximumSize(size);
setMinimumSize(size);
setPreferredSize(size);
setLayout(null);
}
public PaintImg(String img){
this(new ImageIcon(img).getImage());
}
protected void paintComponent(Graphics g) {
g.drawImage(img,0,0,null);
}
}
package cn.burt.frame;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainFrame extends JFrame implements ActionListener {
private final static String PAN1="panel1";
private final static String PAN2="panel2";
private JPanel combopanel;
private JComboBox controlbox;
private JPanel boxpanel;
private JPanel panel1;
private PaintImg img;
private JPanel panel2;
public MainFrame() throws MalformedURLException{
combopanel=new JPanel();
String[] comboitems={PAN1,PAN2};
controlbox=new JComboBox(comboitems);
controlbox.addActionListener(this);
combopanel.add(controlbox,BorderLayout.CENTER);
boxpanel=new JPanel();
CardLayout card=new CardLayout();
boxpanel.setLayout(card);
panel1=new JPanel();
//JLabel label1=new JLabel("This is a Test...panel1");
//panel1.add(label1,BorderLayout.CENTER);
img=new PaintImg("beauty.jpg");
panel1.add(img,BorderLayout.CENTER);
panel2=new JPanel();
JLabel label2=new JLabel("Another test!");
panel2.add(label2,BorderLayout.CENTER);
boxpanel.add(panel1,PAN1);
boxpanel.add(panel2,PAN2);
Container container=this.getContentPane();
container.add(combopanel,BorderLayout.NORTH);
container.add(boxpanel,BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) throws MalformedURLException {
MainFrame m=new MainFrame();
}
public void actionPerformed(ActionEvent e) {
CardLayout c=(CardLayout)boxpanel.getLayout();
String s=(String)controlbox.getSelectedItem();
c.show(boxpanel,s);
}
}
|
2007-06-12 11:02
BoxLayout
public BoxLayout(Container target,int axis)
创建一个将沿给定轴放置组件的布局管理器。
参数:
target - 需要布置的容器
axis - 布置组件时使用的轴。它可以是以下值之一:BoxLayout.X_AXIS、BoxLayout.Y_AXIS、BoxLayout.LINE_AXIS 或 BoxLayout.PAGE_AXIS
GridLayout
public GridLayout(int rows,int cols)
创建具有指定行数和列数的网格布局。给布局中的所有组件分配相等的大小。
rows 和 cols 中的一个可以为零(但不能两者同时为零),这表示可以将任何数目的对象置于行或列中。
参数:
rows - 该 rows 具有表示任意行数的值零。
cols - 该 cols 具有表示任意列数的值零。
BevelBorder
public BevelBorder(int bevelType)
创建具有指定类型的斜面边框,其颜色将从传递给 paintBorder 方法的组件的背景色派生。
参数:
bevelType - 边框斜面类型
|
2007-06-10 01:15
考试暂时告一段落,不过还没有结束,起码能喘息一下了。
所以这些天要经常更新这个博客了。。 |
2007-06-03 11:30
飞阳原创 http://hi.baidu.com/burtcn
无聊中。。。
#include <stdio.h>
#include <string.h>
int issub(char *t,char *s){
int tlen=strlen(t);
int slen=strlen(s);
for(int i=0,j=0;i<slen&&j<tlen;){
if(s[i]==t[j])
i++,j++;
else
j++;
}
return i==slen?1:0;
}
int main(){
char t[100],s[100];
scanf("%s %s",t,s);
if(issub(t,s))
printf("%s是%s的子串!\n",s,t);
else
printf("%s不是%s的子串!\n",s,t);
return 0;
} |
2007-05-26 11:58
原创作品,作者:飞阳。转载请注明出处,谢谢。
http://hi.baidu.com/burtcn
测试数据如下
###########下面行开始
6
a 45
b 13
c 12
d 16
e 9
f 5
###########上面行结束
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Huff{
public:
Huff():lchild(NULL),rchild(NULL),prob(0),name('#'){};
Huff *lchild,*rchild;
int prob;
char name;
};
bool comp(Huff *a,Huff *b){
return a->prob>=b->prob;
}
int height(Huff *root){
if(root==NULL)
return -1;
else
return height(root->lchild)>height(root->rchild)?
height(root->lchild)+1:height(root->rchild)+1;
}
void print(int array[],int k){
for(int i=0;i<k;i++)
cout<<array[i];
cout<<endl;
}
void traverse(Huff *root,int array[],int &k){
if(root->name!='#'){
cout<<root->name<<":";
print(array,k);
}else{
array[k++]=0;
traverse(root->lchild,array,k);
array[k++]=1;
traverse(root->rchild,array,k);
}
array[k]=-1;
k--;
}
int main(){
int count;
cin>>count;
vector<Huff*> heap;
for(int i=0;i<count;i++){
Huff *node=new Huff();
cin>>node->name>>node->prob;
heap.push_back(node);
}
make_heap(heap.begin(),heap.end(),comp);
Huff *first=NULL;
Huff *second=NULL;
Huff *combine=NULL;
while(heap.size()>1){
pop_heap(heap.begin(),heap.end(),comp);
first=heap.back();
heap.pop_back();
pop_heap(heap.begin(),heap.end(),comp);
second=heap.back();
heap.pop_back();
combine=new Huff();
combine->lchild=first;
combine->rchild=second;
combine->prob=first->prob+second->prob;
heap.push_back(combine);
push_heap(heap.begin(),heap.end(),comp);
}
pop_heap(heap.begin(),heap.end(),comp);
combine=heap.back();
heap.pop_back();
int h=height(combine)+1;
int *array=new int[h];
int k=0;
traverse(combine,array,k);
return 0;
} |
2007-05-26 11:56
2007-05-22 16:24
原创作品,作者:飞阳。转载请注明出处,谢谢。
http://hi.baidu.com/burtcn
POJ上不了。。只好去ZOJ做题。。不爽。。
不过,还算是AC了。。哇哈哈
不过看看这道题的做题情况,发现自己算法效率还是很低的。。
http://acm.zju.edu.cn/show_problem.php?pid=1074
#include <stdio.h>
#include <stdlib.h>
int main(){
int count;
scanf("%d",&count);
int len=count*count;
int *matrix=new int[len];
int *temp=new int[count];
int i,j,k,r;
for(i=0;i<len;i++)
scanf("%d",matrix+i);
int maxsum=0;
for(i=0;i<count;i++){
for(j=i;j<count;j++){
int sub=0;
for(k=0;k<count;k++){
temp[k]=0;
for(r=i;r<=j;r++)
temp[k]+=matrix[r*count+k];
sub>0?sub+=temp[k]:sub=temp[k];
if(sub>maxsum) maxsum=sub;
}
}
}
printf("%d\n",maxsum);
return 0;
} |
|
|
burtcn
男
广东 广州
上次登录: 3月27日
加为好友
|