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

📄 3.java

📁 里面有我的JAVA实验和一些教程
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class textfield1 extends Applet implements ActionListener
{
	JTextField txtfld1;
	TextArea txt,txt1;
	JButton button;
	String ch[]=new String[100];
	String s2[]=new String[100];
	private JCheckBox a[] = new JCheckBox[52];
	private JLabel inputJLabel;
	int j=0,i=0;
	public void init()
	{
		txtfld1=new JTextField(30);
		txt=new TextArea("",20,140,50);
		txt1=new TextArea("",20,140,50);
		button=new JButton("添加");
		inputJLabel = new JLabel();
		inputJLabel.setText("请输入单词");
		add(inputJLabel);
		add(txtfld1);
		add(button);
		add(txt); 
		txt.setEditable(false);
		txt1.setEditable(false);
		button.addActionListener(this);
		for (int i = 0; i < 26; i++) 
		{
			a[i]= new JCheckBox();
			a[i].setText(""+(char)(i+97));
		    add(a[i]);	
		}
		for (int i = 26; i < 52; i++) 
		{
			a[i]= new JCheckBox();
			a[i].setText(""+(char)(i+39));
		    add(a[i]);	
		}
		CheckBoxAction cba = new CheckBoxAction();
		for (int i = 0; i < 52; i++)
			a[i].addItemListener(cba);
		add(txt1);
	}

	public void actionPerformed(ActionEvent evt)
	{
	if((evt.getSource()==button))
		{
		    String s=new String(""+txtfld1.getText());
			txtfld1.setText("");    
			txt.append(s+"\n");
			ch[j++]=s;
		}
	}
	class CheckBoxAction implements ItemListener
	{
	
		public void itemStateChanged(ItemEvent e) 
		{
			JCheckBox i = (JCheckBox) e.getSource();
			txt1.setText("");
			for (int n = 0; n < j; n++)
				if (i.getText().equals(ch[n].substring(0, 1)))
					txt1.append(ch[n]+"\n");
		}

	}
}

⌨️ 快捷键说明

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