java中如何补全代码 java补全字符串右补齐( 二 )


}//End generate_arr
public void Maximum()//得出数组中最大值的成员方法
{ //To do the code
int max = 0;
for (int i=0;i100;i++)
if (maxarr[i])
max=arr[i] ;
this.maxint=max;
}//End Maximum
public void Average()//得出数组平均值的成员方法
{ //To do the code
int sum=0;
for(int i=0;i100;i++)
sum=sum+arr[i];
this.average=(float)sum/100;
}//End Average
}//End class C package ex1;
Java 自动补全 按什么键?java自动补全按的是“Alt + /” 。
为了方便,可以设置自动联想 。
window-preference,然后搜索assist , 然后在相应的位置输入全部字符,而且也可以修改延迟时间 , ms级别 。然后apply,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(hour10)
{
strTime += "0"+hour + ":";
}
else
{
strTime += hour + ":";
}
if(minute10)
{
strTime += "0"+minute + ":";
}
else
{
strTime += minute + ":";

推荐阅读