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

📄 answerright.java.bak

📁 抢答器
💻 BAK
字号:
/*
抢答权显显屏
界面制做人:程希望
类名Cxw 

*/
//package    包名没定呢
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import sun.audio.*;
import java.io.*;
public class Cxw extends JFrame implements ActionListener{
AudioStream music;	
JTextField f1;
JTextField f2;
JButton b1;
JButton b2;
JButton b3;
Timer tr;
Timer tr1;
ServerMain sm;
boolean b=false;
int type=0;// 用来记录事件代表的状态,1 :是正确加分 2:是错误减分 3是犯规罚分
//****************************************************************************
public Cxw(String code,String name,ServerMain sm){//构造方法开始 ,等传入参数做为文本中显示的名字
		this.sm=sm;
		try{//******************
				music = new AudioStream(  new FileInputStream("铃.au")   );
				AudioPlayer.player.start(music);
				}catch(Exception e1){
					e1.printStackTrace();	
				} //*********************end trycatch						
	  Container c = getContentPane();
			  c.setLayout(new BorderLayout());
		JPanel p=new JPanel();
				Label l1=new Label("获得答题权的是:");
				l1.setFont( new Font(null,Font.BOLD,40) ); 
				Label l2=new Label("倒计时");
				f1=new JTextField("60");
				f1.setFont( new Font(null,Font.BOLD,30) );
				f1.setBackground(new Color(206,222,190));	
				f1.setForeground(Color.red);
				Label l3=new Label("秒");			
				p.add(l1);		
				p.add(l2);
				p.add(f1);
				p.add(l3);
				p.setBackground(new Color(63,150,171));
		JPanel p1=new JPanel();
				b1=new JButton("答对了");
				b2=new JButton("答错了");
				b3=new JButton("犯规了");		
				b1.addActionListener(this);
				b2.addActionListener(this);
				b3.addActionListener(this);
			  tr=new Timer(1000, this);
			  tr.start();	
 			  tr1=new Timer(8000, this);
			  tr1.start();	
		f2=new JTextField(code+name);//直接用构造方法的行参做实参
		f2.setBackground(new Color(206,222,190));	
		f2.setForeground(Color.red);
				p1.add(b1);
				p1.add(b2);
				p1.add(b3);
				p1.setBackground(new Color(63,150,171));
			  f2.setFont( new Font(null,Font.BOLD,120) );     //设置字体大小		
		c.add(p,"North");
		c.add(f2,"Center");
		c.add(p1,"South");
		this.setTitle("抢答时间控制器");
		this.pack();	//自动调window大小
		this.show();   //等同于setvisible(true)
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置win关毕
}//构造方法完工
//*******************************************************************************
public void close(){//关掉本窗口
	System.exit(0);	
}//关掉它的方法
//****************************************************************************
public void actionPerformed(ActionEvent e){//监听方法开始
		 Object temp = e.getSource();
		
		 
					
						if( temp==b1){
						type=1;  
							try{//************************
								music = new AudioStream(  new FileInputStream("喝采.au")   );
								AudioPlayer.player.start(music);
							}catch(Exception e1){
								e1.printStackTrace();	
							} //*********************end tryactch
							finally{
								sm.update(type);
								b=true;
								//close();
							}
				System.out.println("答对了给他加分吧");    
						}		//如果正确情况结束										
						else if(temp==b2){
						type=2;				
									try{//****************
								music = new AudioStream(  new FileInputStream("错.au")   );
								AudioPlayer.player.start(music);
							}catch(Exception e1){
								e1.printStackTrace();	
							} 
							finally{
							sm.update(type);
							b=true;
							//close();
							}	//*********************end trycatch	
				System.out.println("答错了给他扣分吧");   
						} //如果答错情况结束	
						else if(temp==b3){
						type=3;
									try{//******************
								music = new AudioStream(  new FileInputStream("啊哦.au")   );
								AudioPlayer.player.start(music);
							}catch(Exception e1){
								e1.printStackTrace();	
							} 
							finally{
							sm.update(type);
							b=true;
						//	close();
							}//*********************end trycatch	
				System.out.println("犯规给他罚分吧");   
						}	//如果犯规情况结束	
						else if(temp==tr){
						String y=f1.getText();
						int i=Integer.parseInt(y);
						String ss=String.valueOf(--i);
									if(i>=0){						
										f1.setText(ss);
									}
									else{
									type=3; //如果超过时间也算犯规	
									try{//******************
										music = new AudioStream(  new FileInputStream("叮.au")   );
										AudioPlayer.player.start(music);
									}catch(Exception e1){
										e1.printStackTrace();	
									} 
									finally{
									sm.update(type);
									b=true;
							//		close();
							}//*********************end trycatch	
						System.out.println("超时了给他加分吧");   
									}//else小 结束
						}//else if 结束	
						else if(temp==tr1){
						if (b==true)
						close();
						}											  
}//监听方法结束
//***********************************************************************************
public static void  main(String args[]){//主函数用来测试
	ServerMain sm=new ServerMain();
	 Cxw t= new Cxw("1","程希望",sm);
	//t.close();	//要调用的关毕函数
	}//主函数结束
}//Jframe 类结束



//张名的类
class ServerMain{
	void update(int type){
		System.out.println(type);
	}

} 

⌨️ 快捷键说明

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