58,446
社区成员
发帖
与我相关
我的任务
分享
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ThreadTest1 extends JFrame {
JTextField l;
Button m2;
private static int count = 0;
private Test12 m;
public ThreadTest1() {
super();
this.setSize(300, 400);
this.setLayout(new BorderLayout());
m2 = new Button("Start");
JPanel m1 = new JPanel();
l = new JTextField(10);
m2.addActionListener(new Thread1());
m1.add(l, BorderLayout.SOUTH);
m1.add(m2, FlowLayout.LEFT);
this.add(m1);
}
class Thread1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
m = new Test12(m2, l);
m.start();
}
}
}
public class ThreadTest {
public static void main(String[] args) {
ThreadTest1 l = new ThreadTest1();
l.setVisible(true);
}
}
import javax.swing.JFrame;
public class ThreadTest {
public static void main(String[] args) {
ThreadTest1 l = new ThreadTest1();
l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l.setVisible(true);
}
}
import javax.swing.JTextField;
public class Test12 extends Thread {
private JTextField m;
private static int count=0;
public Test12(JTextField k)
{
this.m=k;
}
public void run()
{
try{
while(true)
{
m.setText(Integer.toString(count));
count = count + 1;
Thread.sleep(3000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ThreadTest1 extends JFrame {
JTextField l;
private static int count = 0;
private Test12 m;
public ThreadTest1() {
super();
this.setSize(300, 400);
this.setLayout(new BorderLayout());
JPanel m1 = new JPanel();
l = new JTextField(10);
l.addActionListener(new Thread1());
m = new Test12(l);
m1.add(l, BorderLayout.SOUTH);
this.add(m1);
}
class Thread1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(m!=null)
{
//m = new Test12(l);
m.start();
}else
{
m = new Test12(l);
m.start();
}
}
}
}
import javax.swing.JFrame;
public class ThreadTest {
public static void main(String[] args) {
ThreadTest1 l = new ThreadTest1();
l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l.setVisible(true);
}
}
import javax.swing.JTextField;
public class Test12 extends Thread {
private JTextField m;
private static int count=0;
public Test12(JTextField k)
{
this.m=k;
}
public void run()
{
try{
while(true)
{
m.setText(Integer.toString(count));
count = count + 1;
Thread.sleep(3000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}