array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(3) "428" ["text"]=> string(77) "Visual Studio 2017 单独启动MSDN帮助(Microsoft Help Viewer)的方法" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(8) "DonetRen" ["tagsname"]=> string(55) "Visual Studio 2017|MSDN帮助|C#程序|.NET|Help Viewer" ["tagsid"]=> string(23) "[401,402,403,"300",404]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400964" ["_id"]=> string(3) "428" } [1]=> array(10) { ["id"]=> string(3) "427" ["text"]=> string(42) "npm -v;报错 cannot find module "wrapp"" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "zzty" ["tagsname"]=> string(50) "node.js|npm|cannot find module "wrapp“|node" ["tagsid"]=> string(19) "[398,"239",399,400]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400760" ["_id"]=> string(3) "427" } [2]=> array(10) { ["id"]=> string(3) "426" ["text"]=> string(54) "说说css中pt、px、em、rem都扮演了什么角色" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(12) "zhengqiaoyin" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400640" ["_id"]=> string(3) "426" } [3]=> array(10) { ["id"]=> string(3) "425" ["text"]=> string(83) "深入学习JS执行--创建执行上下文(变量对象,作用域链,this)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "Ry-yuan" ["tagsname"]=> string(33) "Javascript|Javascript执行过程" ["tagsid"]=> string(13) "["169","191"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511399901" ["_id"]=> string(3) "425" } [4]=> array(10) { ["id"]=> string(3) "424" ["text"]=> string(30) "C# 排序技术研究与对比" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "vveiliang" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(8) ".Net Dev" ["catesid"]=> string(5) "[199]" ["createtime"]=> string(10) "1511399150" ["_id"]=> string(3) "424" } [5]=> array(10) { ["id"]=> string(3) "423" ["text"]=> string(72) "【算法】小白的算法笔记:快速排序算法的编码和优化" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "penghuwan" ["tagsname"]=> string(6) "算法" ["tagsid"]=> string(7) "["344"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511398109" ["_id"]=> string(3) "423" } [6]=> array(10) { ["id"]=> string(3) "422" ["text"]=> string(64) "JavaScript数据可视化编程学习(二)Flotr2,雷达图" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "chengxs" ["tagsname"]=> string(28) "数据可视化|前端学习" ["tagsid"]=> string(9) "[396,397]" ["catesname"]=> string(18) "前端基本知识" ["catesid"]=> string(5) "[198]" ["createtime"]=> string(10) "1511397800" ["_id"]=> string(3) "422" } [7]=> array(10) { ["id"]=> string(3) "421" ["text"]=> string(36) "C#表达式目录树(Expression)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "wwym" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(4) ".NET" ["catesid"]=> string(7) "["119"]" ["createtime"]=> string(10) "1511397474" ["_id"]=> string(3) "421" } [8]=> array(10) { ["id"]=> string(3) "420" ["text"]=> string(47) "数据结构 队列_队列实例:事件处理" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "idreamo" ["tagsname"]=> string(40) "C语言|数据结构|队列|事件处理" ["tagsid"]=> string(23) "["246","247","248",395]" ["catesname"]=> string(12) "数据结构" ["catesid"]=> string(7) "["133"]" ["createtime"]=> string(10) "1511397279" ["_id"]=> string(3) "420" } [9]=> array(10) { ["id"]=> string(3) "419" ["text"]=> string(47) "久等了,博客园官方Android客户端发布" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(3) "cmt" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511396549" ["_id"]=> string(3) "419" } } ["count"]=> int(200) } 222 Java之图形程序设计 - 爱码网
fr-ruiyang

AWT、Swing、JavaFX

Java起初包含一个用于基本GUI程序设计的类库AWT(Abstract Window Toolkit)

后来基于AWT架构上创建了Swing类库,仅仅提供能力更加强大的用户界面控件。

比如,Button,Frame等类属于AWT组件,Swing组件由AWT组件扩展而来,以J开头

在不久的将来,JavaFX可能会取代Swing。

框架

创建框架

 1 package simpleFrame;
 2 
 3 import java.awt.*;
 4 import javax.swing.*;
 5 
 6 /**
 7  * @version 1.32 2007-06-12
 8  * @author Cay Horstmann
 9  */
10 public class SimpleFrameTest
11 {
12    public static void main(String[] args)
13    {
14       EventQueue.invokeLater(new Runnable()
15          {
16             public void run()
17             {
18                SimpleFrame frame = new SimpleFrame();
19                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20                frame.setVisible(true);
21             }
22          });
23    }
24 }
25 
26 class SimpleFrame extends JFrame
27 {
28    private static final int DEFAULT_WIDTH = 300;
29    private static final int DEFAULT_HEIGHT = 200;
30 
31    public SimpleFrame()
32    {
33       setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
34    }
35 }
View Code

 框架定位

 1 package sizedFrame;
 2 
 3 import java.awt.*;
 4 import javax.swing.*;
 5 
 6 /**
 7  * @version 1.32 2007-04-14
 8  * @author Cay Horstmann
 9  */
10 public class SizedFrameTest
11 {
12    public static void main(String[] args)
13    {
14       EventQueue.invokeLater(new Runnable()
15          {
16             public void run()
17             {
18                JFrame frame = new SizedFrame();
19                frame.setTitle("SizedFrame");
20                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21                frame.setVisible(true);
22             }
23          });
24    }
25 }
26 
27 class SizedFrame extends JFrame
28 {
29    public SizedFrame()
30    {
31       // get screen dimensions
32 
33       Toolkit kit = Toolkit.getDefaultToolkit();
34       Dimension screenSize = kit.getScreenSize();
35       int screenHeight = screenSize.height;
36       int screenWidth = screenSize.width;
37 
38       // set frame width, height and let platform pick screen location
39 
40       setSize(screenWidth / 2, screenHeight / 2);
41       setLocationByPlatform(true);
42 
43       // set frame icon
44 
45       Image img = new ImageIcon("icon.gif").getImage();
46       setIconImage(img);      
47    }
48 }
View Code

在组件中显示信息

 1 package notHelloWorld;
 2 
 3 import javax.swing.*;
 4 import java.awt.*;
 5 
 6 /**
 7  * @version 1.32 2007-06-12
 8  * @author Cay Horstmann
 9  */
10 public class NotHelloWorld
11 {
12    public static void main(String[] args)
13    {
14       EventQueue.invokeLater(new Runnable()
15          {
16             public void run()
17             {
18                JFrame frame = new NotHelloWorldFrame();
19                frame.setTitle("NotHelloWorld");
20                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21                frame.setVisible(true);
22             }
23          });
24    }
25 }
26 
27 /**
28  * A frame that contains a message panel
29  */
30 class NotHelloWorldFrame extends JFrame
31 {
32    public NotHelloWorldFrame()
33    {
34       add(new NotHelloWorldComponent());
35       pack();
36    }
37 }
38 
39 /**
40  * A component that displays a message.
41  */
42 class NotHelloWorldComponent extends JComponent
43 {
44    public static final int MESSAGE_X = 75;
45    public static final int MESSAGE_Y = 100;
46 
47    private static final int DEFAULT_WIDTH = 300;
48    private static final int DEFAULT_HEIGHT = 200;
49 
50    public void paintComponent(Graphics g)
51    {
52       g.drawString("Not a Hello, World program", MESSAGE_X, MESSAGE_Y);
53    }
54    
55    public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
56 }
View Code

2D图形

 1 package draw;
 2 
 3 import java.awt.*;
 4 import java.awt.geom.*;
 5 import javax.swing.*;
 6 
 7 /**
 8  * @version 1.32 2007-04-14
 9  * @author Cay Horstmann
10  */
11 public class DrawTest
12 {
13    public static void main(String[] args)
14    {
15       EventQueue.invokeLater(new Runnable()
16          {
17             public void run()
18             {
19                JFrame frame = new DrawFrame();
20                frame.setTitle("DrawTest");
21                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22                frame.setVisible(true);
23             }
24          });
25    }
26 }
27 
28 /**
29  * A frame that contains a panel with drawings
30  */
31 class DrawFrame extends JFrame
32 {
33    public DrawFrame()
34    {      
35       add(new DrawComponent());
36       pack();
37    }
38 }
39 
40 /**
41  * A component that displays rectangles and ellipses.
42  */
43 class DrawComponent extends JComponent
44 {
45    private static final int DEFAULT_WIDTH = 400;
46    private static final int DEFAULT_HEIGHT = 400;
47 
48    public void paintComponent(Graphics g)
49    {
50       Graphics2D g2 = (Graphics2D) g;
51 
52       // draw a rectangle
53 
54       double leftX = 100;
55       double topY = 100;
56       double width = 200;
57       double height = 150;
58 
59       Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
60       g2.draw(rect);
61 
62       // draw the enclosed ellipse
63 
64       Ellipse2D ellipse = new Ellipse2D.Double();
65       ellipse.setFrame(rect);
66       g2.draw(ellipse);
67 
68       // draw a diagonal line
69 
70       g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height));
71 
72       // draw a circle with the same center
73 
74       double centerX = rect.getCenterX();
75       double centerY = rect.getCenterY();
76       double radius = 150;
77 
78       Ellipse2D circle = new Ellipse2D.Double();
79       circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
80       g2.draw(circle);
81    }
82    
83    public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
84 }
View Code

