下面的Java程序怎么该
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclasslianxi27extend...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class lianxi27 extends JFrame implements Runnable{
private JTextArea textArea;
private boolean running=true;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run(){
lianxi27 frame=new lianxi27();
new Thread(frame).start();
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}});}
public lianxi27(){
super("ai");
this.setBounds(100,100,232,241);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel=new JPanel();
this.add(panel,BorderLayout.SOUTH);
final JButton button=new JButton("停止");
button.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
do_button_actionPerformed(e);}});
panel.add(button);
final JScrollPane jscrollPane=new JScrollPane ();
this.add(jscrollPane,BorderLayout.CENTER);
textArea=new JTextArea();
textArea.setLineWrap(true);
jscrollPane.setViewportView(textArea);}
public void run(){
int count=0;
while(running){
try{
Thread.sleep(100);
textArea.append(++count+" ");
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
public void do_button_actionPerformed(final ActionEvent e){
stopThread();
}
public void stopThread(){
this.running=false;}
} 展开
import javax.swing.*;
import java.awt.event.*;
public class lianxi27 extends JFrame implements Runnable{
private JTextArea textArea;
private boolean running=true;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run(){
lianxi27 frame=new lianxi27();
new Thread(frame).start();
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}});}
public lianxi27(){
super("ai");
this.setBounds(100,100,232,241);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel=new JPanel();
this.add(panel,BorderLayout.SOUTH);
final JButton button=new JButton("停止");
button.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
do_button_actionPerformed(e);}});
panel.add(button);
final JScrollPane jscrollPane=new JScrollPane ();
this.add(jscrollPane,BorderLayout.CENTER);
textArea=new JTextArea();
textArea.setLineWrap(true);
jscrollPane.setViewportView(textArea);}
public void run(){
int count=0;
while(running){
try{
Thread.sleep(100);
textArea.append(++count+" ");
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
public void do_button_actionPerformed(final ActionEvent e){
stopThread();
}
public void stopThread(){
this.running=false;}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询