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

📄 butterflyframe.java

📁 生物物种进化历程的演示
💻 JAVA
字号:
/* * Created on Mar 22, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */package TreeJuxtaposer;//import javax.imageio.ImageIO;//import javax.imageio.ImageReader;import javax.swing.*;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import  java.awt.Image ;import java.io.ByteArrayOutputStream ;import java.io.InputStream ;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;/** * @author jzhang * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */public class ButterflyFrame extends JFrame implements ActionListener { // implements MouseListener, ActionListener{	    private TreeJuxtaposer tj;		JLabel direction;		JLabel split;		JButton LL, RL, RR, UU;        JButton Hor, Ver;				public ButterflyFrame(TreeJuxtaposer tj)		{			super("Windows");			this.tj = tj;			//this.title = title;				initComponents();			setButtonStatus(1);			Hor.setEnabled(false);		} 		public void initComponents()        {			Insets inset = new Insets(0, 0, 0, 0);	        this.getContentPane().setLayout(new BorderLayout());			GridBagConstraints gbc = new GridBagConstraints();			JPanel jp = new JPanel();			jp.setLayout(new GridBagLayout());				gbc = new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,					GridBagConstraints.WEST, GridBagConstraints.BOTH,					inset, 5, 5);			direction = new JLabel("Direction");			jp.add(direction, gbc);						gbc = new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE,					inset, 5, 5);			split = new JLabel("Split");			jp.add(split, gbc);				LL = new JButton("Left ");			LL.addActionListener(this);			gbc = new GridBagConstraints(3, 0, 1, 1, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE, inset, 5, 5);			jp.add(LL, gbc);				RR = new JButton("Right");			RR.addActionListener(this);			gbc = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE, inset, 5, 5);			jp.add(RR, gbc);				RL = new JButton("Right/Left");			RL.addActionListener(this);			gbc = new GridBagConstraints(5, 0, 1, 1, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE, inset, 5, 5);			jp.add(RL, gbc);				UU = new JButton("Up");			UU.addActionListener(this);				gbc = new GridBagConstraints(6, 0, 1, 1, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE, inset, 5, 5);			jp.add(UU, gbc);				Hor = new JButton("Horizontal");			Hor.addActionListener(this);			gbc = new GridBagConstraints(3, 1, 2, 3, 1.0, 1.0,					GridBagConstraints.CENTER, GridBagConstraints.NONE,					inset, 5, 5);			jp.add(Hor, gbc);				Ver = new JButton("Vertical");			Ver.addActionListener(this);			gbc = new GridBagConstraints(4, 1, GridBagConstraints.REMAINDER, 3,					1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,					inset, 5, 5);			jp.add(Ver, gbc);				this.getContentPane().add(jp, BorderLayout.CENTER);				this.setResizable(false);			this.setSize(500, 110);        }                Image getImage(String file)        {			InputStream is;			ByteArrayOutputStream baos ;			Image image;			is = this .getClass().getResourceAsStream (file );//						if ( is == null ) throw new IOException ( "images/LL.png" + " not found" );			baos = new ByteArrayOutputStream();			int c;			try{				while ( ( c = is.read() ) >= 0 )				{					baos.write(c );				}            			}catch(Exception e)			{					System.out.println("Error: " + e.toString());			        return null;			}						image = getToolkit ().createImage( baos.toByteArray() );			return image;        }                public JButton[] getButtons()        {        	JButton[] buttons = new JButton[4];        	buttons[0] = LL;        	buttons[1] = RR;        	buttons[2] = RL;        	buttons[3] = UU;        	//buttons[4] = DD;        	return buttons;        }                public void setButtonStatus(int index)        {        	JButton[] buttons = getButtons();        	for(int i=0; i<buttons.length; i++)        	{        		if(i == index)        		buttons[i].setEnabled(false);        		else        		buttons[i].setEnabled(true);        	}        	        	        }		/* (non-Javadoc)		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)		 */		public void actionPerformed(ActionEvent e) {			// TODO Auto-generated method stub			Object obj = e.getSource();			if (obj instanceof JButton)			{				if (obj == LL)				{					setButtonStatus(0);//					tj.drawLL();					}				else if (obj == RR)				{				    setButtonStatus(1);//				    tj.drawRR();				}				else if (obj == RL)				{					setButtonStatus(2);//				   	tj.drawRL();				}				else if (obj == UU)				{						setButtonStatus(3);//				   	tj.drawUU();				}				else if (obj == Ver)				{						Hor.setEnabled(true);				   	Ver.setEnabled(false);//				   	tj.setVerticalDirection();				}				else if (obj == Hor)				{						Ver.setEnabled(true);				   	Hor.setEnabled(false);//				   	tj.setHorizontalDirection();				}			}					}        //}

⌨️ 快捷键说明

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