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

📄 selectbuttontest.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/*
 * @(#)JSelectButton.java	1.59 03/12/19
 *
 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package flow.graph.test;

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.DefaultButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.accessibility.*;

import flow.graph.gui.tools.ButtonBorderFactory;
import flow.graph.gui.tools.JButtonGroup;
import flow.graph.gui.tools.SelectButton;

import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;


/**
 * An implementation of a two-state button.  
 * The <code>JRadioButton</code> and <code>JCheckBox</code> classes
 * are subclasses of this class.
 * For information on using them see
 * <a
 href="http://java.sun.com/docs/books/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>,
 * a section in <em>The Java Tutorial</em>.
 * <p>
 * <strong>Warning:</strong>
 * Serialized objects of this class will not be compatible with
 * future Swing releases. The current serialization support is
 * appropriate for short term storage or RMI between applications running
 * the same version of Swing.  As of 1.4, support for long term storage
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
 * has been added to the <code>java.beans</code> package.
 * Please see {@link java.beans.XMLEncoder}.
 *
 * @beaninfo
 *   attribute: isContainer false
 * description: An implementation of a two-state button.
 * 
 * @see JRadioButton
 * @see JCheckBox
 * @version 1.59 12/19/03
 * @author Jeff Dinkins
 */
public class SelectButtonTest{
	public SelectButton b1, b2, b3,b4,b5;
	public 	JButtonGroup gb;
	public SelectButtonTest(){
		gb = new JButtonGroup();
		b1 = new SelectButton("b1"){
			public void actionPerformed(){
				System.out.println("b1 actionPerformed...");
			}
		};
		b1.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.out.println("b1");
				gb.setSelected(b1.getModel(), false);
			}
			
		});
		b2 = new SelectButton("b2"){
			public void actionPerformed(){
				System.out.println("b2 actionPerformed...");
			}
		};
		b2.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				gb.setSelected(b2.getModel(), false);
				System.out.println("b2");
			}
			
		});
		b3 = new SelectButton("b3"){
			public void actionPerformed(){
				System.out.println("b3 actionPerformed...");
			}
		};
		b3.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				gb.setSelected(b3.getModel(), false);
				System.out.println("b3");
			}
			
		});
		
		gb.add(b1);
		gb.add(b2);
		gb.add(b3);
	}

	public JToolBar createToolBar(){
		JToolBar tb = new JToolBar();
		tb.setLayout(new FlowLayout(FlowLayout.LEFT));
		tb.add(b1);
		tb.add(b2);
		tb.add(b3);
		//b2.doClick();
		//b2.updateUI();
		return tb;
	}
	
	public JPanel createTextArea(){
		JPanel pane = new JPanel();
		//pane.add(new JTextArea(10, 20));
		pane.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				//System.out.println("click...");
				//System.out.println(gb.getSelected());
				//System.out.println(gb.getSelection());
				//((SelectButton)gb.getSelected()).doClick();
				gb.unSelectedAll();
			}

			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
		return pane;
	}
	
	public static void main(String args[]) {
		JFrame frame = new JFrame();

		SelectButtonTest sb = new SelectButtonTest();
		
		JPanel actionPanel = new JPanel();
		actionPanel.setLayout(new BorderLayout());
		actionPanel.add(sb.createToolBar(), BorderLayout.NORTH);
		actionPanel.add(sb.createTextArea(), BorderLayout.CENTER);

		
		frame.getContentPane().add(actionPanel);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(300, 300);
		frame.show();
	}
}
  

⌨️ 快捷键说明

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