我有个秒表的JAVA源代码,老师要求上交.JAVA文件,请问怎么把源代码变成.JAVA文件
展开全部
在jAVA编辑工具里新建一个类,再将代码复制进去。注意新建类的名字和你代码类里的一致。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-24
展开全部
先是后缀名后然后重命名:*.java
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
纯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();
}
}
}
}
运行界面:
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的文件 代码我有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询