1、package day; 重新定义包名和类名import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.InputStreamReader;import java.ut
2、il.Date;import java.util.Timer;import java.util.TimerTask;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextArea;public class c private JFrame j1;private JPanel k1;private JButton b1;private JButton b2;private JButton b3;
3、private JButton b4;private JTextArea t1;private JLabel l1;static Timer timer;private String s;int i=0;int t=20;public c()j1=new JFrame();k1=new JPanel();b1=new JButton(“START“);b2=new JButton(“下一题 “);b2.setEnabled(false);b3=new JButton(“跳过 “); b3.setEnabled(false);b4=new JButton(“答案 “);b4.setEnabled
4、(false);s=new String10;t1=new JTextArea();l1=new JLabel(“20 秒“,JLabel.CENTER);public void init()JPanel k2=new JPanel();j1.add(k1);k1.setLayout(new BorderLayout();k2.setLayout(new FlowLayout();k1.add(l1,BorderLayout.NORTH);k1.add(t1,BorderLayout.CENTER);k1.add(k2,BorderLayout.SOUTH);k2.add(b1);k2.add
5、(b2);k2.add(b3);k2.add(b4);b1.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) t=20;time();t1.setText(download(i);b1.setEnabled(false);b2.setEnabled(false);b3.setEnabled(true);b4.setEnabled(true););b2.addActionListener(new ActionListener() Overridepublic void
6、 actionPerformed(ActionEvent e) t=20;time();i=i+1;t1.setText(download(i);b2.setEnabled(false);b3.setEnabled(true);b4.setEnabled(true););b3.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) timer.cancel();t=20;time();t1.setText(download(i);b3.setEnabled(false);
7、);b4.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) timer.cancel();i=i+1;timedelay();t1.setText(download(i);b2.setEnabled(true);b3.setEnabled(false);b4.setEnabled(false);if(i=(s.length-1)b2.setEnabled(false););public String download(int j)tryBufferedReader
8、bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(“daytimu“);for( int i=0;i10;i+)si=bufferedReader.readLine();bufferedReader.close();catch (Exception e)e.printStackTrace();return sj;public void time()timer=new Timer();timer.schedule(new TimerTask() Overridepublic void run()
9、 l1.setText(Integer.toString(t)+“秒“);t=t-1;,000,1000);timer.schedule(new TimerTask() Overridepublic void run() timer.cancel();, new Date(System.currentTimeMillis()+20*1000);public void timedelay()tryThread.sleep(2000);timer.cancel();catch (InterruptedException e) e.printStackTrace();public void setF
10、ontAndColor()t1.setFont(new Font(“行楷“,Font.BOLD,40);l1.setFont(new Font(“楷书“,Font.BOLD+Font.ITALIC,40);l1.setForeground(Color.RED);b1.setFont(new Font(“行楷“,Font.BOLD+Font.ITALIC,60);b1.setForeground(Color.RED);b1.setBackground(Color.GRAY);b2.setFont(new Font(“宋体“, Font.BOLD, 25);b3.setFont(new Font(
11、“宋体“, Font.BOLD, 25);b4.setFont(new Font(“宋体“, Font.BOLD, 25);public void showMe()j1.setSize(800,600);j1.setVisible(true);t1.setLineWrap(true);t1.setEditable(false);j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public static void main(String args) c c=new c();c.init();c.showMe();c.setFontAndColor();