⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttondemo.java

📁 主要为一个空间信息管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003 Sun Microsystems, Inc. All  Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * -Redistributions of source code must retain the above copyright *  notice, this list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduct the above copyright *  notice, this list of conditions and the following disclaimer in *  the documentation and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or intended for * use in the design, construction, operation or maintenance of any nuclear * facility. *//* * @(#)ButtonDemo.java	1.10 03/01/23 */package com.sunking.swing;import javax.swing.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.border.*;import javax.swing.colorchooser.*;import javax.swing.filechooser.*;import javax.accessibility.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.util.*;import java.io.*;import java.applet.*;import java.net.*;/** * JButton, JRadioButton, JToggleButton, JCheckBox Demos * * @version 1.10 01/23/03 * @author Jeff Dinkins */public class ButtonDemo extends DemoModule implements ChangeListener {    JTabbedPane tab;    JPanel buttonPanel = new JPanel();    JPanel checkboxPanel = new JPanel();    JPanel radioButtonPanel = new JPanel();    JPanel toggleButtonPanel = new JPanel();    Vector buttons = new Vector();    Vector checkboxes = new Vector();    Vector radiobuttons = new Vector();    Vector togglebuttons = new Vector();    Vector currentControls = buttons;    JButton button;    JCheckBox check;    JRadioButton radio;    JToggleButton toggle;    EmptyBorder border5 = new EmptyBorder(5,5,5,5);    EmptyBorder border10 = new EmptyBorder(10,10,10,10);    ItemListener buttonDisplayListener = null;    ItemListener buttonPadListener = null;    Insets insets0 = new Insets(0,0,0,0);    Insets insets10 = new Insets(10,10,10,10);    /**     * main method allows us to run as a standalone demo.     */    public static void main(String[] args) {	ButtonDemo demo = new ButtonDemo(null);	demo.mainImpl();    }    /**     * ButtonDemo Constructor     */    public ButtonDemo(SwingSet2 swingset) {	// Set the title for this demo, and an icon used to represent this	// demo inside the SwingSet2 app.	super(swingset, "ButtonDemo", "toolbar/JButton.gif");	tab = new JTabbedPane();	tab.getModel().addChangeListener(this);	JPanel demo = getDemoPanel();	demo.setLayout(new BoxLayout(demo, BoxLayout.Y_AXIS));	demo.add(tab);	addButtons();	addRadioButtons();	addCheckBoxes();	// addToggleButtons();	currentControls = buttons;    }    public void addButtons() {	tab.addTab(getString("ButtonDemo.buttons"), buttonPanel);	buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));        buttonPanel.setBorder(border5);	JPanel p1 = createVerticalPanel(true);	p1.setAlignmentY(TOP_ALIGNMENT);	buttonPanel.add(p1);	// Text Buttons	JPanel p2 = createHorizontalPanel(false);	p1.add(p2);	p2.setBorder(new CompoundBorder(new TitledBorder(null, getString("ButtonDemo.textbuttons"),							  TitledBorder.LEFT, TitledBorder.TOP), border5));	buttons.add(p2.add(new JButton(getString("ButtonDemo.button1"))));	p2.add(Box.createRigidArea(HGAP10));	buttons.add(p2.add(new JButton(getString("ButtonDemo.button2"))));	p2.add(Box.createRigidArea(HGAP10));	buttons.add(p2.add(new JButton(getString("ButtonDemo.button3"))));	// Image Buttons	p1.add(Box.createRigidArea(VGAP30));	JPanel p3 = createHorizontalPanel(false);	p1.add(p3);	p3.setLayout(new BoxLayout(p3, BoxLayout.X_AXIS));	p3.setBorder(new TitledBorder(null, getString("ButtonDemo.imagebuttons"),					 TitledBorder.LEFT, TitledBorder.TOP));	// home image button	String description = getString("ButtonDemo.phone");	button = new JButton(createImageIcon("buttons/b1.gif", description));	button.setPressedIcon(createImageIcon("buttons/b1p.gif", description));	button.setRolloverIcon(createImageIcon("buttons/b1r.gif", description));	button.setDisabledIcon(createImageIcon("buttons/b1d.gif", description));	button.setMargin(new Insets(0,0,0,0));	p3.add(button);	buttons.add(button);	p3.add(Box.createRigidArea(HGAP10));	// write image button	description = getString("ButtonDemo.write");	button = new JButton(createImageIcon("buttons/b2.gif", description));	button.setPressedIcon(createImageIcon("buttons/b2p.gif", description));	button.setRolloverIcon(createImageIcon("buttons/b2r.gif", description));	button.setDisabledIcon(createImageIcon("buttons/b2d.gif", description));	button.setMargin(new Insets(0,0,0,0));	p3.add(button);	buttons.add(button);	p3.add(Box.createRigidArea(HGAP10));	// write image button	description = getString("ButtonDemo.peace");	button = new JButton(createImageIcon("buttons/b3.gif", description));	button.setPressedIcon(createImageIcon("buttons/b3p.gif", description));	button.setRolloverIcon(createImageIcon("buttons/b3r.gif", description));	button.setDisabledIcon(createImageIcon("buttons/b3d.gif", description));	button.setMargin(new Insets(0,0,0,0));	p3.add(button);	buttons.add(button);	p1.add(Box.createVerticalGlue());	buttonPanel.add(Box.createRigidArea(HGAP10));	currentControls = buttons;	buttonPanel.add(createControls());    }    public void addRadioButtons() {	ButtonGroup group = new ButtonGroup();	tab.addTab(getString("ButtonDemo.radiobuttons"), radioButtonPanel);	radioButtonPanel.setLayout(new BoxLayout(radioButtonPanel, BoxLayout.X_AXIS));        radioButtonPanel.setBorder(border5);	JPanel p1 = createVerticalPanel(true);	p1.setAlignmentY(TOP_ALIGNMENT);	radioButtonPanel.add(p1);	// Text Radio Buttons	JPanel p2 = createHorizontalPanel(false);	p1.add(p2);	p2.setBorder(new CompoundBorder(                      new TitledBorder(			null, getString("ButtonDemo.textradiobuttons"),			TitledBorder.LEFT, TitledBorder.TOP), border5)	);        radio = (JRadioButton)p2.add(                new JRadioButton(getString("ButtonDemo.radio1")));        group.add(radio);	radiobuttons.add(radio);	p2.add(Box.createRigidArea(HGAP10));	radio = (JRadioButton)p2.add(                new JRadioButton(getString("ButtonDemo.radio2")));        group.add(radio);	radiobuttons.add(radio);	p2.add(Box.createRigidArea(HGAP10));	radio = (JRadioButton)p2.add(                new JRadioButton(getString("ButtonDemo.radio3")));        group.add(radio);	radiobuttons.add(radio);	// Image Radio Buttons        group = new ButtonGroup();	p1.add(Box.createRigidArea(VGAP30));	JPanel p3 = createHorizontalPanel(false);	p1.add(p3);	p3.setLayout(new BoxLayout(p3, BoxLayout.X_AXIS));	p3.setBorder(new TitledBorder(null, getString("ButtonDemo.imageradiobuttons"),					 TitledBorder.LEFT, TitledBorder.TOP));	// image radio button 1	String description = getString("ButtonDemo.customradio");	String text = getString("ButtonDemo.radio1");	radio = new JRadioButton(text, createImageIcon("buttons/rb.gif", description));	radio.setPressedIcon(createImageIcon("buttons/rbp.gif", description));	radio.setRolloverIcon(createImageIcon("buttons/rbr.gif", description));	radio.setRolloverSelectedIcon(createImageIcon("buttons/rbrs.gif", description));	radio.setSelectedIcon(createImageIcon("buttons/rbs.gif", description));	radio.setMargin(new Insets(0,0,0,0));	group.add(radio);	p3.add(radio);	radiobuttons.add(radio);	p3.add(Box.createRigidArea(HGAP20));	// image radio button 2	text = getString("ButtonDemo.radio2");	radio = new JRadioButton(text, createImageIcon("buttons/rb.gif", description));	radio.setPressedIcon(createImageIcon("buttons/rbp.gif", description));	radio.setRolloverIcon(createImageIcon("buttons/rbr.gif", description));	radio.setRolloverSelectedIcon(createImageIcon("buttons/rbrs.gif", description));	radio.setSelectedIcon(createImageIcon("buttons/rbs.gif", description));	radio.setMargin(new Insets(0,0,0,0));	group.add(radio);	p3.add(radio);	radiobuttons.add(radio);	p3.add(Box.createRigidArea(HGAP20));	// image radio button 3	text = getString("ButtonDemo.radio3");	radio = new JRadioButton(text, createImageIcon("buttons/rb.gif", description));	radio.setPressedIcon(createImageIcon("buttons/rbp.gif", description));	radio.setRolloverIcon(createImageIcon("buttons/rbr.gif", description));	radio.setRolloverSelectedIcon(createImageIcon("buttons/rbrs.gif", description));	radio.setSelectedIcon(createImageIcon("buttons/rbs.gif", description));	radio.setMargin(new Insets(0,0,0,0));	group.add(radio);	radiobuttons.add(radio);	p3.add(radio);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -