Source Code Cross Referenced for GraphDemo.java in  » Science » JSci » examples » GraphDemo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » JSci » examples.GraphDemo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        import java.awt.*;
002:        import java.awt.event.*;
003:        import javax.swing.*;
004:        import JSci.awt.*;
005:        import JSci.swing.*;
006:
007:        /**
008:         * Sample program demonstrating use of the Swing/AWT graph components.
009:         * @author Mark Hale
010:         * @version 1.1
011:         */
012:        public class GraphDemo extends Frame {
013:            private DefaultCategoryGraph2DModel categoryModel;
014:            private DefaultGraph2DModel valueModel;
015:
016:            public static void main(String arg[]) {
017:                new GraphDemo();
018:            }
019:
020:            public GraphDemo() {
021:                super ("JSci Graph Demo");
022:                addWindowListener(new WindowAdapter() {
023:                    public void windowClosing(WindowEvent evt) {
024:                        dispose();
025:                        System.exit(0);
026:                    }
027:                });
028:                setSize(700, 600);
029:                final Font titleFont = new Font("Default", Font.BOLD, 14);
030:                Label title;
031:                // category graphs
032:                categoryModel = createCategoryData();
033:                // bar graph
034:                JBarGraph barGraph = new JBarGraph(categoryModel);
035:                final Panel barGraphPanel = new Panel(new JGraphLayout());
036:                title = new Label("Bar graph", Label.CENTER);
037:                title.setFont(titleFont);
038:                barGraphPanel.add(title, JGraphLayout.TITLE);
039:                barGraphPanel.add(barGraph, JGraphLayout.GRAPH);
040:                barGraphPanel.add(new Label("y-axis", Label.RIGHT),
041:                        JGraphLayout.Y_AXIS);
042:                barGraphPanel.add(new Label("Category axis", Label.CENTER),
043:                        JGraphLayout.X_AXIS);
044:                // pie chart
045:                JPieChart pieChart = new JPieChart(categoryModel);
046:                final Panel pieChartPanel = new Panel(new GraphLayout());
047:                title = new Label("Pie chart", Label.CENTER);
048:                title.setFont(titleFont);
049:                pieChartPanel.add(title, GraphLayout.TITLE);
050:                pieChartPanel.add(pieChart, GraphLayout.GRAPH);
051:                // value graphs
052:                valueModel = createValueData();
053:                // line graph
054:                JLineGraph lineGraph = new JLineGraph(valueModel);
055:                lineGraph.setGridLines(true);
056:                lineGraph.setMarker(new Graph2D.DataMarker.Circle(5));
057:                final Panel lineGraphPanel = new Panel(new JGraphLayout());
058:                title = new Label("Line graph", Label.CENTER);
059:                title.setFont(titleFont);
060:                lineGraphPanel.add(title, JGraphLayout.TITLE);
061:                lineGraphPanel.add(lineGraph, JGraphLayout.GRAPH);
062:                Choice choice = new Choice();
063:                choice.add("Temp.");
064:                choice.add("Rain fall");
065:                choice.addItemListener(new ItemListener() {
066:                    public void itemStateChanged(ItemEvent evt) {
067:                        if (evt.getStateChange() == ItemEvent.SELECTED) {
068:                            if (evt.getItem().toString().equals("Temp.")) {
069:                                valueModel.setSeriesVisible(0, true);
070:                                valueModel.setSeriesVisible(1, false);
071:                            } else if (evt.getItem().toString().equals(
072:                                    "Rain fall")) {
073:                                valueModel.setSeriesVisible(0, false);
074:                                valueModel.setSeriesVisible(1, true);
075:                            }
076:                        }
077:                    }
078:                });
079:                lineGraphPanel.add(choice, JGraphLayout.Y_AXIS);
080:                lineGraphPanel.add(new Label("x-axis", Label.CENTER),
081:                        JGraphLayout.X_AXIS);
082:
083:                // data series tables
084:                final Box tablePanel = new Box(BoxLayout.Y_AXIS);
085:                tablePanel.add(new JLabel("Data series 0", JLabel.CENTER));
086:                tablePanel.add(new JTable(valueModel.getSeries(0)));
087:                tablePanel.add(new JLabel("Data series 1", JLabel.CENTER));
088:                tablePanel.add(new JTable(valueModel.getSeries(1)));
089:                // layout
090:                GridBagLayout gb = new GridBagLayout();
091:                GridBagConstraints gbc = new GridBagConstraints();
092:                setLayout(gb);
093:                gbc.weightx = 0.5;
094:                gbc.weighty = 0.5;
095:                gbc.fill = GridBagConstraints.BOTH;
096:
097:                gbc.gridx = 0;
098:                gbc.gridy = 0;
099:                gb.setConstraints(barGraphPanel, gbc);
100:                add(barGraphPanel);
101:                gbc.gridx = 1;
102:                gbc.gridy = 0;
103:                gb.setConstraints(pieChartPanel, gbc);
104:                add(pieChartPanel);
105:
106:                gbc.fill = GridBagConstraints.HORIZONTAL;
107:                gbc.gridx = 0;
108:                gbc.gridy = 1;
109:                gbc.gridwidth = GridBagConstraints.REMAINDER;
110:                Button updateButton = new Button("Update");
111:                updateButton.addActionListener(new ActionListener() {
112:                    public void actionPerformed(ActionEvent evt) {
113:                        float newData[] = { 3.4f, 5.6f, 6.2f, 3.9f, 1.8f };
114:                        categoryModel.changeSeries(0, newData);
115:                    }
116:                });
117:                gb.setConstraints(updateButton, gbc);
118:                add(updateButton);
119:
120:                gbc.fill = GridBagConstraints.BOTH;
121:                gbc.gridx = 0;
122:                gbc.gridy = 2;
123:                gbc.gridwidth = 1;
124:                gb.setConstraints(lineGraphPanel, gbc);
125:                add(lineGraphPanel);
126:                gbc.gridx = 1;
127:                gbc.gridy = 2;
128:                gbc.gridwidth = GridBagConstraints.REMAINDER;
129:                gb.setConstraints(tablePanel, gbc);
130:                add(tablePanel);
131:                setVisible(true);
132:            }
133:
134:            private static DefaultCategoryGraph2DModel createCategoryData() {
135:                String labels[] = { "Alpha1", "Beta2", "Gamma3", "Delta4",
136:                        "Epsilon5" };
137:                float values1[] = { 2.4f, 7.3f, 3.2f, 0.5f, 2.2f };
138:                float values2[] = { 0.9f, 3.4f, 2.1f, 6.5f, 8.2f };
139:                DefaultCategoryGraph2DModel model = new DefaultCategoryGraph2DModel();
140:                model.setCategories(labels);
141:                model.addSeries(values1);
142:                model.addSeries(values2);
143:                return model;
144:            }
145:
146:            private static DefaultGraph2DModel createValueData() {
147:                float values1[] = { 3.0f, 2.8f, 3.5f, 3.6f, 3.1f, 2.6f };
148:                float values2[] = { 7.8f, 4.1f, 0.9f, 0.2f, 1.3f, 2.5f };
149:                DefaultGraph2DModel model = new DefaultGraph2DModel();
150:                model.setXAxis(0.0f, 5.0f, values1.length);
151:                model.addSeries(values1);
152:                model.addSeries(values2);
153:                model.setSeriesVisible(1, false);
154:                return model;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.