《Java2图形设计卷II:Swing》配套光盘源码

源代码在线查看: test.java

软件大小: 4504 K
上传用户: guigong
关键词: Java2 Swing 图形 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				import java.awt.event.*;
				import javax.swing.*;
				
				public class Test extends JApplet {
					public void init() {
						Container contentPane = new CustomContentPane();
						JLabel view1 = new JLabel(
											new ImageIcon("gjMedium.gif"));
						JLabel view2 = new JLabel(
											new ImageIcon("anjinAndMariko.gif"));
				
						JScrollPane sp1 = new JScrollPane(view1);
						JScrollPane sp2 = new JScrollPane(view2);
				
						setContentPane(contentPane);
						sp1.setPreferredSize(new Dimension(250,250));
						sp2.setPreferredSize(new Dimension(250,250));
				
						contentPane.add(sp1);
						contentPane.add(sp2);
					}
				}
				class CustomContentPane extends JPanel { 
					private ImageIcon rain = new ImageIcon("rain.gif");
				
					public CustomContentPane() {
						setLayout(new FlowLayout());
					}	
					public void paintComponent(Graphics g) {
						int rainw = rain.getIconWidth();
						int rainh = rain.getIconHeight();
				
						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);
					}
				}
							

相关资源