colorpanel.java

来自「color panel is a simple tool to help you」· Java 代码 · 共 45 行

JAVA
45
字号
package herbTool;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.geom.*;
public class colorPanel extends JPanel
    {
        private Color sc;
        private Color ec;
        private int xax;
        private int yax;
        public colorPanel(Color s,Color e, int x, int y)
        {
            sc = s;
            ec = e;
            xax = x;
            yax = y;
        }
        public void paintComponent(Graphics g)
        {
            Graphics2D g2 = (Graphics2D) g;
            drawShapes(g2);
        }
        public void drawShapes(Graphics2D g2)
        {
            int gridWidth = 400;
            int gridHeight = 300 / 2;
         
            int rowspacing = 5;
            int columnspacing = 7;
            int rectWidth = gridWidth - columnspacing;
            int rectHeight = gridHeight - rowspacing;
            int x = 0;
            int y = 0;
            // fill RoundRectangle2D.Double
            GradientPaint redtowhite;
            redtowhite = new GradientPaint(x,y,sc,xax,yax,ec);
            g2.setPaint(redtowhite);
            g2.fill(new RoundRectangle2D.Double(x, y, xax,
                                        xax, 10, 10));
            g2.setPaint(Color.black);
            x += gridWidth;
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?