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

📄 e.java

📁 一个简单的英语单词学习小程序
💻 JAVA
字号:
package 输入输出流;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
class EWindow extends Frame implements ActionListener,ItemListener
{
	String str[]=new String[7];
	String s;
	FileReader file;
	BufferedReader in;
	Button start,next;
	Checkbox box[];
	TextField 题目,分数;
	int score=0;
	CheckboxGroup age=new CheckboxGroup();
	EWindow()
	{
		super("英语单词学习");
		分数=new TextField(10);
		题目=new TextField(70);
		start=new Button("重新练习");
		start.addActionListener(this);
		next=new Button("下一题目");
		next.addActionListener(this);
		box=new Checkbox[4];
		for(int i=0;i<=3;i++)
		{
			box[i]=new Checkbox("",false,age);
			box[i].addItemListener(this);
		}
		try
		{
			File f1=new File("D:\\space.java\\进一步\\src\\输入输出流","Example_0.java");
			file=new FileReader(f1);
			in=new BufferedReader(file);
		}
		catch(IOException e){}
		setBounds(100,100,400,320);
		setVisible(true);
		setLayout(new GridLayout(4,1));
		setBackground(Color.pink);
		Panel p1=new Panel();
		Panel p2=new Panel();
		Panel p3=new Panel();
		Panel p4=new Panel();
        p1.add(new Label("题目:"));
		p1.add(题目);
		p2.add(new Label("选择答案:"));
		for(int i=0;i<=3;i++)
		{
			p2.add(box[i]);
		}
		p3.add(new Label("您的得分:"));
		p3.add(分数);
		p4.add(start);
		p4.add(next);
		add(p1);
		add(p2);
		add(p3);
		add(p4);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		reading();
	}
	public void reading()
	{
		int i=0;
		try
		{
			s=in.readLine();
			if(!(s.startsWith("ended")))
			{
			StringTokenizer tokenizer=new StringTokenizer(s,"#");
			while(tokenizer.hasMoreTokens())
			{
				str[i]=tokenizer.nextToken();
				i++;
			}
			题目.setText(str[0]);
			for(int j=1;j<=4;j++)
			{
				box[j-1].setLabel(str[j]);
			}
			}
			else if(s.startsWith("ended"))
			{
				题目.setText("学习完毕");
				for(int j=0;j<4;j++)
				{
					box[j].setLabel("end");
					in.close();
					file.close();
				}
			}
		}
		catch(IOException exp)
		{
			题目.setText("无试题文件");
		}
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==start)
		{
			score=0;
			分数.setText("得分: "+score);
			try
			{
				File f1=new File("D:\\space.java\\进一步\\src\\输入输出流","Example_0.java");
				file=new FileReader(f1);
				in=new BufferedReader(file);
			}
			catch(IOException e1){}
			this.reading();
		}
		if(e.getSource()==next)
		{
			this.reading();
			for(int j=0;j<4;j++)
			{
				box[j].setEnabled(true);
			}
		}
	}
	public void itemStateChanged(ItemEvent e)
	{
		for(int j=0;j<4;j++)
		{
			if(box[j].getLabel().equals(str[5])&&box[j].getState())
			{
				score++;
				分数.setText("得分: "+score);
			}
			box[j].setEnabled(false);
		}
	}
}


public class Example_6 
{
	public static void main(String args[])
	   {
		   EWindow w=new EWindow();
		   w.pack();
	   }
}

⌨️ 快捷键说明

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