成都网站建设设计

将想法与焦点和您一起共享

java代码实现自动计 java如何自动生成代码

java怎么让代码自动

你说的是Eclipse代码自动补全功能吧。可以实现输入任意字母均可出现代码补全提示框。

成都创新互联公司专注于企业全网整合营销推广、网站重做改版、肥乡网站定制设计、自适应品牌网站建设、H5高端网站建设商城开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为肥乡等各大城市提供网站开发制作服务。

具体设置方式如下:

eclipse--windows--preferences--java--editor--content assist--右边设置如下图

红色箭头指向的地方设置为:

.abcdefghijklmnopqrstuvwxyz(26个字母全部写进去不区分大小写)

用java编写一个倒计时器代码。

import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class TimerDemo extends JFrame implements ActionListener { private static final long serialVersionUID = 201306211111L; private JTextField screen = new JTextField("0"); private JButton start = new JButton("开始"); private JButton reset = new JButton("重置"); private JPanel panel = new JPanel(); private boolean isRunning; private int time; private int timeBetween; public TimerDemo(int timeBetween) { super("计时器"); this.timeBetween = timeBetween; try { init(); } catch (Exception e) { e.printStackTrace(); } } public TimerDemo() { super("计时器"); this.timeBetween = 100; try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() { panel.setLayout(new GridLayout()); panel.add(start); panel.add(reset); start.addActionListener(this); reset.addActionListener(this); screen.setFont(new Font("幼圆", Font.BOLD, 60)); screen.setHorizontalAlignment(JTextField.CENTER); screen.setEditable(false); Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.SOUTH); c.add(screen, BorderLayout.CENTER); this.setSize(200, 150); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args) { new TimerDemo(1);// 设定 1ms/次 // new TimerDemo(); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == start) { if (start.getText().equals("开始")) { start.setText("暂停"); isRunning = true; } else if (start.getText().equals("暂停")) { start.setText("开始"); isRunning = false; } } if (e.getSource() == reset) { start.setText("开始"); screen.setText("0"); isRunning = false; time = 0; } new Thread(new TimeZone()).start(); } class TimeZone implements Runnable { @Override public void run() { while (isRunning) { time++; if (time = Integer.MAX_VALUE) { screen.setText("ERROR"); JOptionPane.showMessageDialog(null, "ERROR"); isRunning = false; } screen.setText(String.valueOf(time)); try { Thread.sleep(timeBetween); } catch (Exception e) { e.printStackTrace(); } } } }}

java中如何实现自动计时功能,就是点击一个start按钮就开始计时,以秒为单位

简单代码如下:

import java.awt.Button;

import java.awt.FlowLayout;

import java.awt.Label;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.swing.JFrame;

import javax.swing.Timer;

@SuppressWarnings("serial")

public class Timers extends JFrame {

final Label lab = new Label();

Date now = new Date();

@SuppressWarnings("deprecation")

public Timers() {

now.setHours(0);

now.setMinutes(0);

now.setSeconds(0);

setBounds(550, 270, 200, 150);

final Timer timer = new Timer(1000, new ActionListener() {

public void actionPerformed(ActionEvent e) {

Date now2 = new Date(now.getTime() + 1000);

now = now2;

SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");

lab.setText(formatter.format(now));

}

});

Button b1 = new Button("开始");

Button b2 = new Button("停止");

b2.setBounds(40, 40, 40, 40);

b1.setBounds(30, 30, 30, 30);

b1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

Button b = (Button) e.getSource();

b.setLabel("开始");

timer.start();

}

});

b2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

Button b = (Button) e.getSource();

b.setLabel("停止");

timer.stop();

}

});

this.setLayout(new FlowLayout());

this.add(b2);

this.add(b1);

this.add(lab);

this.setSize(300, 200);

this.setVisible(true);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public static void main(String[] args) {

Timers t = new Timers();

t.lab.setText("00:00:00");

}

}

不知是否帮到你,如满意请采纳!

求人用java编写一条计时器代码。

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.io.*;

import java.util.*;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.plaf.OptionPaneUI;

public class Demo {

static boolean isRuning=false;

static boolean isFirst=true;

@SuppressWarnings("unchecked")

public static void main(String[] args) throws Exception {

JFrame form1 = new JFrame("Form1");

JTextField jTextField = new JTextField(10);

jTextField.setSize(10, 10);

jTextField.setText("0");

jTextField.setEditable(false);

JButton jButton = new JButton("开始");

jButton.setSize(10, 10);

Thread thread = new Thread(new Runnable() {

@Override

public void run() {

while (true) {

while(isRuning){

Integer counter = Integer.parseInt(jTextField.getText().trim());

counter++;

jTextField.setText(counter.toString());

try {

Thread.sleep(1000);

} catch (Exception e2) {

}

}

}

}

});

jButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

   String text=jButton.getText().equals("开始")?"暂停":"开始";

   jButton.setText(text);

   isRuning=!isRuning;

   if(isFirst){

   thread.start();

   isFirst=false;

   }

}

});

JPanel panel = new JPanel();

panel.setSize(200, 200);

panel.add(jTextField, BorderLayout.NORTH);

panel.add(jButton, BorderLayout.CENTER);

form1.add(panel);

form1.setBounds(200, 100, 250, 150);

form1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

form1.addWindowListener(new WindowListener() {

@Override

public void windowOpened(WindowEvent e) {

// TODO Auto-generated method stub

}

@Override

public void windowIconified(WindowEvent e) {

// TODO Auto-generated method stub

}

@Override

public void windowDeiconified(WindowEvent e) {

// TODO Auto-generated method stub

}

@Override

public void windowDeactivated(WindowEvent e) {

// TODO Auto-generated method stub

}

@Override

public void windowClosing(WindowEvent e) {

// 窗口关闭前取出文本框的数字保存到外部文件,代码在此处写

JOptionPane.showMessageDialog(null, "Are you sure closing?");

}

@Override

public void windowClosed(WindowEvent e) {

// TODO Auto-generated method stub

}

@Override

public void windowActivated(WindowEvent e) {

// TODO Auto-generated method stub

}

});

form1.setVisible(true);

}

}


本文名称:java代码实现自动计 java如何自动生成代码
URL分享:http://chengdu.cdxwcx.cn/article/hipopi.html