//主類(lèi)EnglishTest——
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、白銀區(qū)ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的白銀區(qū)網(wǎng)站制作公司
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EnglishTest extends JFrame
{
TestArea testPanel=null;
Container con=null;
public EnglishTest()
{
super("模擬考試");
testPanel=new TestArea();
con=getContentPane();
con.add(testPanel,BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setVisible(true);
setBounds(60,40,660,460);
con.validate();
validate();
}
public static void main(String args[])
{
new EnglishTest();
}
}
//讀取試題 ReadTestquestion
import java.io.*;
import java.util.*;
public class ReadTestquestion
{ String filename="",
correctAnswer="",
testContent="" ,
selection="" ;
int score=0;
long time=0;
boolean 完成考試=false;
File f=null;
FileReader in=null;
BufferedReader 讀取=null;
public void setFilename(String name)
{ filename=name;
score=0;
selection="";
try {
if(in!=null讀取!=null)
{
in.close();
讀取.close();
}
f=new File(filename);
in=new FileReader(f);
讀取=new BufferedReader(in);
correctAnswer=(讀取.readLine()).trim();
String temp=(讀取.readLine()).trim() ;
StringTokenizer token=new StringTokenizer(temp,":");
int hour=Integer.parseInt(token.nextToken()) ;
int minute=Integer.parseInt(token.nextToken());
int second=Integer.parseInt(token.nextToken());
time=1000*(second+minute*60+hour*60*60);
}
catch(Exception e)
{
testContent="沒(méi)有選擇試題";
}
}
public String getFilename()
{
return filename;
}
public long getTime()
{
return time;
}
public void set完成考試(boolean b)
{
完成考試=b;
}
public boolean get完成考試()
{
return 完成考試;
}
public String getTestContent()
{ try {
String s=null;
StringBuffer temp=new StringBuffer();
if(讀取!=null)
{
while((s=讀取.readLine())!=null)
{
if(s.startsWith("**"))
break;
temp.append("\n"+s);
if(s.startsWith("endend"))
{
in.close();
讀取.close();
完成考試=true;
}
}
testContent=new String(temp);
}
else
{
testContent=new String("沒(méi)有選擇試題");
}
}
catch(Exception e)
{
testContent="試題內(nèi)容為空,考試結(jié)束!!";
}
return testContent;
}
public void setSelection(String s)
{
selection=selection+s;
}
public int getScore()
{ score=0;
int length1=selection.length();
int length2=correctAnswer.length();
int min=Math.min(length1,length2);
for(int i=0;imin;i++)
{ try{
if(selection.charAt(i)==correctAnswer.charAt(i))
score++;
}
catch(StringIndexOutOfBoundsException e)
{
i=0;
}
}
return score;
}20:10 03-8-31
public String getMessages()
{
int length1=selection.length();
int length2=correctAnswer.length();
int length=Math.min(length1,length2);
String message="正確答案:"+correctAnswer.substring(0,length)+"\n"+
"你的回答:"+selection+"\n";
return message;
}
}
//考試區(qū)域TestArea
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
class FileName implements FilenameFilter
{
String str=null;
FileName (String s)
{
str="."+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable
{
Choice list=null;
JTextArea 試題顯示區(qū)=null,消息區(qū)=null;
JCheckBox box[];
JButton 提交該題答案,讀取下一題,查看分?jǐn)?shù);
ReadTestquestion 讀取試題=null;
JLabel welcomeLabel=null;
Thread countTime=null;
long time=0;
JTextField timeShow=null;
boolean 是否關(guān)閉計(jì)時(shí)器=false,
是否暫停計(jì)時(shí)=false;
JButton 暫停或繼續(xù)計(jì)時(shí)=null;
public TestArea()
{
list= new Choice();
String 當(dāng)前目錄=System.getProperty("user.dir");
File dir=new File(當(dāng)前目錄);
FileName fileTxt=new FileName("txt");
String fileName[]=dir.list(fileTxt);
for(int i=0;ifileName.length;i++)
{
list.add(fileName[i]);
}
試題顯示區(qū)=new JTextArea(15,12);
試題顯示區(qū).setLineWrap(true);
試題顯示區(qū).setWrapStyleWord(true);
試題顯示區(qū).setFont(new Font("TimesRoman",Font.PLAIN,14));
試題顯示區(qū).setForeground(Color.blue);
消息區(qū)=new JTextArea(8,8);
消息區(qū).setForeground(Color.blue);
消息區(qū).setLineWrap(true);
消息區(qū).setWrapStyleWord(true);
countTime=new Thread(this);
String s[]={"A","B","C","D"};
box=new JCheckBox[4];
for(int i=0;i4;i++)
{
box[i]=new JCheckBox(s[i]);
}
暫停或繼續(xù)計(jì)時(shí)=new JButton("暫停計(jì)時(shí)");
暫停或繼續(xù)計(jì)時(shí).addActionListener(this);
提交該題答案=new JButton("提交該題答案");
讀取下一題=new JButton("讀取第一題");
讀取下一題.setForeground(Color.blue);
提交該題答案.setForeground(Color.blue);
查看分?jǐn)?shù)=new JButton("查看分?jǐn)?shù)");
查看分?jǐn)?shù).setForeground(Color.blue);
提交該題答案.setEnabled(false);
提交該題答案.addActionListener(this);
讀取下一題.addActionListener(this);
查看分?jǐn)?shù).addActionListener(this);
list.addItemListener(this);
讀取試題=new ReadTestquestion();
JPanel pAddbox=new JPanel();
for(int i=0;i4;i++)
{
pAddbox.add(box[i]);
}
Box boxH1=Box.createVerticalBox(),
boxH2=Box.createVerticalBox(),
baseBox=Box.createHorizontalBox();
boxH1.add(new JLabel("選擇試題文件"));
boxH1.add(list);
boxH1.add(new JScrollPane(消息區(qū)));
boxH1.add(查看分?jǐn)?shù));
timeShow=new JTextField(20);
timeShow.setHorizontalAlignment(SwingConstants.RIGHT);
timeShow.setEditable(false);
JPanel p1=new JPanel();
p1.add(new JLabel("剩余時(shí)間:"));
p1.add(timeShow);
p1.add(暫停或繼續(xù)計(jì)時(shí));
boxH1.add(p1);
boxH2.add(new JLabel("試題內(nèi)容:"));
boxH2.add(new JScrollPane(試題顯示區(qū)));
JPanel p2=new JPanel();
p2.add(pAddbox);
p2.add(提交該題答案);
p2.add(讀取下一題);
boxH2.add(p2);
baseBox.add(boxH1);
baseBox.add(boxH2);
setLayout(new BorderLayout());
add(baseBox,BorderLayout.CENTER);
welcomeLabel=new JLabel("歡迎考試,提高英語(yǔ)水平",JLabel.CENTER);
welcomeLabel.setFont(new Font("隸書(shū)",Font.PLAIN,24));
welcomeLabel.setForeground(Color.blue);
add(welcomeLabel,BorderLayout.NORTH);
}
public void itemStateChanged(ItemEvent e)
{
timeShow.setText(null);
是否關(guān)閉計(jì)時(shí)器=false;
是否暫停計(jì)時(shí)=false;
暫停或繼續(xù)計(jì)時(shí).setText("暫停計(jì)時(shí)");
String name=(String)list.getSelectedItem();
讀取試題.setFilename(name);
讀取試題.set完成考試(false);
time=讀取試題.getTime();
if(countTime.isAlive())
{
是否關(guān)閉計(jì)時(shí)器=true;
countTime.interrupt();
}
countTime=new Thread(this);
消息區(qū).setText(null);
試題顯示區(qū).setText(null);
讀取下一題.setText("讀取第一題");
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(true);
welcomeLabel.setText("歡迎考試,你選擇的試題:"+讀取試題.getFilename());
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==讀取下一題)
{
讀取下一題.setText("讀取下一題");
提交該題答案.setEnabled(true);
String contentTest=讀取試題.getTestContent();
試題顯示區(qū).setText(contentTest);
消息區(qū).setText(null);
讀取下一題.setEnabled(false);
try {
countTime.start();
}
catch(Exception event)
{
}
}
if(e.getSource()==提交該題答案)
{
讀取下一題.setEnabled(true);
提交該題答案.setEnabled(false);
String answer="?";
for(int i=0;i4;i++)
{
if(box[i].isSelected())
{
answer=box[i].getText();
box[i].setSelected(false);
break;
}
}
讀取試題.setSelection(answer);
}
if(e.getSource()==查看分?jǐn)?shù))
{
int score=讀取試題.getScore();
String messages=讀取試題.getMessages();
消息區(qū).setText("分?jǐn)?shù):"+score+"\n"+messages);
}
if(e.getSource()==暫停或繼續(xù)計(jì)時(shí))
{
if(是否暫停計(jì)時(shí)==false)
{
暫停或繼續(xù)計(jì)時(shí).setText("繼續(xù)計(jì)時(shí)");
是否暫停計(jì)時(shí)=true;
}
else if(是否暫停計(jì)時(shí)==true)
{
暫停或繼續(xù)計(jì)時(shí).setText("暫停計(jì)時(shí)");
是否暫停計(jì)時(shí)=false;
countTime.interrupt();
}
}
}
public synchronized void run()
{
while(true)
{
if(time=0)
{
是否關(guān)閉計(jì)時(shí)器=true;
countTime.interrupt();
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(false);
timeShow.setText("用時(shí)盡,考試結(jié)束");
}
else if(讀取試題.get完成考試())
{
是否關(guān)閉計(jì)時(shí)器=true;
timeShow.setText("考試效果:分?jǐn)?shù)*剩余時(shí)間(秒)="+1.0*讀取試題.getScore()*(time/1000));
countTime.interrupt();
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(false);
}
else if(time=1)
{
time=time-1000;
long leftTime=time/1000;
long leftHour=leftTime/3600;
long leftMinute=(leftTime-leftHour*3600)/60;
long leftSecond=leftTime%60;
timeShow.setText(""+leftHour+"小時(shí)"+leftMinute+"分"+leftSecond+"秒");
}
try
{
Thread.sleep(1000);
}
catch(InterruptedException ee)
{
if(是否關(guān)閉計(jì)時(shí)器==true)
return ;
}
while(是否暫停計(jì)時(shí)==true)
{
try
{
wait();
}
catch(InterruptedException ee)
{
if(是否暫停計(jì)時(shí)==false)
{
notifyAll();
}
}
}
}
}
}
public interface Student {
// 該方法用于表示不同階段的學(xué)生在學(xué)習(xí)數(shù)學(xué)課程時(shí)的不同內(nèi)容
public abstract void studyMath();
// 該方法用于表示不同階段的學(xué)生的英語(yǔ)水平
public abstract void studyEnglish();
}
public class PrimarySchoolStudent implements Student {
@Override
public void studyMath() {
System.out.println("小學(xué)生在學(xué)習(xí)數(shù)學(xué)課程時(shí),主要學(xué)習(xí)加減法,數(shù)學(xué)表達(dá)式等基礎(chǔ)知識(shí)。");
}
@Override
public void studyEnglish() {
System.out.println("小學(xué)生在學(xué)習(xí)英語(yǔ)時(shí),主要學(xué)習(xí)詞匯,基本句型,基本語(yǔ)法等基礎(chǔ)知識(shí)。");
}
}
public class MiddleSchoolStudent implements Student {
@Override
public void studyMath() {
System.out.println("中學(xué)生在學(xué)習(xí)數(shù)學(xué)課程時(shí),主要學(xué)習(xí)初等函數(shù),代數(shù)方程等基礎(chǔ)知識(shí)。");
}
@Override
public void studyEnglish() {
System.out.println("中學(xué)生在學(xué)習(xí)英語(yǔ)時(shí),主要學(xué)習(xí)閱讀理解,聽(tīng)力理解,口語(yǔ)交流等能力。");
}
}
public class CollegeStudent implements Student {
@Override
public void studyMath() {
System.out.println("大學(xué)生在學(xué)習(xí)數(shù)學(xué)課程時(shí),主要學(xué)習(xí)高等數(shù)學(xué),概率論,數(shù)值計(jì)算等專(zhuān)業(yè)知識(shí)。");
}
@Override
public void studyEnglish() {
System.out.println("大學(xué)生在學(xué)習(xí)英語(yǔ)時(shí),主要學(xué)習(xí)專(zhuān)業(yè)英語(yǔ),商務(wù)英語(yǔ),英文寫(xiě)作等能力。");
}
}
public class Main {
public static void main(String[] args) {
你安裝JDK的目錄下,有個(gè)src.zip文件,這個(gè)就是JDK源代碼的java文件。
你可以解壓來(lái)查看,但,最好是關(guān)聯(lián)到IDE如?eclipse?中(不需解壓),然后?CTRL?+?點(diǎn)擊就可以查看到源代碼了。
如下圖:
步驟:
1、在cmd中切換到編寫(xiě)的代碼所保存的目錄下;
2、在cmd中輸入javac然后點(diǎn)空格,再點(diǎn)擊文件名和包括后綴名確定后,在存放編寫(xiě)代碼的文件下會(huì)生成一個(gè)class的字節(jié)碼文件;
3、在cmd中輸入java然后點(diǎn)空格,輸入第二步中生成的字節(jié)碼的文件名,不需要后綴名,點(diǎn)擊確定即可運(yùn)行代碼。
代碼就是程序員用開(kāi)發(fā)工具所支持的語(yǔ)言寫(xiě)出來(lái)的源文件,是一組由字符、符號(hào)或信號(hào)碼元以離散形式表示信息的明確的規(guī)則體系。計(jì)算機(jī)代碼稱(chēng)為源代碼,是相對(duì)目標(biāo)代碼和可執(zhí)行代碼而言的。 源代碼就是用匯編語(yǔ)言和高級(jí)語(yǔ)言寫(xiě)出來(lái)的地代碼,目標(biāo)代碼是指源代碼經(jīng)過(guò)編譯程序產(chǎn)生的能被cpu直接識(shí)別二進(jìn)制代碼。
分享題目:大學(xué)guan網(wǎng)java代碼 java代碼交流網(wǎng)站
網(wǎng)站路徑:http://vcdvsql.cn/article10/doicedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站改版、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)