java编程中结果的可视化表示

请描述Java的可视化编程并举例.~

作界面很简单,用NetBeans的可视化设计工具拖拉一下就行,剩下就是一些事件响应代码了,设计工具的对应属性里双击就能帮你生成接口。

网上有别人已经写好的一个GraphViz.java类。java可以直接调用这个类实现画图功能,但是使用这个类的前提是你的电脑已经装了GraphViz软件,你可以在http://www.graphviz.org/Gallery.php下载windows版本,装完后,找到dot.exe所在的路径,我电脑上的是D:\Program Files\Graphviz2.30\bin\dot.exe,
将GraphViz.java中的这一路径改成你电脑上的路径,基本上就可以用了。

package Graphoutput;
// GraphViz.java - a simple API to call dot from Java programs
/*$Id$*/
/*
******************************************************************************
* *
* (c) Copyright 2003 Laszlo Szathmary *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public *
* License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program; if not, write to the Free Software Foundation, *
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
******************************************************************************
*/


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;


/**
*
* Purpose: GraphViz Java API
*
*
* Description:
* With this Java class you can simply call dot
* from your Java programs
* Example usage:
*
*
* GraphViz gv = new GraphViz();
* gv.addln(gv.start_graph());
* gv.addln("A -> B;");
* gv.addln("A -> C;");
* gv.addln(gv.end_graph());
* System.out.println(gv.getDotSource());
*
* String type = "gif";
* File out = new File("out." + type); // out.gif in this example
* gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out );
*
*
*
*
*
* @version v0.4, 2011/02/05 (February) -- Patch of Keheliya Gallaba is added. Now you
* can specify the type of the output file: gif, dot, fig, pdf, ps, svg, png, etc.
* @version v0.3, 2010/11/29 (November) -- Windows support + ability
* to read the graph from a text file
* @version v0.2, 2010/07/22 (July) -- bug fix
* @version v0.1, 2003/12/04 (December) -- first release
* @author Laszlo Szathmary (jabba.laci@gmail.com)
*/
public class GraphViz
{
/**
* The dir. where temporary files will be created.
*/
//private static String TEMP_DIR = "/tmp"; // Linux
private static String TEMP_DIR = "c:/temp"; // Windows


/**
* Where is your dot program located? It will be called externally.
*/
// private static String DOT = "/usr/bin/dot"; // Linux
private static String DOT = "D:\\Program Files\\Graphviz2.30\\bin\\dot.exe"; // Windows


/**
* The source of the graph written in dot language.
*/
private StringBuilder graph = new StringBuilder();


/**
* Constructor: creates a new GraphViz object that will contain
* a graph.
*/
public GraphViz() {
}


/**
* Returns the graph's source description in dot language.
* @return Source of the graph in dot language.
*/
public String getDotSource() {
return graph.toString();
}


/**
* Adds a string to the graph's source (without newline).
*/
public void add(String line) {
graph.append(line);
}


/**
* Adds a string to the graph's source (with newline).
*/
public void addln(String line) {
graph.append(line + "
");
}


/**
* Adds a newline to the graph's source.
*/
public void addln() {
graph.append('
');
}


/**
* Returns the graph as an image in binary format.
* @param dot_source Source of the graph to be drawn.
* @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
* @return A byte array containing the image of the graph.
*/
public byte[] getGraph(String dot_source, String type)
{
File dot;
byte[] img_stream = null;

try {
dot = writeDotSourceToFile(dot_source);
if (dot != null)
{
img_stream = get_img_stream(dot, type);
if (dot.delete() == false)
System.err.println("Warning: " + dot.getAbsolutePath() + " could not be deleted!");
return img_stream;
}
return null;
} catch (java.io.IOException ioe) { return null; }
}


/**
* Writes the graph's image in a file.
* @param img A byte array containing the image of the graph.
* @param file Name of the file to where we want to write.
* @return Success: 1, Failure: -1
*/
public int writeGraphToFile(byte[] img, String file)
{
File to = new File(file);
return writeGraphToFile(img, to);
}


/**
* Writes the graph's image in a file.
* @param img A byte array containing the image of the graph.
* @param to A File object to where we want to write.
* @return Success: 1, Failure: -1
*/
public int writeGraphToFile(byte[] img, File to)
{
try {
FileOutputStream fos = new FileOutputStream(to);
fos.write(img);
fos.close();
} catch (java.io.IOException ioe) { ioe.printStackTrace();return -1; }
return 1;
}


/**
* It will call the external dot program, and return the image in
* binary format.
* @param dot Source of the graph (in dot language).
* @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
* @return The image of the graph in .gif format.
*/
private byte[] get_img_stream(File dot, String type)
{
File img;
byte[] img_stream = null;


try {
img = File.createTempFile("graph_", "."+type, new File(GraphViz.TEMP_DIR));
Runtime rt = Runtime.getRuntime();

// patch by Mike Chenault
String[] args = {DOT, "-T"+type, dot.getAbsolutePath(), "-o", img.getAbsolutePath()};
Process p = rt.exec(args);

p.waitFor();


FileInputStream in = new FileInputStream(img.getAbsolutePath());
img_stream = new byte[in.available()];
in.read(img_stream);
// Close it if we need to
if( in != null ) in.close();


if (img.delete() == false)
System.err.println("Warning: " + img.getAbsolutePath() + " could not be deleted!");
}
catch (java.io.IOException ioe) {
System.err.println("Error: in I/O processing of tempfile in dir " + GraphViz.TEMP_DIR+"
");
System.err.println(" or in calling external command");
ioe.printStackTrace();
}
catch (java.lang.InterruptedException ie) {
System.err.println("Error: the execution of the external program was interrupted");
ie.printStackTrace();
}


return img_stream; }
/**
* Writes the source of the graph in a file, and returns the written file
* as a File object.
* @param str Source of the graph (in dot language).
* @return The file (as a File object) that contains the source of the graph.
*/
public File writeDotSourceToFile(String str) throws java.io.IOException
{
File temp;
try {
temp = File.createTempFile("graph_", ".dot.tmp", new File(GraphViz.TEMP_DIR));
FileWriter fout = new FileWriter(temp);
fout.write(str);
fout.close();
}
catch (Exception e) {
System.err.println("Error: I/O error while writing the dot source to temp file!");
return null;
}
return temp;
}


/**
* Returns a string that is used to start a graph.
* @return A string to open a graph.
*/
public String start_graph() {
return "digraph G {" ;
}


/**
* Returns a string that is used to end a graph.
* @return A string to close a graph.
*/
public String end_graph() {
return "}";
}


/**
* Read a DOT graph from a text file.
*
* @param input Input text file containing the DOT graph
* source.
*/
public void readSource(String input)
{
StringBuilder sb = new StringBuilder();

try
{
FileInputStream fis = new FileInputStream(input);
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
dis.close();
}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}

this.graph = sb;
}

} // end of class GraphViz



通过下面这个类调用graphViz.java

import java.io.File;
public class Proba
{
public static void main(String[] args)
{
Proba p = new Proba();
p.start();
// p.start2();
}


/**
* Construct a DOT graph in memory, convert it
* to image and store the image in the file system.
*/
private void start()
{
GraphViz gv = new GraphViz();
gv.addln(gv.start_graph());
gv.addln("A -> B;");
gv.addln("A -> C;");
gv.addln(gv.end_graph());
System.out.println(gv.getDotSource());

String type = "gif";
// String type = "dot";
// String type = "fig"; // open with xfig
// String type = "pdf";
// String type = "ps";
// String type = "svg"; // open with inkscape
// String type = "png";
// String type = "plain";
File out = new File("/tmp/out." + type); // Linux
// File out = new File("c:/eclipse.ws/graphviz-java-api/out." + type); // Windows
gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out );
}

/**
* Read the DOT source from a file,
* convert to image and store the image in the file system.
*/
private void start2()
{
// String dir = "/home/jabba/eclipse2/laszlo.sajat/graphviz-java-api"; // Linux
// String input = dir + "/sample/simple.dot";
String input = "c:/eclipse.ws/graphviz-java-api/sample/simple.dot"; // Windows

GraphViz gv = new GraphViz();
gv.readSource(input);
System.out.println(gv.getDotSource());

String type = "gif";
// String type = "dot";
// String type = "fig"; // open with xfig
// String type = "pdf";
// String type = "ps";
// String type = "svg"; // open with inkscape
// String type = "png";
// String type = "plain";
File out = new File("/tmp/simple." + type); // Linux
// File out = new File("c:/eclipse.ws/graphviz-java-api/tmp/simple." + type); // Windows
gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out );
}
}

