tailieunhanh - Introduction to Programming Using Java Version 6.0 phần 5

(tiêu đề) tạo ra một biên giới với tiêu đề. Tiêu đề là một String, được hiển thị ở góc trên bên trái của biên giới. Có rất nhiều phương pháp khác trong lớp BorderFactory, hầu hết trong số họ cung cấp các biến thể của phong cách biên giới cơ bản được đưa ra ở đây. | CHAPTER 6. INTRODUCTION TO GUI PROGRAMMING 291 similar to a LoweredBevelBorder but the component looks like it is raised above the computer screen. title creates a border with a title. The title is a String which is displayed in the upper left corner of the border. There are many other methods in the BorderFactory class most of them providing variations of the basic border styles given here. The following illustration shows six components with six different border styles. The text in each component is the command that created the border for that component The source code for the applet that produced this picture can be found in . SliderAndComboBoxDemo Now that we have looked at components and layouts it s time to put them together into some complete programs. We start with a simple demo that uses a JLabel a JComboBox and a couple of JSliders all laid out in a GridLayout as shown in this picture The sliders in this applet control the foreground and background color of the label and the combo box controls its font style. Writing this program is a matter of creating the components laying them out and programming listeners to respond to events from the sliders and combo box. In my program I define a subclass of JPanel which will be used for the applet s content pane. This class implements ChangeListener and ActionListener so the panel itself can act as the listener for change events from the sliders and action events from the combo box. In the CHAPTER 6. INTRODUCTION TO GUI PROGRAMMING 292 constructor the four components are created and configured a GridLayout is installed as the layout manager for the panel and the components are added to the panel Create the sliders and set up this panel to listen for ChangeEvents that are generated by the sliders. bgColorSlider new JSlider 0 255 100 this fgColorSlider new JSlider 0 255 200 .