首页 > 代码库 > gui线程
gui线程
package thread; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JTextField; public class Thread1 extends JFrame implements Runnable ,ActionListener { private JPanel contentPane; private JTextField text; private JLabel ah = new JLabel("a"); private Thread giveLetter=new Thread(this); private int score=0; private JLabel defen = new JLabel("\u5F97\u52060"); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Thread1 frame = new Thread1(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public Thread1() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 670, 129); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel panel = new JPanel(); contentPane.add(panel, BorderLayout.CENTER); JLabel label = new JLabel("\u663E\u793A\u5B57\u6BCD"); panel.add(label); panel.add(ah); JLabel label_1 = new JLabel("\u8F93\u5165\u663E\u793A\u7684\u5B57\u6BCD"); panel.add(label_1); text = new JTextField(); panel.add(text); text.setColumns(10); panel.add(defen); text.addActionListener(this); giveLetter.start(); } @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 String letter=ah.getText().trim(); String daan=text.getText(); if(letter.equals(daan)){ score++; defen.setText("score"+score); text.setText(null); validate(); giveLetter.interrupt(); } text.setText(null); } @Override public void run() { // TODO 自动生成的方法存根 char c=‘a‘; for(;;){ ah.setText(""+c+" "); validate(); c=(char)(c+1); if(c>‘z‘) c=‘a‘; System.out.println(c); try{ Thread.sleep(2000); } catch(Exception e){ System.out.println(e.getMessage()); } } } }
gui线程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。