可以  javaSwing 编程  给你个例子 

package com.xu.pcchart;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.sql.Date;
import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Clinet extends JFrame implements Runnable, ActionListener
{
    private static final long serialVersionUID = 1L;
    public static final int PORT  = 8521;
    //声明套接字对象
    Socket socket;
    //声明线程对象
    Thread thread1;
    //声明客户端数据输入输出流
    DataInputStream in;
    DataOutputStream out;
    //是否登录的标记
    boolean flag = false;
    
    //声明字符串,name存储用户名,chat_txt存储发送的信息,chat_in存储从服务器接收到的信息
    String name,chat_txt,chat_in;
    String ip = null;
    
    /**
     * 服务器端主程序负责界面以及服务端主线程ServerThread的启动
     * 服务主线程ServerThread又产生BroadCast及ClientThread线程
     */
     //建立服务器端主界面所用到的布局方式
    BorderLayout borderlayout1 = new BorderLayout();
    BorderLayout borderlayout2 = new BorderLayout();
    BorderLayout borderlayout3 = new BorderLayout();
    
    //创建面板
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    //创建按钮
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton("发送");
    JScrollPane jScrollpanel = new JScrollPane();
    
    //创建服务器端接收信息文本框
    static  JTextArea jTextArea1 = new JTextArea();
    boolean bool = false,start = false;
    
    JLabel usernamelable = new JLabel("用户名");
    JTextField usernametext  = new JTextField(10);
    JTextField sendmsgText  = new JTextField(20);
    JLabel lable = new JLabel("服务器地址");
    JTextField addresslable  =new JTextField("192.168.1.198",10);
    
    
    //声明ServerThread线程对象
    ServerThread serverThread;
    Thread thread;
    
    //构造函数 ,生成客户端界面
    public Clinet()
        {
        //设置内容分面板布局方式
            getContentPane().setLayout(borderlayout1);
            //初始化组件
            jButton1.setText("进入聊天室");
            jButton1.addActionListener(this);
            jButton2.setText("退出聊天室");
            jButton2.addActionListener(this);
            jButton3.addActionListener(this);
            
            //初始化JPanel1面板对象,并向其加入组件
            this.getContentPane().add(jPanel1,java.awt.BorderLayout.NORTH);
            jPanel1.add(usernamelable);
            jPanel1.add(usernametext);
            jPanel1.add(jButton1);
            jPanel1.add(jButton2);
            
            //初始化jpanel2面板对象,并向其加入组件
            jTextArea1.setText("");
            jPanel2.setLayout(borderlayout2);
            
            jPanel2.add(jScrollpanel,java.awt.BorderLayout.CENTER);
            jScrollpanel.getViewport().add(jTextArea1);
            this.getContentPane().add(jPanel2,java.awt.BorderLayout.CENTER);
            jPanel4.add(lable);
            jPanel4.add(addresslable);
            getContentPane().add(jPanel4,java.awt.BorderLayout.EAST);
            
            getContentPane().add(jPanel3,java.awt.BorderLayout.SOUTH);
            jPanel3.add(sendmsgText);
            jPanel3.add(jButton3);
            this.setSize(400,400);
            this.setVisible(true);
        }        
    public static void main(String[] args)
    {
        Clinet server = new Clinet ();
         server.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    //界面按钮的事件处理
    @Override
    public void actionPerformed(ActionEvent e)
    {
        //进入聊天室的按钮处理
        if(e.getSource() == jButton1)
        {
            //获取用户名
            name = usernametext.getText();
            //获取服务器IP
            ip = addresslable.getText();
            //判断用户名是否有效及ip是否为空
            if(name!="用户名输入"&&ip != null)
            {
                try
                {
                    //创建socket对象
                    socket = new Socket(ip,PORT);
                    //创建客户端数据输入输出流,用于对服务器端发送或接收数据
                    in = new DataInputStream(socket.getInputStream());
                    out = new DataOutputStream(socket.getOutputStream());
                    Date now = new Date(System.currentTimeMillis());
                    SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
                    String nowStr = format.format(now);
                    out.writeUTF("$$"+name+" "+nowStr+" 上线了!");
                } catch (Exception e2)
                {
                    e2.printStackTrace();
                }
                thread = new Thread(this);
                //开启线程,监听服务器端是否有消息
                thread.start();
                //说明已经登录成功
                flag = true;
            }
        }
        //发送按钮的处理
        else if(e.getSource() == jButton3)
        {
            //获取客户端输入的发言内容
            chat_txt = sendmsgText.getText();
            if(chat_txt != null)
            {
                Date now = new Date(System.currentTimeMillis());
                SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
                String nowStr = format.format(now);
                //发言 向服务器发送发言的信息
                try
                {
                    out.writeUTF("^-^"+usernametext.getText()+" "+nowStr+" 说
"+chat_txt);
                } catch (Exception e2)
                {
                    // TODO: handle exception
                }
            }
            else
            {
                try
                {
                    out.writeUTF("亲说话");;
                } catch (Exception e2)
                {
                    // TODO: handle exception
                }
            }
        }
        //退出聊天室按钮事件处理
        else if(e.getSource() == jButton2)
        {
            if(flag == true)
            {
                try
                {
                    out.writeUTF("##"+name+"下线了!");
                    
                    out.close();
                    in.close();
                    socket.close();
                    
                } catch (Exception e2)
                {
                    // TODO: handle exception
                }
            }
            flag = false;
            this.setVisible(false);
        }
    }
    //客户端线程启动后的动作
    @Override
    public void run()
    {
        //循环执行 作用是一直监听服务器端是否有消息
        while(true)
        {
            try
            {
                //读取服务器发送来的数据
                chat_in = in.readUTF();
                //将消息显示在客户端的对话窗口中
                jTextArea1.append(chat_in+"

");
            } catch (Exception e)
            {
                // TODO: handle exception
            }
            
        }
    }
    
    
}

运行结果

具体介绍请看java的   JDK 文档



插件不清楚.
不过你可以尝试把数据设置到Jquery中的Jtree中.

java编程中结果的可视化表示
答:可以 javaSwing 编程 给你个例子 package com.xu.pcchart;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.DataInputStream;import java.io.DataOutputStream;import java.net.Socket;import java.sql.Date;import java.text.Simpl...

用java如何将查询的结果在table中显示
答:利用Java开发数据库应用系统时,经常需要在用户界面上显示查询结果。由于SUN公司提供的JDK1.x开发工具包不是可视化的集成开发环境(IDE),不能象Delphi、VB那样方便地把查询结果在DBGrid等表格中显示出来。因此,只能靠自己编写代码来实现。在实际应用中,我们可以利用Vector、JTable、AbstractTableModel等三个...

java echarts
答:ECharts是一款基于JavaScript的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表,ECharts提供了常规的折线图、柱状图、散点图、饼图、K线图。echarts的特点有哪些?1、ECharts 属于开源软件,并且为我们提供了非常炫酷的图形界面,特色是地图,另外还提供了柱状图、折线图、饼图、气...

java做报表
答:把数据库中需要的数据处理后做成可视化图表,根据不同需求可以做成不同形式的图表,节省时间,效果比较好,报表软件国外的话水晶报表,SAP公司的商业报表工具,作为SAP“集团”下的报表组件模块。10年事前盛行一时,后被SAP收购。但水晶报表(Crystal Report)在理论上只支持单数据集,对多集的支持依赖于数...

目前大家在java开发中使用什么报表工具
答:1、Jasperreport:最常用的报表工具,常和Ireport搭配使用。可以在java环境下制作报表,支持PDF、XLS、HTML、CSV、XLM文件输出格式。2、Irepoer:允许用户可视化编辑包含charts,图片,子报表等的复杂报表,还集成了TFreechart图表制作包。3、BIRT:由数据连接,数据转换,业务逻辑设计,表现四个组成逻辑构成...

常见的数据分析可视化图表有哪些?
答:饼状图和柱状图在应用上有一定的重合。饼状图的应用重点在于发现单体因素在整体因素中的占比,但如果用多个单体因素做饼状图,可能导致数据特征不明显。④散点图:用于二维数据的比较。散点图可以用于三维数据的表现,也可以用于二维数据的比较。一般我们将数据大的维度作为纵轴,更有利于展示结果。⑤气泡...

支持Java的报表工具都有哪些?
答:报表工具靠不靠谱,来试试Smartbi,思迈特软件Smartbi经过多年持续自主研发,凝聚大量商业智能最佳实践经验,整合了各行业的数据分析和决策支持的功能需求。满足最终用户在企业级报表、数据可视化分析、自助探索分析、数据挖掘建模、AI智能分析等大数据分析需求。思迈特软件Smartbi个人用户全功能模块长期免费试用马上...

Java中JTble表格中的数据如何逐行显示?
答:import java.awt.event.*;import java.awt.*;import javax.swing.table.*;public class Test extends JFrame implements ActionListener { private JButton button1;private JButton button2;private JButton button3;private DefaultTableModel model;private JTable table;private JProgressBar bar;private ...

(java编程) 输入一个数字,则输出其加法表 比如输入5,则输出 0+5=5 1...
答:public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner (System.in);System.out.print("请输入一个值:");int j = sc.nextInt();System.out.println("根据这个值可以输出以下加法表:");for(int i = 0;i<=j;i++) { System.out....

eclipse怎么做java的可视化编程?
答:在eclipse中安装插件,比如window Builder就可以变成可视化的。一.找到对应版本的windowbuilder 打开这个链接:http://www.eclipse.org/windowbuilder/download.php 如下图,显示eclipse的版本号和对应的插件链接 eclipse的版本号可以在eclipse的help中查看,然后复制你对应版本号后面的link连接 二.在eclipse在线...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网