console-Java程序没有错,但是Console有问题,没运行结果(秒表)

问题描述

Java程序没有错,但是Console有问题,没运行结果(秒表)

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
//import java.util.TimerTask;
import javax.swing.Timer;

import javax.swing.*;

public class StopwatchFrame extends JFrame implements ActionListener
{
private static final long serialVersionUID = -1947098583246834192L;
JButton startButton; //启动按钮
JButton stopButton; //暂停按钮
JButton countButton; //完成按钮
JButton resetButton; //复位按钮
JLabel timeLabel;
JTextArea resultArea;
Timer myTimer;
int minute; //分
int second; //秒
int donknow; //秒后的单位
int numberFinish; //记录的次数

     StopwatchFrame(String s)
    {

        super(s);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container contentPane = getContentPane();
        contentPane.setLayout(new CardLayout(4,4));

        JPanel mainPanel = new JPanel(new BorderLayout());
        JPanel resultPanel = new JPanel(new CardLayout(4,4));
        JPanel timePanel = new JPanel(new CardLayout(45,4));
        //JPanel timeFlowPanel = new JPanel(new FlowLayout());
        JPanel buttonCardPanel = new JPanel(new CardLayout(4,4));
        JPanel buttonPanel = new JPanel(new GridLayout(4,1,0,3));
        JPanel westPanel = new JPanel(new BorderLayout());

        startButton = new JButton("开始/继续");
        stopButton = new JButton("暂停");
        countButton = new JButton("计数");
        resetButton = new JButton("复位");
        timeLabel = new JLabel("00:00:00");

        timeLabel.setFont(new Font("微软雅黑",Font.PLAIN,35));
        timeLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        timeLabel.setAlignmentY(JLabel.CENTER_ALIGNMENT);
        resultArea = new JTextArea();
        resultArea.setEditable(true);
        resultArea.setLineWrap(false);
        resultArea.setColumns(10);

        buttonPanel.add(startButton);
        buttonPanel.add(stopButton);
        buttonPanel.add(resetButton);
        buttonPanel.add(countButton);
        buttonCardPanel.add(buttonPanel);
        timePanel.add(timeLabel);
        resultPanel.add(new JScrollPane(resultArea));
        westPanel.add(buttonCardPanel,BorderLayout.CENTER);
        mainPanel.add(timePanel,BorderLayout.NORTH);

        mainPanel.add(westPanel,BorderLayout.CENTER);
        mainPanel.add(resultPanel,BorderLayout.WEST);
        contentPane.add(mainPanel);

        myTimer = new Timer(10,this);
        startButton.addActionListener(this);
        stopButton.addActionListener(this);
        countButton.addActionListener(this);
        resetButton.addActionListener(this);

        this.minute = 0;
        this.second = 0;
        this.donknow = 0;
        this.numberFinish=0;

        setSize(250,300);
        setResizable(false);   //禁止改变窗口大小
        setLocationRelativeTo(null); // 在屏幕中心弹出窗口
        setVisible(true);   

    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==startButton){

            myTimer.start();
        }
        else if(e.getSource()==stopButton){
            myTimer.stop();
        }
        else if(e.getSource()==countButton){

            this.numberFinish++;
            DecimalFormat myFormat = new DecimalFormat("00");
            this.resultArea.append(" 第"+this.numberFinish+":   "+myFormat.format(this.minute)+":"+
                    myFormat.format(this.second)+":"+myFormat.format(this.donknow)+"rn");
        }
        else if(e.getSource()==resetButton){

            myTimer.stop();
            this.minute = 0;
            this.second = 0;
            this.donknow = 0;
            this.numberFinish=0;
            timeLabel.setText("00:00:00");

            //myTimer.start();
            //resultArea.setText("");
        }
        else if(e.getSource()==myTimer)
        {

            this.donknow++;
            this.second += this.donknow/100;
            this.minute += this.second/60;

            this.donknow = this.donknow%100;
            this.second = this.second%60;
            this.minute =this.minute%60;

            DecimalFormat myFormat = new DecimalFormat("00");
            this.timeLabel.setText(myFormat.format(this.minute)+":"+
                    myFormat.format(this.second)+":"+myFormat.format(this.donknow));

        }

    }
    public static void main(String args[])
    {
        @SuppressWarnings("unused")
        StopwatchFrame myFrame = new StopwatchFrame("秒表");
    }

}

解决方案

试了一下,JLabel正常显示秒表时间,各个按钮功能都有反应。
没明白Console没有运行结果是什么意义。

解决方案二:

请哪位大师指点一下,感激不尽

解决方案三:

你个Swing程序,main方法和其他被调用中又没有写System.out.println语句又不会打印输出,控制台当然看不懂啊任何结果了。

时间: 2024-09-16 23:54:45

console-Java程序没有错,但是Console有问题,没运行结果(秒表)的相关文章

