重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
策略模式,单例模式,装饰模式,简单工厂模式这几种模式个人感觉在实际开发过程中用的比较多,开发的多了对模式的概念反而会渐渐模糊
网站设计制作、网站制作介绍好的网站是理念、设计和技术的结合。成都创新互联拥有的网站设计理念、多方位的设计风格、经验丰富的设计团队。提供PC端+手机端网站建设,用营销思维进行网站设计、采用先进技术开源代码、注重用户体验与SEO基础,将技术与创意整合到网站之中,以契合客户的方式做到创意性的视觉化效果。
在这里面找到快捷键方式,Window-Preferences-General-Key。输入format找到绑定输入Ctrl+Shift+F。应用一下,应该就可以了,有的版本快捷方式不同而已。
对于代码结构上,看起来漂亮起作用的模式,常用的策略模式,工厂模式,装饰模式和观察者模式吧。但也看情景,生搬硬套会显得不够简洁的
唉,给你看看小Case的,自己运行一下
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TranslucentButton extends JButton {
BufferedImage buttonImage = null;
/** Creates a new instance of TranslucentButton */
public TranslucentButton(String label) {
super(label);
setOpaque(false);
}
public void paint(Graphics g) {
// Create an image for the button graphics if necessary
if (buttonImage == null || buttonImage.getWidth() != getWidth() ||
buttonImage.getHeight() != getHeight()) {
buttonImage = getGraphicsConfiguration().
createCompatibleImage(getWidth(), getHeight());//返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage
}
Graphics gButton = buttonImage.getGraphics();
gButton.setClip(g.getClip());//设置获取的当前的剪贴区域
// Have the superclass render the button for us
super.paint(gButton);
// Make the graphics object sent to this paint() method translucent
Graphics2D g2d = (Graphics2D)g;
AlphaComposite newComposite =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
g2d.setComposite(newComposite);
// Copy the button's image to the destination graphics, translucently
g2d.drawImage(buttonImage, 0, 0, null);
}
private static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 300);
JPanel checkerboard = new Checkerboard();
checkerboard.add(new TranslucentButton("Translucent Button"));
f.add(checkerboard);
f.setVisible(true);
}
public static void main(String args[]) {
Runnable doCreateAndShowGUI = new Runnable() {
public void run() {
createAndShowGUI();
}
};
SwingUtilities.invokeLater(doCreateAndShowGUI);//swing线程
}
private static class Checkerboard extends JPanel {
static final int CHECKER_SIZE = 60;
public void paintComponent(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
for (int stripeX = 0; stripeX getWidth(); stripeX += CHECKER_SIZE) {
for (int y = 0, row = 0; y getHeight(); y += CHECKER_SIZE/2, ++row) {
int x = (row % 2 == 0) ? stripeX : (stripeX + CHECKER_SIZE/2);
g.fillRect(x, y, CHECKER_SIZE/2, CHECKER_SIZE/2);
}
}
}
}
}