使用颜色

 1 package fill;
 2 
 3 import java.awt.*;
 4 import java.awt.geom.*;
 5 import javax.swing.*;
 6 
 7 /**
 8  * @version 1.33 2007-04-14
 9  * @author Cay Horstmann
10  */
11 public class FillTest
12 {
13    public static void main(String[] args)
14    {
15       EventQueue.invokeLater(new Runnable()
16          {
17             public void run()
18             {
19                JFrame frame = new FillFrame();
20                frame.setTitle("FillTest");
21                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22                frame.setVisible(true);
23             }
24          });
25    }
26 }
27 
28 /**
29  * A frame that contains a component with drawings
30  */
31 class FillFrame extends JFrame
32 {
33    public FillFrame()
34    {
35       add(new FillComponent());
36       pack();
37    }
38 }
39 
40 /**
41  * A component that displays filled rectangles and ellipses
42  */
43 class FillComponent extends JComponent
44 {
45    private static final int DEFAULT_WIDTH = 400;
46    private static final int DEFAULT_HEIGHT = 400;
47 
48    public void paintComponent(Graphics g)
49    {
50       Graphics2D g2 = (Graphics2D) g;
51 
52       // draw a rectangle
53 
54       double leftX = 100;
55       double topY = 100;
56       double width = 200;
57       double height = 150;
58 
59       Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
60       g2.setPaint(Color.BLACK);
61       g2.draw(rect);
62       g2.setPaint(Color.RED);
63       g2.fill(rect); // Note that the right and bottom edge are not painted over
64       
65       // draw the enclosed ellipse
66 
67       Ellipse2D ellipse = new Ellipse2D.Double();
68       ellipse.setFrame(rect);
69       g2.setPaint(new Color(0, 128, 128)); // a dull blue-green
70       g2.fill(ellipse);
71    }
72    
73    public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
74 }
View Code

