java学习经典书籍《core java2》源码

源代码在线查看: bordertest.java

软件大小: 558 K
上传用户: junjie_x
关键词: java2 java core 书籍
下载地址: 免注册下载 普通下载 VIP

相关代码

				/**
				   @version 1.32 2004-05-05
				   @author Cay Horstmann
				*/
				
				import java.awt.*;
				import java.awt.event.*;
				import javax.swing.*;
				import javax.swing.border.*;
				 
				public class BorderTest
				{
				   public static void main(String[] args)
				   {  
				      BorderFrame frame = new BorderFrame();
				      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				      frame.setVisible(true);
				   }
				}
				
				/**
				   A frame with radio buttons to pick a border style. 
				*/
				class BorderFrame extends JFrame 
				{  
				   public BorderFrame()
				   {  
				      setTitle("BorderTest");
				      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
				
				      demoPanel = new JPanel();
				      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(10, 10, 10, 10, Color.BLUE));
				      addRadioButton("Empty", BorderFactory.createEmptyBorder());
				         
				      Border etched = BorderFactory.createEtchedBorder();
				      Border titled = BorderFactory.createTitledBorder(etched, "Border types");
				      buttonPanel.setBorder(titled);
				          
				      setLayout(new GridLayout(2, 1));
				      add(buttonPanel);
				      add(demoPanel);
				   }
				
				   public void addRadioButton(String buttonName, final Border b)
				   {  
				      JRadioButton button = new JRadioButton(buttonName);
				      button.addActionListener(new
				         ActionListener()
				         {
				            public void actionPerformed(ActionEvent event)
				            {  
				               demoPanel.setBorder(b);
				               validate();
				            }
				         });
				      group.add(button);
				      buttonPanel.add(button);
				   }
				
				   public static final int DEFAULT_WIDTH = 600;
				   public static final int DEFAULT_HEIGHT = 200;  
				   
				   private JPanel demoPanel;
				   private JPanel buttonPanel;
				   private ButtonGroup group;
				}
							

相关资源