java程序报错,求大神找bug

问题描述 java程序报错,求大神找bug package arraysofobjects; import java.util.Scanner; public class arraysofobjects { public static void main(String[] args) { Scanner input=new Scanner(System.in); students[] stu=new students[4]; String name; int grade; for(int i=0

bat下执行java程序报错处理

G:\>java -Xms128M -Xmx512M -server -Dprogram.name=b omc-sa-tdtpagent -Dfile.encoding=GBK -Duser.timezone=GMT+8 -jar ../test.jar agent 1>td.log Error: missing `server' JVM at `C:\Program Files\Java\jre7\bin\server\jvm.dll'. Please install or use the

怎样把java程序放在没有安装JRE的电脑上运行?

问题描述 网上说可以把jar和JRE绑定成一个exe,然后运行但是我试过launch4j和jsmooth,都无法把JRE绑定到exe文件里面,也就无法在没有JRE环境的电脑上运行了谁知道怎么做?我看lauch4j的介绍说可以绑定JRE,但是我找不到如何绑定,网上的介绍都试过了,没有用泪奔了~~~ 解决方案 解决方案二:下载EXE4j,按照说明来使用即可.不过这样一来,你的目标文件就会很大(因为绑定了JRE),如果向对文件瘦身的话就再用一款软件:InnoSetup.

编写跨平台Java程序注意事项

程序 使用Java语言编写应用程序最大的优点在于"一次编译,处处运行",然而这并不是说所有的Java程序都具有跨平台的特性,事实上,相当一部分的Java程序是不能在别的操作系统上正确运行的,那么如何才能编写一个真正的跨平台的Java程序呢?下面是在编写跨平台的Java程序是需要注意的一些事情:   1. 编写Java跨平台应用程序时,你可以选择JDK1.0,1.1,1.2或支持它们的GUI开发工具如:Jbuilder,Visual Age for Java 等等,但是必须注意你的Jav

实现Java程序跨平台运行的12点注意事项

程序 编写跨平台Java程序注意事项 使用Java语言编写应用程序最大的优点在于"一次编译,处处运行",然而这并不是说所有的Java程序都具有跨平台的特性,事实上,相当一部分的Java程序是不能在别的操作系统上正确运行的,那么如何才能编写一个真正的跨平台的Java程序呢?下面是在编写跨平台的Java程序是需要注意的一些事情: 1. 编写Java跨平台应用程序时,你可以选择JDK1.0,1.1,1.2或支持它们的GUI开发工具如:Jbuilder,Visual Age for Java

跨平台Java程序_JSP编程

使用Java语言编写应用程序最大的优点在于"一次编译,处处运行",然而这并不是说所有的Java程序都具有跨平台的特性,事实上,相当一部分的Java程序是不能在别的操作系统上正确运行的,那么如何才能编写一个真正的跨平台的Java程序呢?下面是在编写跨平台的Java程序是需要注意的一些事情: 1.编写Java跨平台应用程序时,你可以选择JDK1.0,1.1,1.2或支持它们的GUI开发工具如:Jbuilder,Visual Age for Java 等等,但是必须注意你的Java程序只能使

讲解关于编写跨平台Java程序时的注意事项

使用Java语言编写应用程序最大的优点在于"一次编译,处处运行",然而这并不是说所有的Java程序都具有跨平台的特性,事实上,相当一部分的Java程序是不能在别的操作系统上正确运行的,那么如何才能编写一个真正的跨平台的Java程序呢?下面是在编写跨平台的Java程序是需要注意的一些事情:1.编写Java跨平台应用程序时,你可以选择JDK1.0,1.1,1.2或支持它们的GUI开发工具如:Jbuilder,Visual Age for Java 等等,但是必须注意你的Java程序只能使用

mysql案例:Java程序访问Mysql报错

mysql案例:Java程序访问Mysql报错'OPTION SQL_SELECT_LIMIT=XXX' [环境描述] mysql版本: 5.6.14-56-log Percona Server (GPL) 程序: 使用JDBC驱动mysql-connector-java访问mysql数据库 [报错信息] 程序访问mysql执行SQL语句的时候报错: You have an error in your SQL syntax; check the manual that corresponds t

eclipse报错-JAVA程序编程成CLASS文件后能在CMD运行,但是无法运行ECLIPSE。

问题描述 JAVA程序编程成CLASS文件后能在CMD运行,但是无法运行ECLIPSE. JAVA程序编程成CLASS文件后能在CMD运行,但是无法运行ECLIPSE,报错 解决方案 具体是哪里错了,有截图吗 解决方案二: 直接将该程序的源代码复制到eclipse某项目的src下再运行该程序 解决方案三: http://jingyan.baidu.com/article/15622f247de105fdfcbea5c9.html 解决方案四: 是无法运行ECLIPSE还是代码在ECLIPSE上报