⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opaquetest.java

📁 swing 教程,与大家分享一下,哈哈,希望大家多多指教
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;

public class OpaqueTest extends JApplet {
	public void init() {
		Container contentPane = getContentPane();
		RainPanel rainPanel = new RainPanel();

		ColoredPanel 	opaque = new ColoredPanel(),
						transparent = new ColoredPanel();

		// JComponents are opaque by default, so the opaque
		// property only needs to be set for transparent
		transparent.setOpaque(false);

		rainPanel.add(opaque);
		rainPanel.add(transparent);

		contentPane.add(rainPanel, BorderLayout.CENTER);

		System.out.println(opaque.isOpaque());
		System.out.println(transparent.isOpaque());
	}
}
class RainPanel extends JPanel {
	ImageIcon rain = new ImageIcon("rain.gif");
	private int rainw = rain.getIconWidth();
	private int rainh = rain.getIconHeight();

	public void paintComponent(Graphics g) {
		Dimension size = getSize();

		for(int row=0; row < size.height; row += rainh)
			for(int col=0; col < size.width; col += rainw)
				rain.paintIcon(this,g,col,row);
	}
}
class ColoredPanel extends JPanel {
	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Dimension size = getSize();

		g.setColor(Color.black);
		g.drawRect(0,0,size.width-1,size.height-1);

		g.setColor(Color.red);
		g.fillRect(size.width/2-25,size.height/2-25,50,50);
	}
	public Dimension getPreferredSize() {
		return new Dimension(100,100);
	}
}

⌨️ 快捷键说明

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