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

📄 gaascsgtext.java

📁 Java实现的遗传算法工具集:GA Playground
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import com.scs.awt.*;
import com.scs.util.*;


public class GaaScsGText extends ScsGComponent implements ActionListener, KeyListener, java.io.Serializable {

	private TextField tf = new TextField();
	private String savetext=null;
	private int row=-1;
	private int col=-1;

	public GaaScsGText() {
		super();
		setOverlayComponent(true);
		setActionComponent(true);

		setLayout(null);

	  tf.setSize(60,20);
		tf.setFont(new Font("Times New Roman",Font.PLAIN,10));
		tf.addKeyListener(this);
		
		setSize(100,20);
		
		add(tf);
	}
	
	public void actionPerformed(ActionEvent e) {
		doAction();
	}
	
	public void cellSelected(int oldrow, int oldcol, int newrow, int newcol) {
		if ((newrow!=row || newcol!=col) && row>=0) doAction();
	}
	
	private void doAction() {
		if (savetext != tf.getText()) {
			savetext=tf.getText();
			grid.setGridCell(row,col,savetext,false);
		}
	}
	
	public boolean getActionComponent() {
	    return super.isActionComponent();
	}
	
	public Color getTextBackColor() {return tf.getBackground();}
	
	public TextField getTextBox()
	{
		return tf;
	}
	
	public Color getTextColor() {return tf.getForeground();}
	
	public Font getTextFont() {return tf.getFont();}
	
	public void keyPressed(KeyEvent evt) {
		switch(evt.getKeyCode()) {
		case(evt.VK_ENTER):
			doAction();
			//grid.requestFocus();
			//grid.dispatchEvent(new Event(this,AWTEvent.VK_TAB,null));
			break;
		case(evt.VK_TAB):
		case(evt.VK_DOWN):
		case(evt.VK_UP):
			grid.requestFocus();
			grid.dispatchEvent(evt);
			break;
		case(evt.VK_ESCAPE):
			startEdit(row,col);
		}
	}
	
	public void keyReleased(KeyEvent evt) {}
	
	public void keyTyped(KeyEvent evt) {}
	
	public void setActionComponent(boolean a) {
	    super.setActionComponent(a);
	}
	
	public void setBounds(int x, int y, int width, int height)
	{
			
	    if (width > 60) {
	    	super.setBounds(x,y,width,20);
	    	tf.setSize(width,20);
	    }
	    else {
	    	super.setBounds(x,y,60,20);
				tf.setSize(60,20);
			}
			
			tf.setLocation(0,0);
	}
	
	public void setTextBackColor(Color c) {tf.setBackground(c);}

	public void setTextColor(Color c) {tf.setForeground(c);}

	public void setTextFont(Font f) {tf.setFont(f);}
	
	public void startEdit(int row, int col) {
		this.row=row;
		this.col=col;
		savetext=grid.getGridCell(row,col);
		if (savetext!=null) {
			try {
				savetext = GaaMisc.gaaFormat.format(Double.valueOf(savetext));
			}catch (Exception e) {
			}
			tf.setText(savetext);
		}
		else tf.setText(new String());
		tf.requestFocus();
		tf.selectAll();
	}
}

⌨️ 快捷键说明

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