java,eclipse美化代码格式的快捷键Ctrl+shift+F 重新格式化代码....
【java怎么美化代码呢 javaswing美化】还可以用菜单Source下format,多费1秒钟鼠标,
java全是代码,怎么会做出非常漂亮的画面唉,给你看看小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; stripeXgetWidth(); stripeX += CHECKER_SIZE) {
for (int y = 0, row = 0; ygetHeight(); 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);
}
}
}
}
}
北大青鸟java培训:如何才能写出一手高质量优美的代码?怎么判断代码是否是优质量的代码呢?下面河南电脑培训来简单对代码质量的问题进行一个介绍 。
代码质量所涉及的5个方面,编码标准、代码重复、代码覆盖率、依赖项分析、复杂度分析 。
我们分别来看一下这5方面:编码标准:一般来说,公司都会有一份编码规范 , 类命名、包命名、代码风格之类的都会有所要求 。
代码重复:顾名思义就是重复的代码,如果代码中有大量的重复代码,就要考虑是否将重复的代码提取出来 , 封装成一个公共的方法或者组件 。
代码覆盖率:测试代码能运行到的代码比率 , 代码经过了单元测试了吗?是不是每个方法都进行了测试,代码覆盖率是多少?这关系到代码的功能性和稳定性 。
推荐阅读
- 最真实的卡车模拟游戏,最真实的卡车模拟游戏了3
- 酒店的SAP是什么服务,酒店的sap是什么服务
- 电脑能接什么设备,电脑能接什么设备的网线
- linux移动命令用法 linux移动命令mv
- 微信怎么剪切其他视频号,怎样剪断微信视频
- 毕业设计方案用什么网站,毕业设计方案怎么做
- vb.net窗体自适应的简单介绍
- html5videojs属性,html video属性
- 猪猪游戏下载,猪猪手游下载