首页 > 后端开发 > 正文

JAVA里编一个程序运行后结果怎么在文本文档中显示?

2024-05-29 06:29:34 | 我爱编程网

小编今天整理了一些JAVA里编一个程序运行后结果怎么在文本文档中显示?相关内容,希望能够帮到大家。

本文目录一览:

JAVA里编一个程序运行后结果怎么在文本文档中显示?

java 怎样让页面动态显示程序的执行情况

你可以在servlet中把你要知道的信息存到session中,ServletActionContext.getRequest().getSession().setAttribute("message", "程序正在组织数据,请稍后。。。。

HttpSession session=ServletActionContext.getRequest().getSession();

@SuppressWarnings("unused")我爱编程网

String str=(String)session.getAttribute("message");

需要知道什么消息酒吧消息项上面那样存储就可以了,然后在jsp中用${message}来取得session中的值,这样就可以动态的显示信息了!

JAVA里编一个程序运行后结果怎么在文本文档中显示?

JAVA里编一个程序运行后结果怎么在文本文档中显示?

你好,很高兴为你解答,以下答案来自问问团队:54666

=======================================================

你可以使用流来将运行结果写进一个文本文档中,请看我的如下的代码:

import java.io.*;

public class IOTest{public static void main(String[] args){PrintStream ps=null;try{FileOutputStream fos=new FileOutputStream("c:\\Test.txt");

JAVA里编一个程序运行后结果怎么在文本文档中显示?

java 如何在图形界面显示程序运行结果

如果只是一些文本要显示,可以在上面加个JTextArea,JTextField之类的组件,用这些组件的对象调用setText("           ")方法(括号里是字符串)来显示文本

比如:

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.HashMap;

import java.util.Map;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

/** 文本区域

*

* @author Administrator

*

*/

public class TextArea extends JFrame {

private static final long serialVersionUID = 2306597749734227012L;

private JButton b1 = new JButton("Add Data"), b2 = new JButton("Clear Data");

private JTextArea text = new JTextArea(20, 40);

private Map map =

new HashMap();

public TextArea() {

// Use up all the data:

map.put("a", "1");

map.put("b", "2");

b1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

for(@SuppressWarnings("rawtypes") Map.Entry me : map.entrySet()){

text.append(me.getKey()+": "+me.getValue()+"\n");

}

}

});

b2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

text.setText("");

}

});

setLayout(new FlowLayout());

add(new JScrollPane(text));

add(b1);

add(b2);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

GUItools.SwingConsole.run(new TextArea(), 475, 475);

}

}

JTextField和这差不多,只不过是显示单行的。

如果要显示其他字体的,可以用HTML格式,如下:

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

/** Swing 组件上的HTML

*

* @author Administrator

*

*/

@SuppressWarnings("serial")

public class HTMLButton extends JFrame {

private JButton b = new JButton(

""+

"

Hello!
Press me now!");

// 必须使文本以 "" 标记开始。

public HTMLButton() {

// TODO Auto-generated constructor stub

b.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

add(new JLabel(""+"Kapow!"));

// Force a re-layout to include the new label:

validate();

}

});

setLayout(new FlowLayout());

add(b);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

GUItools.SwingConsole.run(new HTMLButton(), 200, 500);

}

}

以上就是我爱编程网小编为大家带来的内容了,想要了解更多相关信息,请关注我爱编程网。

免责声明:文章内容来自网络,如有侵权请及时联系删除。
与“JAVA里编一个程序运行后结果怎么在文本文档中显示?”相关推荐