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

源代码在线查看: test.java

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

相关代码

				import java.awt.*;
				import java.awt.event.*;
				import javax.swing.*;
				import javax.swing.event.*;
				
				public class Test extends JApplet {
					Icon icon = new ImageIcon("icon.gif");
					JButton button = new JButton("button");
				
					public Test() {
						Container contentPane = getContentPane();
				
						button.setRolloverIcon(new ImageIcon("punch.gif"));
						button.setIcon(new ImageIcon("open_hand.gif"));
				
						contentPane.setLayout(new FlowLayout());
						contentPane.add(button);
				
						button.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								System.out.println("action!");
							}
						});
						button.addChangeListener(new ChangeListener() {
							public void stateChanged(ChangeEvent e) {
								System.out.println(getButtonState());
							}
						});
					}
					private String getButtonState() {
						ButtonModel model = button.getModel();
						String state = "Button State: "; 
				
						state += model.isSelected() ? "selected" : "deselected";
						state += model.isPressed() ? ", pressed" : 
													 ", not pressed";
						state += model.isArmed() ? ", armed" : ", disarmed";
						state += model.isRollover() ? ", rollover" : 
													  ", not rollover";
				
						return state;
					}
				}
							

相关资源