我有个秒表的JAVA源代码,老师要求上交.JAVA文件,请问怎么把源代码变成.JAVA文件
发布网友
发布时间:2022-05-15 03:05
我来回答
共5个回答
热心网友
时间:2023-10-05 14:25
额。估计你还没有下载JDK 吧。下载JDK,安装。可以不添加环境变量什么的,直接把源文件拷贝到/bin目录下,进入命令行,跳到安装目录/bin,下面javac 文件名。。。就可以了。目录下会有文件。如果出现错误缺少包,就去下载,放到 /lib 下。追问我 要的是后缀名为JAVA的文件
热心网友
时间:2023-10-05 14:25
在jAVA编辑工具里新建一个类,再将代码复制进去。注意新建类的名字和你代码类里的一致。
热心网友
时间:2023-10-05 14:26
先是后缀名后然后重命名:*.java
热心网友
时间:2023-10-05 14:26
纯Java做的秒表:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestTimer extends JFrame implements ActionListener, Runnable {
private static TestTimer obj;
private JButton btnStart;
private JButton btnPause;
private JButton btnResume;
private JButton btnStop;
private JLabel lblTime;
private static Thread th;
private long count;
public TestTimer(){
super("秒表");
btnStart = new JButton("开始");
btnPause = new JButton("暂停");
btnResume = new JButton("继续");
btnStop = new JButton("停止");
lblTime = new JLabel("00:00:00.000");
this.setLayout(new FlowLayout());
this.add(btnStart);
this.add(btnPause);
this.add(btnResume);
this.add(btnStop);
this.add(lblTime);
btnStart.addActionListener(this);
btnPause.addActionListener(this);
btnResume.addActionListener(this);
btnStop.addActionListener(this);
this.setSize(150, 200);
this.setVisible(true);
}
public static void main(String[] args) {
obj = new TestTimer();
}
public void actionPerformed(ActionEvent e) {
JButton btn = (JButton)e.getSource();
if(btn.getText().equals("开始")){
th = new Thread(obj);
count = 0;
th.start();
}
else if(btn.getText().equals("暂停")){
th.suspend();
}
else if(btn.getText().equals("继续")){
th.resume();
}
else if(btn.getText().equals("停止")){
th.stop();
}
}
@Override
public void run() {
while(true){
int ms, seconds, minutes, hours;
String msg = "";
hours = (int)(count / 3600000);
minutes = (int)((count - hours * 3600000) / 60000);
seconds = (int)((count - hours * 3600000 - minutes * 60000) / 1000);
ms = (int)(count % 1000);
if(hours < 10){
msg += "0" + hours + ":";
}
else{
msg += hours + ":";
}
if(minutes < 10){
msg += "0" + minutes + ":";
}
else{
msg += minutes + ":";
}
if(seconds < 10){
msg += "0" + seconds + ":";
}
else{
msg += seconds + ":";
}
if(ms < 10){
msg += "00" + ms;
}
else if(ms < 100){
msg += "0" + ms;
}
else{
msg += ms;
}
lblTime.setText(msg);
count++;
try {
Thread.sleep(1);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行界面:
追问我 要的是后缀名为JAVA的文件 代码我有
热心网友
时间:2023-10-05 14:27
找个反编译工具