📄 disk.java
字号:
/* * Disk.java * * Created on 2007年10月4日, 下午6:06 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package 汉诺塔;/** * * @author baili */import java.awt.*;import java.awt.geom.*;import java.awt.font.*;import java.awt.image.*;public class Disk extends Button{ int number; boolean 上方有盘=false; Color startColor, endColor; public Disk(int number) { this.number=number; //setBackground(Color.GREEN); startColor=new Color(15*16+5,15*16+5,13*16+12); endColor=new Color(13*16+2,6*16+9,1*16+14); } public boolean get上方有盘() { return 上方有盘; } public void set上方有盘(boolean b) { 上方有盘=b; } public int getNumber() { return number; } public void paint(Graphics g) { fillGradient(this, g, startColor, endColor); } public void fillGradient(Component c, Graphics g, Color start, Color end) { Rectangle bounds = this.getBounds(); // How big is the component? // Get the red, green, and blue components of the start and end // colors as floats between 0.0 and 1.0. Note that the Color class // also works with int values between 0 and 255 float r1 = start.getRed()/255.0f; float g1 = start.getGreen()/255.0f; float b1 = start.getBlue()/255.0f; float r2 = end.getRed()/255.0f; float g2 = end.getGreen()/255.0f; float b2 = end.getBlue()/255.0f; // Figure out how much each component should change at each y value float dr = (r2-r1)/bounds.height; float dg = (g2-g1)/bounds.height; float db = (b2-b1)/bounds.height; // Now loop once for each row of pixels in the component for(int y = 0; y < bounds.height; y++) { g.setColor(new Color(r1, g1, b1)); // Set the color of the row //g2D.setPaint(new GradientPaint(0, 0, Color.BLUE, // bounds.width,bounds.height, Color.MAGENTA, true)); g.drawLine(0,y, bounds.width-1,y); // Draw the row// g2D.fillRect(0, 0,bounds.width, bounds.height); r1 += dr; g1 += dg; b1 += db; // Increment color components }// Graphics2D g2D=(Graphics2D)g;// g2D.setPaint(new GradientPaint(0, 0,new Color(15*16+5,15*16+5,13*16+12), bounds.width,bounds.height,new Color(13*16+2,6*16+9,1*16+14), true)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -