《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 {
					int clickDuration = 68;
				
					public Test() {
						Container contentPane = getContentPane();
						JPanel controlPanel = new JPanel();
						JPanel buttonPanel = new JPanel();
				
						JButton doClick = new JButton("do click");
						final JButton clickMe = new JButton("click me");
				
						final JComboBox comboBox = new JComboBox(new Object[] {
								"68", "250", "500", "750", "1000"
						});
				
						controlPanel.add(new JLabel("Click Duration:"));
						controlPanel.add(comboBox);
				
						buttonPanel.add(doClick);
						buttonPanel.add(clickMe);
				
						contentPane.add(controlPanel, BorderLayout.NORTH);
						contentPane.add(buttonPanel, BorderLayout.CENTER);
				
						getRootPane().setDefaultButton(doClick);
				
						doClick.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								clickMe.doClick(clickDuration);
							}
						});
				
						comboBox.addItemListener(new ItemListener() {
							public void itemStateChanged(ItemEvent e) {
								if(e.getStateChange() == ItemEvent.SELECTED) {
									clickDuration = Integer.parseInt((String)
													comboBox.getSelectedItem());
								}
							}
						});
					}
				}
							

相关资源