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

📄 timeselect.java

📁 Typing fingers Typing programme
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
	
/**	This class allows the user to specify the duration of lesson.
*/

class TimeSelect extends JPanel{
	private ImgPanel up,down;
	public JTextField tf;
	private boolean flag=false;
	public int count=3;
	private int range;
	TimeSelect(String cap,final int range){
		this.range=range;
		setLayout(new GridLayout(2,1));
		JPanel p1=new JPanel(new GridLayout(1,2));
		JPanel p2=new JPanel(new GridLayout(2,1));
		String s=System.getProperty("user.dir");
		p2.add(up=new ImgPanel(new ImageIcon(s+"/Images/Up.gif")));
		p2.add(down=new ImgPanel(new ImageIcon(s+"/Images/Down.gif")));
		up.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent m){
				incCount();
			}
		});
		down.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent m){
				decCount();
			}
		});
		p1.add(tf=new JTextField());
		tf.setText("3");
		tf.addKeyListener(new KeyAdapter(){
			public void keyReleased(KeyEvent k){
				int x=3;
				String s=tf.getText();
				if(s.length()<1) return;
				try{
					
					x=Integer.parseInt(s);
					if(x<1||x>range)
						tf.setText("3");
				}catch(Exception e){tf.setText("3");}
			}
		});
		p1.add(p2);
		add(new DialogLabel(cap));
		add(p1);
	}
	public int getTime(){
		return Integer.parseInt(tf.getText());
	}
	private void incCount(){
		if(count<range){
			count++;
			tf.setText(""+count);
		}
	}
	private void decCount(){
		if(count>1){
			count--;
			tf.setText(""+count);
		}
	}
}
class ImgPanel extends JPanel{
	private ImageIcon icon;
	ImgPanel(ImageIcon icon){
		this.icon=icon;
		int w=icon.getIconWidth();
		int h=icon.getIconHeight();
		setPreferredSize(new Dimension(w+6,h+6));
		setBorder(new TitledBorder(new EtchedBorder()));
		addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent m){
				setBorder(new TitledBorder(new EtchedBorder(getBackground(),Color.white)));
			}
			public void mouseReleased(MouseEvent m){
				setBorder(new TitledBorder(new EtchedBorder()));
			}
		});
	}
	public void paint(Graphics g){
		super.paint(g);
		icon.paintIcon(this,g,3,3);
	}
}

⌨️ 快捷键说明

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