我在win平台上用java做一个服务器程序,有一些信息输出到dos的console上,但是用System.out.print输出信息控制不住,它总是滚动的,我想要在固定的行输出信息,请问是不是有其它什么类库可以用,在console上固定的输出信息???我现在的程序如下,它的信息只能滚动输出,我想固定输出,先谢谢了...我只有那么多分,我已经全给了...public class hjserver
{
public static void main(String args[])
{
resnew t1 = new resnew();
event_move t2 = new event_move();
t1.start();
t2.start();
}
}
class resnew extends Thread
{
public void run()
{
while(true)
{
try {
sleep(2000);
System.out.print("OK1");
}
catch(InterruptedException e)
{
}
}
}
}
class event_move extends Thread
{ public void run()
{
while(true)
{
try {
sleep(2000);
System.out.print("OK2");
}
catch(InterruptedException e)
{
}
}
}
}
{
public static void main(String args[])
{
resnew t1 = new resnew();
event_move t2 = new event_move();
t1.start();
t2.start();
}
}
class resnew extends Thread
{
public void run()
{
while(true)
{
try {
sleep(2000);
System.out.print("OK1");
}
catch(InterruptedException e)
{
}
}
}
}
class event_move extends Thread
{ public void run()
{
while(true)
{
try {
sleep(2000);
System.out.print("OK2");
}
catch(InterruptedException e)
{
}
}
}
}
解决方案 »
- 下载的tomcat没有源代码
- 请问java中如何将整型的hashCode值转化成对应的字符串
- Query queryObject = getSession().createQuery(hql);报空异常
- 急!急!急!判断用户登录问题
- spring 管理struts2.0和hibernate3.0 需要哪些配置文件?
- Service中使用java反射的问题
- JNI中,在C++的控制台打印java异常
- hibernate导入类问题
- 翻译了《Struts in Action》第12章第1节的内容,请大家批评指教,以利于我以后的翻译
- 大家来讨论,精彩有分
- 关于Spring的一些总结
- 如何获取应用服务器的JNDI名称
你没有使用开发工具么?
print本来就是在一行打印的。
程序运行后,它是这样输出的:OK1
OK2
OK1
OK2
OK1
OK2
OK1
OK2
OK1
OK2
OK1
OK2
我想让线程1只在第一行输出,而线程2只在第二行输出.
OK1
OK2
package print;import java.util.HashMap;
import java.util.Map;public class PrintTest2 {
public static void main(String[] args) {
final Map<String, Integer> map = new HashMap<String, Integer>();
final String thname[] = { "Test1", "Test2", "Test3" };
Runnable r1 = new Runnable() { @Override
public void run() {
for (int i = 0; i < 10; i++) {
synchronized (map) {
map.put(thname[0], i);
map.notify();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
synchronized (map) {
map.put(thname[0], 9999);
map.notify();
}
}
};
Runnable r2 = new Runnable() { @Override
public void run() {
for (int i = 0; i < 10; i++) {
synchronized (map) {
map.put(thname[1], i);
map.notify();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
synchronized (map) {
map.put(thname[1], 9999);
map.notify();
}
}
};
Runnable r3 = new Runnable() {
private int t1 = 0;
private int t2 = 0; @Override
public void run() {
boolean flag1 = true;
boolean flag2 = true;
while (flag1 && flag2) {
synchronized (map) {
try {
map.wait();
} catch (InterruptedException e) {
continue;
}
System.out.printf("\r %s %d,%s %d", thname[0], t1,
thname[1], t2);
if (flag1) {
t1 = map.get(thname[0]);
if (t1 == 9999) {
flag1 = false;
}
}
if (flag2) {
t2 = map.get(thname[1]);
if (t2 == 9999) {
flag2 = false;
}
}
}
}
}
};
Thread t1 = new Thread(r1, thname[0]);
Thread t2 = new Thread(r2, thname[1]);
Thread t3 = new Thread(r3, thname[2]);
t1.start();
t2.start();
t3.start();
}
}
只要在输出里一加'\n',就完了,乱了
import java.util.*;
import java.awt.*;
import java.awt.event.*;//import org.hibernate.*;
//import org.hibernate.cfg.*;
import po.*;
public class hjserver
{ public static TextField txt1=new TextField(30);
public static TextField txt2=new TextField(30);
public static TextField txt3=new TextField(30); public static void main(String args[])
{
resnew t1 = new resnew();
event_move t2 = new event_move();
t1.start();
t2.start();
Panel p1=new Panel(); p1.setLayout(new GridLayout(3,1,0,10)); p1.add(txt1);
p1.add(txt2);
p1.add(txt3);
Frame f = new Frame();
f.add(p1);
f.setLayout(new FlowLayout());
f.setSize(400,300);
f.setVisible(true);
}
}
class resnew extends Thread
{
public void run()
{
while(true)
{
try {
sleep(2000);
hjserver.txt1.setText("OK1");
}
catch(InterruptedException e)
{
}
}
}
}
class event_move extends Thread
{ public void run()
{
while(true)
{
try {
sleep(2000);
hjserver.txt2.setText("OK2");
}
catch(InterruptedException e)
{
}
}
}
}