网站建设资讯

NEWS

网站建设资讯

java实验五补全代码 java中补全快捷键

怎样设置Eclipse的java自动补全

工具/原料

成都创新互联公司主要从事成都网站设计、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务蜀山,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

电脑

Eclipse

·1 第一步:打开编译器然后再点开一个java文件。

2第二步:在文件里右击鼠标,然后再选择Preferences。

3第三步:而后再Preferences里选择java

4第四步:再选择Editor,再选择Content Assist

5 第五步:再在所圈出的地方设置时间(200)和字母(.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz),而后点击ok即可。

java 补全代码

楼主,依题意,完整的程序如下:

import java.awt.FlowLayout;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class Exam2 extends Thread implements ActionListener

{

//声明界面元素

private JFrame timeFrame;

private JButton startButton;

private JButton stopButton;

private JButton resetButton;

private JLabel timeLabel;

//定义变量存储时、分、秒

int hour = 0;

int minute = 0;

int second = 0;

//声明线程对象

Thread myThread;

public Exam2()

{

timeFrame = new JFrame("计时器");

startButton = new JButton("开始");

stopButton = new JButton("停止");

resetButton = new JButton("重置");

timeLabel = new JLabel("00:00:00");

timeFrame.setLayout(new FlowLayout());

timeFrame.setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - 300)/2,

(Toolkit.getDefaultToolkit().getScreenSize().height - 200)/2, 300, 200);

timeFrame.add(timeLabel);

timeFrame.add(startButton);

timeFrame.add(stopButton);

timeFrame.add(resetButton);

timeFrame.setVisible(true);

timeFrame.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});

startButton.addActionListener(this);

stopButton.addActionListener(this);

resetButton.addActionListener(this);

myThread = this;

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource() == this.startButton)

{

System.out.println("计时开始...");

if(this.start)

{

this.myThread.start();

}

else

{

this.start = true;

}

}

if(e.getSource() == this.stopButton)

{

System.out.println("计时停止...");

this.start = false;

}

if(e.getSource() == this.resetButton)

{

hour = 0;

minute = 0;

second = 0;

}

}

volatile boolean start = true;

@Override

public void run()

{

while(true)

{

if(this.start)

{

second++;

try

{

Thread.sleep(1000);

} catch (InterruptedException e)

{

e.printStackTrace();

}

if(second = 60)

{

second = 0;

minute++;

}

if(minute = 60)

{

minute = 0;

hour++;

}

showTime();

}

}

}

private void showTime()

{

String strTime = "";

if(hour 10)

{

strTime += "0"+hour + ":";

}

else

{

strTime += hour + ":";

}

if(minute 10)

{

strTime += "0"+minute + ":";

}

else

{

strTime += minute + ":";

}

if(second 10)

{

strTime += "0"+second;

}

else

{

strTime += second;

}

this.timeLabel.setText(strTime);

}

public static void main(String[] args)

{

new Exam2();

}

}

有问题欢迎提问,满意请采纳,谢谢!

求解一道Java实验题,给出一段代码,要求把该代码补充完整使其可以运行,具体要求如下

package xinguan;

abstract class Operation{ //抽象类

public static double numberA= 0;

public static double numberB = 0;

abstract double getResult(); //抽象方法

}

class OperationADD extends Operation{

@Override

double getResult() {

return numberA+numberB;

}

}

class OperationSUB extends Operation{

@Override

double getResult() {

return numberA-numberB;

}

}

class OperationMUL extends Operation{

@Override

double getResult() {

return numberA*numberB;

}

}

class OperationDIV extends Operation{

@Override

double getResult() {

return numberA/numberB;

}

}

class OperationFactory{

public static Operation createOperate(char operate){

Operation oper = null;

switch (operate){

case'+':

oper= new OperationADD();

break;

case'-':

oper= new OperationSUB();

break;

case'*':

oper= new OperationMUL();

break;

case'/':

oper= new OperationDIV();

break;

}

return oper;

}

}

public class CalculateDemo {

/**

* @param args

*/

public static void main(String[] args) {

Operation operADD = OperationFactory.createOperate('+');

Operation operSUB = OperationFactory.createOperate('-');

Operation operMUL = OperationFactory.createOperate('*');

Operation operDIV = OperationFactory.createOperate('/');

operADD.numberA = 15.0;

operADD.numberB = 3;

System.out.println(operADD.getResult());

System.out.println(operSUB.getResult());

System.out.println(operMUL.getResult());

System.out.println(operDIV.getResult());

}

}

因为抽象类是静态方法 所以 给operADD 那个对象赋值一次就能获得所有结果。要是去掉static 那么就需要每个对象 赋值。现在基本满足你的要求了。

java根据需求补全下面的程序

public class ___ArrayUtil___{

public static void _printReversely(String a[])___{

for(int i=___ a.length___ ; i0; i++){//这里不是i++吧,应该是i--

System.out.println(__a[i-1]____);

}

}

}

写完ArrayUtil类后,若要在同一个包中的Decoder类中使用ArrayUtil类中的数组元素倒序打印函数,打印数组{1,2,3,4,5},则正确的调用方式为():

public class Decoder{

public static void main(String args[]){

int a[]={1,2,3,,4,5}

____ArrayUtil.printReversely(a)__________;

}

}


标题名称:java实验五补全代码 java中补全快捷键
网站地址:http://cdweb.net/article/ddsdsec.html