新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

网站计数器java源代码 jsp网站计数器

JAVA编写一个完整的计数器类Count,写出源代码

public class Count{ int countValue; Count(){ countValue=0; } public void increment() { countValue++; } public void decrement() { countValue--; } public void reset() { countValue=0; } public int getCountValue(){ return countValue; } public static void main(String args[]){ Count c = new Count(); c.increment(); System.out.println(c.getCountValue()); c.reset(); System.out.println(c.getCountValue()); } } 运行结果: 1 0

为西林等地区用户提供了全套网页设计制作服务,及西林网站建设行业解决方案。主营业务为成都网站建设、成都网站制作、西林网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

采纳哦

计数器的java代码

看书觉得很容易,真正写代码才发现真不容易,累死。

我也是JAVA初学者(学了不到半年),代码肯定有不合适的地方,凑合看吧,反正功能是完成了,代码如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class TestClock extends JFrame{

/** Creates a new instance of TestClock */

public TestClock() {

JPanel jp=new JPanel();

final JLabel jl=new JLabel("0");

jp.add(jl);

add(jp,BorderLayout.CENTER);

JButton jbStart=new JButton("开始");

jbStart.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JButton j =(JButton)e.getSource();

j.setEnabled(false);

dt=new DamThread(new ClockThread(jl));

dt.start();

}

});

JButton jbPause=new JButton("暂停");

jbPause.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JButton j=(JButton)e.getSource();

String s=(String)e.getActionCommand();

if(s.equals("暂停")){

dt.setStatus(ClockStatus.PAUSE);

j.setText("继续");

}else{

dt.setStatus(ClockStatus.CONTINUE);

j.setText("暂停");

}

}

});

JButton jbZero=new JButton("清零");

jbZero.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

dt.setStatus(ClockStatus.ZERO);

}

});

JButton jbStop=new JButton("停止");

jbStop.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

dt.setStatus(ClockStatus.STOP);

}

});

JPanel jp1=new JPanel();

jp1.add(jbStart);

jp1.add(jbPause);

jp1.add(jbZero);

jp1.add(jbStop);

add(jp1,BorderLayout.SOUTH);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pack();

setLocationRelativeTo(null);

}

public static void main(String[] args) {

TestClock tc=new TestClock();

tc.setVisible(true);

}

DamThread dt;

}

class DamThread extends Thread{

public DamThread(ClockThread c){

this.ct=c;

ct.start();

this.setDaemon(true);

this.STATUS=ClockStatus.START;

}

public void run(){

while(ct.isAlive()){

CheckStatus();

}

}

private void CheckStatus(){

switch(getStatus()){

case PAUSE:

ct.mysuspend();

break;

case ZERO:

ct.seti(0);

ct.label.setText("0");

setStatus(ClockStatus.START);

break;

case STOP:

ct.seti(1001);

break;

case CONTINUE:

ct.myresume();

break;

default:

break;

}

}

public void setStatus(ClockStatus cs){

this.STATUS=cs;

}

public ClockStatus getStatus(){

return STATUS;

}

ClockStatus STATUS;

ClockThread ct;

}

class ClockThread extends Thread{

public ClockThread(JLabel j){

this.label=j;

suspendFlag=false;

}

public void run(){

while(i=1000){

try {

i++;

label.setText(""+i);

synchronized(this){

while(suspendFlag){

wait();

}

}

sleep(100);

} catch (InterruptedException ex) {

ex.printStackTrace();

}

}

}

public void seti(int in){

this.i=in;

}

public void mysuspend()

{

suspendFlag=true;

}

synchronized void myresume()

{

suspendFlag=false;

notify();

}

private boolean suspendFlag;

private int i=0;

JLabel label;

}

enum ClockStatus{

START,PAUSE,ZERO,STOP,CONTINUE

}

网站访问量统计java代码?

public class Counter {

private int count;

// 每访问一次,计数器自加一

public int getCount() {

return ++count;

}

public void setCount(int count) {

this.count = count;

}

}

%-- 定义一个 session 范围内的计数器 记录个人访问信息 --%

jsp:useBean id="personCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="session" /

%-- 定义一个 application 范围内的计数器 记录所有人的访问信息 --%

jsp:useBean id="totalCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="application" /

div align="center"

form action="method.jsp" method="get"

fieldset style='width: 300'

legend计数器/legend

table align="center" width="400"

tr

td width=150 align="right" style="font-weight:bold; "您的访问次数:/td

td

%-- 获取个人的 访问次数 --%

jsp:getProperty name="personCount" property="count" / 次

/td

/tr

tr

td width=150 align="right" style="font-weight:bold; "总共的访问次数:/td

td

%-- 获取所有人的 访问次数 --%

jsp:getProperty name="totalCount" property="count" / 次

/td

/tr

/table

/fieldset

/form

/div

希望你能帮到你


名称栏目:网站计数器java源代码 jsp网站计数器
转载源于:http://www.wjwzjz.com/article/dosgjjc.html
在线咨询
服务热线
服务热线:028-86922220
TOP