当前位置: 技术问答>java相关
关于线程wait的问题,向各位大侠求救!!!!!
来源: 互联网 发布时间:2015-09-27
本文导语: 我做了一个动画的程序,有两个按钮,一个是启动,另一个让线程wait,但线程wait后界面上的按钮不响应鼠标事件,(原想再点启动按钮线程又启动) 我的程序如下: import java.awt.*; import java.awt.event.*; import javax.swing...
我做了一个动画的程序,有两个按钮,一个是启动,另一个让线程wait,但线程wait后界面上的按钮不响应鼠标事件,(原想再点启动按钮线程又启动)
我的程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class graphicFrame extends JFrame implements Runnable {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JButton jButton1 = new JButton();
private MyPanel panel1 = new MyPanel();
Thread myThread = null;
MyChar[] str = new MyChar[20];
int yStep = 0;
int xCenter = 150;
//Construct the frame
public graphicFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("开始");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 423));
this.setTitle("Frame Title");
contentPane.add(jButton1, BorderLayout.SOUTH);
contentPane.add(panel1, BorderLayout.CENTER);
//initial
for(int i=0;i
我的程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class graphicFrame extends JFrame implements Runnable {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JButton jButton1 = new JButton();
private MyPanel panel1 = new MyPanel();
Thread myThread = null;
MyChar[] str = new MyChar[20];
int yStep = 0;
int xCenter = 150;
//Construct the frame
public graphicFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("开始");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 423));
this.setTitle("Frame Title");
contentPane.add(jButton1, BorderLayout.SOUTH);
contentPane.add(panel1, BorderLayout.CENTER);
//initial
for(int i=0;i