第1章 记忆测试软件 1.1. 设计内容 1.2. 设计要求 1.3. 总体设计 1.4. 具体设计 1.4.1. 运行效果与程序发布 1.4.2. 主类Memory 1.4.3. 方块

源代码在线查看: borderexample.java

软件大小: 1744 K
上传用户: stuoju
关键词: Memory 测试软件 发布 方块
下载地址: 免注册下载 普通下载 VIP

相关代码

				//BorderExample.java
				
				import java.awt.*;
				import java.awt.event.*;
				import javax.swing.*;
				import javax.swing.border.*;
				 
				public class BorderExample
				{
					public static void main(String[] args)
					{  
						BorderFrame frame = new BorderFrame();
						frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						frame.show();
					}
				}
				
				class BorderFrame extends JFrame 
				{  
					public BorderFrame()
					{  
						setTitle("BorderExample");
						setSize(WIDTH, HEIGHT);
				
						Container contentPane = getContentPane();
				
						buttonPanel = new JPanel();
						group = new ButtonGroup();
						
						//添加按钮和事件监视器
						//低斜面边界
						addRadioButton("Lowered bevel", 
							BorderFactory.createLoweredBevelBorder());    
				
						//凸斜面边界
						addRadioButton("Raised bevel", 
							BorderFactory.createRaisedBevelBorder());    
				
						//蚀刻边界
						addRadioButton("Etched", 
							BorderFactory.createEtchedBorder());
				
						//直线边界
						addRadioButton("Line", 
							BorderFactory.createLineBorder(Color.blue));
						
						//不光滑边界
						addRadioButton("Matte",
							BorderFactory.createMatteBorder(5, 5, 5, 5, Color.yellow));
						
						//空边界
						addRadioButton("Empty", 
							BorderFactory.createEmptyBorder());
				
						//初始化带标题的空边界
						Border border = BorderFactory.createEmptyBorder();
						Border titled = BorderFactory.createTitledBorder
							(border, "Border types");
						
						//给面板设置给定的边界
						buttonPanel.setBorder(titled);
				
						contentPane.add(buttonPanel);
					}
				
					public void addRadioButton(String buttonName, final Border b)
					{  
						JRadioButton button = new JRadioButton(buttonName);
						button.addActionListener(new ActionListener()
							{
								public void actionPerformed(ActionEvent event)
								{  
									Border titled = BorderFactory.createTitledBorder
										(b, "Border types");
									buttonPanel.setBorder(titled);
									
									//重新显示
									validate();
								}
							});
				
						group.add(button);
						buttonPanel.add(button);
					}
				
					public static final int WIDTH = 500;
					public static final int HEIGHT = 200;  
				
					private JPanel buttonPanel;
					private ButtonGroup group;
				}			

相关资源