文本使用特殊字体

 1 package font;
 2 
 3 import java.awt.*;
 4 import java.awt.font.*;
 5 import java.awt.geom.*;
 6 import javax.swing.*;
 7 
 8 /**
 9  * @version 1.33 2007-04-14
10  * @author Cay Horstmann
11  */
12 public class FontTest
13 {
14    public static void main(String[] args)
15    {
16       EventQueue.invokeLater(new Runnable()
17          {
18             public void run()
19             {
20                JFrame frame = new FontFrame();
21                frame.setTitle("FontTest");
22                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
23                frame.setVisible(true);
24             }
25          });
26    }
27 }
28 
29 /**
30  * A frame with a text message component
31  */
32 class FontFrame extends JFrame
33 {
34    public FontFrame()
35    {      
36       add(new FontComponent());
37       pack();
38    }
39 }
40 
41 /**
42  * A component that shows a centered message in a box.
43  */
44 class FontComponent extends JComponent
45 {
46    private static final int DEFAULT_WIDTH = 300;
47    private static final int DEFAULT_HEIGHT = 200;
48 
49    public void paintComponent(Graphics g)
50    {
51       Graphics2D g2 = (Graphics2D) g;
52 
53       String message = "Hello, World!";
54 
55       Font f = new Font("Serif", Font.BOLD, 36);
56       g2.setFont(f);
57 
58       // measure the size of the message
59 
60       FontRenderContext context = g2.getFontRenderContext();
61       Rectangle2D bounds = f.getStringBounds(message, context);
62 
63       // set (x,y) = top left corner of text
64 
65       double x = (getWidth() - bounds.getWidth()) / 2;
66       double y = (getHeight() - bounds.getHeight()) / 2;
67 
68       // add ascent to y to reach the baseline
69 
70       double ascent = -bounds.getY();
71       double baseY = y + ascent;
72 
73       // draw the message
74 
75       g2.drawString(message, (int) x, (int) baseY);
76 
77       g2.setPaint(Color.LIGHT_GRAY);
78 
79       // draw the baseline
80 
81       g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));
82 
83       // draw the enclosing rectangle
84 
85       Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
86       g2.draw(rect);
87    }
88    
89    public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
90 }
View Code

