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

📄 animationcontrollermanager.java

📁 用JAVA实现排序等简单算法的演示
💻 JAVA
字号:
package animationController;

import java.awt.*;
import javax.swing.*;


public class AnimationControllerManager {
	public static AnimationController controller = new AnimationController();
	
	public static void changeValuesByUser(JFrame parent) {
		AnimationControllerChanger changer = new AnimationControllerChanger();
		
		changer.changeValuesByUser(parent);
	}
	
	public static AnimationController createAnimationController() {
		AnimationController localController = new AnimationController();
		localController.animationDelay = controller.animationDelay;
		localController.stepDelay = controller.stepDelay;
		localController.unitMoving = controller.unitMoving;
		return localController;
	}
}

class AnimationControllerChanger {
	private JDialog place;
	private JTextField stepDelayField;
	private JTextField animationDelayField;
	private JTextField unitMovingField;
	
	public void changeValuesByUser(JFrame parent) {
		
		JPanel basicPanel = new JPanel();
		basicPanel.setLayout(new GridLayout(3, 1, 0, 15));
		basicPanel.setBorder(BorderFactory.createTitledBorder(""));
		
		JPanel tempPanel = new JPanel();
		tempPanel.setLayout(new GridLayout(1, 2, 0, 0));
		JLabel promptLabel = new JLabel("Delay times between actions: ", JLabel.LEFT);
		stepDelayField = new JTextField(6);
		stepDelayField.setText(AnimationControllerManager.controller.stepDelay+"");
		promptLabel.setLabelFor(stepDelayField);
		tempPanel.add(promptLabel);
		tempPanel.add(stepDelayField);
		basicPanel.add(tempPanel);
		
		tempPanel = new JPanel();
		tempPanel.setLayout(new GridLayout(1, 2, 0, 0));
		promptLabel = new JLabel("Delay times between animation steps: ", JLabel.LEFT);
		animationDelayField = new JTextField(6);
		animationDelayField.setText(AnimationControllerManager.controller.animationDelay+"");
		promptLabel.setLabelFor(animationDelayField);
		tempPanel.add(promptLabel);
		tempPanel.add(animationDelayField);
		basicPanel.add(tempPanel);
		
		tempPanel = new JPanel();
		tempPanel.setLayout(new GridLayout(1, 2, 0, 0));
		promptLabel = new JLabel("Unit moving pixels in animation: ", JLabel.LEFT);
		unitMovingField = new JTextField(6);
		unitMovingField.setText(AnimationControllerManager.controller.unitMoving+"");
		promptLabel.setLabelFor(unitMovingField);
		tempPanel.add(promptLabel);
		tempPanel.add(unitMovingField);
		basicPanel.add(tempPanel);
		
		// 创建一事件监听器,该监听器监听下述两个按钮上发生的事件
		SimpleListener listener = new SimpleListener();
		JButton okButton = new JButton("Ok");
		okButton.setMnemonic('Y');					// 设置快捷键
		okButton.setActionCommand("ok");			
		okButton.addActionListener(listener);		// 添加事件监听器
		JButton cancelButton = new JButton("Cancel");
		cancelButton.setMnemonic('N');				// 设置快捷键
		cancelButton.setActionCommand("cancel");			
		cancelButton.addActionListener(listener);	// 添加事件监听器
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 40, 0));
		buttonPanel.add(okButton);
		buttonPanel.add(cancelButton);
		
		place = new JDialog(parent, "Set control parameters for animation", true);
		place.setLayout(new BorderLayout());
		place.add(basicPanel, BorderLayout.NORTH);		// 放在左边
		place.add(buttonPanel, BorderLayout.SOUTH);
		
		place.pack();
		place.setLocation((parent.getWidth()-place.getWidth())/2, (parent.getHeight()-place.getHeight())/2);
		place.setVisible(true);
	}

	// 监听按钮的事件
	private class SimpleListener implements java.awt.event.ActionListener {
		// 事件监听程序
		public void actionPerformed(java.awt.event.ActionEvent evt) {
			String command = evt.getActionCommand();
			if (command.equals("ok")) {
				String text = stepDelayField.getText();
				AnimationControllerManager.controller.stepDelay = Integer.valueOf(text);
				text = animationDelayField.getText();
				AnimationControllerManager.controller.animationDelay = Integer.valueOf(text);
				text = unitMovingField.getText();
				AnimationControllerManager.controller.unitMoving = Integer.valueOf(text);
			}
			place.dispose();
		}
	}
}

⌨️ 快捷键说明

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