字体列表

 1 package listFonts;
 2 
 3 import java.awt.*;
 4 
 5 /**
 6  * @version 1.11 2004-06-05
 7  * @author Cay Horstmann
 8  */
 9 public class ListFonts
10 {
11    public static void main(String[] args)
12    {
13       String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment()
14             .getAvailableFontFamilyNames();
15 
16       for (String fontName : fontNames)
17          System.out.println(fontName);
18    }
19 }
View Code

显示图像

 1 package image;
 2 
 3 import java.awt.*;
 4 import javax.swing.*;
 5 
 6 /**
 7  * @version 1.33 2007-04-14
 8  * @author Cay Horstmann
 9  */
10 public class ImageTest
11 {
12    public static void main(String[] args)
13    {
14       EventQueue.invokeLater(new Runnable()
15          {
16             public void run()
17             {
18                JFrame frame = new ImageFrame();
19                frame.setTitle("ImageTest");
20                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21                frame.setVisible(true);
22             }
23          });
24    }
25 }
26 
27 /**
28  * A frame with an image component
29  */
30 class ImageFrame extends JFrame
31 {
32    public ImageFrame()
33    {
34       add(new ImageComponent());
35       pack();
36    }
37 }
38 
39 /**
40  * A component that displays a tiled image
41  */
42 class ImageComponent extends JComponent
43 {
44    private static final int DEFAULT_WIDTH = 300;
45    private static final int DEFAULT_HEIGHT = 200;
46 
47    private Image image;
48 
49    public ImageComponent()
50    {
51       image = new ImageIcon("blue-ball.gif").getImage();
52    }
53 
54    public void paintComponent(Graphics g)
55    {
56       if (image == null) return;
57 
58       int imageWidth = image.getWidth(this);
59       int imageHeight = image.getHeight(this);
60 
61       // draw the image in the upper-left corner
62 
63       g.drawImage(image, 0, 0, null);
64       // tile the image across the component
65 
66       for (int i = 0; i * imageWidth <= getWidth(); i++)
67          for (int j = 0; j * imageHeight <= getHeight(); j++)
68             if (i + j > 0) 
69                g.copyArea(0, 0, imageWidth, imageHeight, i * imageWidth, j * imageHeight);
70    }
71    
72    public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
73 }
View Code

 

分类:

技术点:

相关文章: